/* Author: P.A. Huisman
 * SiteCLX Webdesign Dordrecht
*/

$(function() {
	
	// landing page boxes
	$(".landing-page .business, .landing-page .private").click( function(o) {
			if( $(o.target).parent()[0].nodeName == 'H1')
				return;
			
			var txt = $(this).find('.text');
			if(txt.hasClass('openmnu')){
				return;
			}
			$('.openmnu').css('top', '290px');
			$('.openmnu').removeClass('openmnu');
			
			txt.animate({top: 0},  500, function(){
				$(this).addClass('openmnu');
			});
	});
	
	$('ul.topmenu').superfish({
		dropShadows: true,
		disableHI	: true
	}); 
	
	
	// set width for menu item elements
	$('#topmenu ul.topmenu li.item a.item').each(function(){
		$(this).parent().css('width', $(this).outerWidth() + "px");
	});
	
	// hover menubar items
	$("#menubar li.menu-item").hover(
	  function () {
	    $(this).addClass("hover");
	  },
	  function () {
	    $(this).removeClass("hover");
	  }
	);
	
	// top slider
	$('#topslideshow').nivoSlider({
			effect: 'slideInRight',
			directionNav:false,
	        controlNav: false, 
	        keyboardNav:false,
			pauseOnHover:false,
			pauseTime: 4000,
			beforeChange: function(o){
				
				$('#topslideshowtitle .title').html( '<br />' );
			},
			afterChange: function(o){
				var cs = $('#topslideshow').data('nivo:vars').currentSlide +1;
				var ts = $('#topslideshow').data('nivo:vars').totalSlides;
				
				var currentImage = $('#topslideshow').data('nivo:vars').currentImage;
				var text = $(currentImage).attr('alt');
				$('#topslideshowtitle .title').html( text );
				$('#topslideshowinfo').html( cs + ' van ' + ts);
				
			}
		}
	);

	// projects photo album
	$("a[rel='project']").colorbox({transition:"fade", current: "", next: "volgende", previous: "vorige", close: "x"});
	
	// route lightbox
	$('a[href*="Route/lightbox"]').colorbox({iframe: true, width:800, height: 500, close: 'sluiten'});
	
	// attr placeholder support
	if (!Modernizr.input.placeholder){
		$('input[placeholder], textarea[placeholder]').each(function(){
			var ielm = $(this);
			if ( ielm.val() === ''){
				ielm.val( ielm.attr('placeholder'));
			}
			if ( ielm.val() == ielm.attr('placeholder') ) {
				ielm.addClass('placeholder');
			}
			
			ielm.focus(function () {
				if ( ielm.attr('placeholder') == ielm.val() ){
					ielm.removeClass('placeholder').val("");
				}
			}).blur(function () {
				if ( ielm.val() === "" ){
					ielm.addClass('placeholder').val( ielm.attr('placeholder') );
				}
			});
		});
	}
	
});

