
$(function(){ $("#footerform label").inFieldLabels(); });
$(function(){ $("#freeform label").inFieldLabels(); });
$(function(){ $("#quickscanform label").inFieldLabels(); });
$(function(){ $("#nbform label").inFieldLabels(); });

$(document).ready(function() {
	
	/* ========== SOCIAL MEDIA ICONS ========== */	
	$('#socialmedia a').hover(function() {
	      $(this).animate({ left : "12px"}, 150);            
	  }, function() {
	      $(this).animate({ left : "0px" }, 150);
	});
	
	// ipad en android draggable fix	  
	if($('.ismobile').length){
	  $('#sortable1 li').click(function() {
				  
		 var hasclass = $(this).hasClass('selected')
		
		 if(hasclass == true){
			 $(this).removeClass('selected');
			 $('#sortable1').append($(this));
		 }else{
			 $(this).addClass('selected');
			 $('#sortable2').append($(this)); 			 	
		 }
		 
		 // update the hidden field
		 var result = $("#sortable2").sortable("toArray");
		 $("#menu").val(result);
				
	  });
	}
	
    jQuery('a.popup').click('click', function(){
        newwindow=window.open($(this).attr('href'),'','height=400,width=760');
        if (window.focus) {newwindow.focus()}
        return false;
        });
		
	/* ========== PARALLAX ANIMAL FARM - TEAM PAGINA  ========== */
		jQuery('#animal-farm').jparallax();

		
	/* ======= JS voor de om en om cases ========== */
	
	if($('body.cases .item.casuslist')){
		$('.item.casuslist:odd').each(function() {		
			var imghtml = $(this).find('div.image').html();
			$(this).addClass('twisted');
			$(this).find('div.image').hide();
			$(this).append('<div class="image">'+imghtml+'</div>');	
		});
	}
	
	/* ======= JS voor de form validatie ========== */
	
	if($('.offerte form')){		
		$(".offerte form").validate();
		$('.offerte div.inputtext').click(function() {
			$(this).find('input').focus();
		});		
	}
	if($('form#footerform')){		
		$("form#footerform").validate();
		$('div.formlabel span').click(function() {
			$(this).parent().find('input').focus();
		});
	}
	if($('form#quickscanform')){		
		$("form#quickscanform").validate();
		$('.diensten div.inputtext').click(function() {
			$(this).find('input').focus();
		});
	}
	if($('form#boekjeform')){		
		$("form#boekjeform").validate();
		$("form#boekpdfform").validate();
	}
	if($('form#nbform')){		
		$("form#nbform").validate();		
	}
	
	/* ======= LINK EXTERN ========== */	
	$("a[href^='http']").filter(function(){
		var href = $(this).attr("href");
		var same_domain = (href.indexOf(document.domain) != -1);
		return !same_domain;
	}).addClass("external").attr({ target: "_blank" });

	
	/* ========== WORKSHOP LIST HOVER ========== */

	$('.linklist.images ul li').hover(function() {
			$(this).find('span.text').stop().delay(300).animate({top:'-36px'},{duration:200});
		}, function() {
			$(this).find('span.text').stop().animate({top:'0px'},{duration:200});
	});
 
	/* ========== FANCYBOX ========== */
	
	$(".bestel-bt").fancybox({
		'titlePosition'		: 'inside',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});
	
	/* ========== TOOLTIPS (portfolio) ========== */
	$('.icons span').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		fade: 150
	});
		
	/* ========== TOOLTIPS (footer) ========== */
	$('.footer .top h2').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		fade: 150
	});
	
	/* ========== TOOLTIP (casus -> easter egg) ========== */
	$('.tt').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		fade: 150
	});
	
/* ========== DISPLAY HOMEPAGE ========== */
	$('#display-home').cycle({
		        fx:     'blindY',
				sync: 0,
		        speed:  1500,
		        timeout: 5000,
		        pager:  '#slidenav',
				slideExpr: 'img',
				cleartype: true,
				cleartypeNoBg: true,
				prev:	'#prev',
				next:	'#next',
				pause: true
		    });
			
			
$('#toggle_slider a').click(function() {
	
	if ($('#display-home').height() == 65) {
          $('#display-home').animate({
                height: '425'
          }, 1000);
          $('#toggle_slider a').html('sluiten');
    }else{
          $('#display-home').animate({
                height: '65'
          }, 1000);
          $('#toggle_slider a').html('openen');
    }
    return false;
}); 			
			

	/* ========== PORTFOLIO SLIDER ========== */
		$('#portfolio-slider').cycle({
			        fx:     'fade',
					sync: 1,
			        speed:  2000,
			        timeout: 6000,
			        pager:  null,
					slideExpr: 'div.si',
					cleartypeNoBg: true,
					prev:	'#prev',
					next:	'#next'
			    });
			
		$('#portfolio-slider-text').cycle({
			        fx:     'fade',
					sync: 1,
			        speed:  2000,
			        timeout: 6000,
			        pager:  null,
					slideExpr: 'div.st',
					cleartypeNoBg: true,
					prev:	'#prev',
					next:	'#next'
		});

						
/* ========== OFFERTE RADIO ========== */	
		
	/* check radio based on html class .radiobox.checked */
	$('.radiobox.checked').find('input').attr("checked", "checked");
		
	/* check radio based on div.radiobox click */
	$('.radiobox').click(function() {
		$('.radiobox').removeClass('checked');
		$(this).addClass('checked');
		$(this).find('input').attr("checked", "checked");
	});
		
	/*$('label.small').bind('click', function(){
		$('#radio-small').click();
		$('.radiobox label').removeClass('checked');
		$(this).addClass('checked');
	});
	$('label.medium').bind('click', function(){
		$('#radio-medium').click();
		$('.radiobox label').removeClass('checked');
		$(this).addClass('checked');
	});
	$('label.large').bind('click', function(){
		$('#radio-large').click();
		$('.radiobox label').removeClass('checked');
		$(this).addClass('checked');
	});*/
});

/* ========== CUFON ========== */

 Cufon.replace('h2, h3, .logolist a, .pagetitle span, .subnav .suptitle, .contentbox h1, #sortable2 .suptitle, .call span, .slide-title, .ie6 span.title, .sidebar h4', {fontFamily: 'boton-m' });
 Cufon.replace('a.more, .pagetitle .subtitle, .linklist h3, a.go-back, .offerte .textarea h2, .droplist p, .call h2, .portfolio .item .image p', {fontFamily: 'amtw-m' });
 Cufon.replace('.footer .textarea h3', {fontFamily: 'amtw-l' });
 Cufon.replace('.ie6 span.subtitle', { fontFamily: 'boton-li'});
 Cufon.replace('p.intro', {fontFamily: 'boton-li' });
 Cufon.replace('.item-large .title', {
 	fontFamily: 'boton-li',
		hover: {
			color: '#5c5c5c'
		}
	});

	
/* ========== SCROLL TO ========== */
		
		jQuery(function($) {
					
					$(".to-top").click(function() {
						$.scrollTo('.header', {duration: 1000});
						return false;
		    		});
					
					$(".to").click(function() {
						var classString = '.item.'+$(this).attr('id');
						$.scrollTo(classString, {duration: 1000});
						return false;
		    		});
					
		});

/* ========== END ========== */
		
		jQuery(function($) {
			$("ul.droptrue").sortable({
				connectWith: "ul"
			});

			$("ul.dropfalse").sortable({
				connectWith: "ul",
				dropOnEmpty: false
			});

			$("#sortable1, #sortable2").disableSelection();		
				
			$("#sortable2").sortable({
			   update: function(event, ui) { 
			   		var result = $("#sortable2").sortable("toArray");
					$("#menu").val(result);			
				
					 var n = $("#sortable2 li").length;
					 if(n%2 == 0 && n <= 12){
					 	var m = (n * 49)+80;			
					 	$("#sortable2").animate({ height: m}, 500);				 
					 }				 

			   }
			});
			
		});
		
