// JQUERY CUSTOM COMMANDS
//$(document).ready( function() {  // start javascript when document is loaded
jQuery(document).ready(function() {
	
	/* SUBMENU */
	jQuery('#subMenu > ul > li > a').addClass('level1');
	Cufon.replace('#subMenu a.level1', { hover: true });
	
	/* CONTACT TOGGLE */
	jQuery('.contactList .cAnswer').hide();
	jQuery('.contactList .cQuestion a').click(function() {
		jQuery(this).parents('.contactList').find(".cAnswer").slideUp(200); // Hide all answers
		jQuery(this).parents('.contactList').find('li').removeClass("active");
	    jQuery(this).parents('li').find(".cAnswer").slideDown(200); // Show current answer
		jQuery(this).parents('li').addClass("active");
		return false;		
	});
		//extra remove active
	jQuery("#contactBox").mouseleave(function() {			
		jQuery('.contactList').find(".cAnswer").slideUp(200); // Hide all answers
		jQuery('.contactList').find('li').removeClass("active");
	});	
	
	
	
	/* CLIENT LOGOS TOGGLE */
	jQuery('#clientLogos .midNext').hide();
	jQuery('#clientLogos .midFeatured a').hover(function() {		
	    jQuery(this).parents('#clientLogos').find(".midNext").slideDown(200); // Show current answer	
		jQuery(this).parents('li').addClass('hover');			
	}, function() {
	    jQuery(this).parents('li').removeClass('hover');
	});
		//extra remove active
	jQuery("#clientLogos").mouseleave(function() {			
		jQuery('#clientLogos').find(".midNext").slideUp(200); // Hide all answers		
	});	
	
	
	/* Left column more services choice */
	jQuery('.leftColumn .moreInfo ul.moreChoice li ul').hide();	
	jQuery('.leftColumn .moreInfo ul.moreChoice li a').hover(function() {		
	    jQuery(this).parents('.leftColumn .moreInfo ul.moreChoice li').find("ul").slideDown(200); // Show current answer		
		return false;		
	});
	
	//extra remove active
	jQuery(".leftColumn .moreInfo ul.moreChoice").mouseleave(function() {			
		jQuery('.leftColumn .moreInfo ul.moreChoice li').find("ul").slideUp(200); // Hide all answers		
	});	
	

			
	/* MENU HOVERS */
	jQuery('#topMenu li, #services li, .leftColumn .services li, .tabMenu li, .projectThumbs img, #clientLogos .midNext li').hover(function() { // IE6 does not support :hover on elements other than <a>
	    jQuery(this).addClass('hover');
	}, function() {
	    jQuery(this).removeClass('hover');
	});
	
	
			
	// INPUT FOCUS & BLUR
	jQuery('input.textfield, textarea.textarea, select.select').focus(function() {
	    jQuery(this).addClass("focus");
	});
	jQuery('input.textfield, textarea.textarea, select.select').blur(function() {
	    jQuery(this).removeClass("focus");
		jQuery(this).removeClass("error");
		jQuery(this).parents("li").find("div.error").empty();
	});
	
	// HIDE EMPTY ERROR FIELDS
	jQuery('ul.formfields div.error:empty').hide();
	
	
	
	
	// ACCOUNT INPUT LABELS as background
	// fill or empty name field onDefault
	if (jQuery(".inputName").val() == "") {
		jQuery(".inputName").css({ backgroundImage : "url(images/account_input_name.gif)" });
	} else {
		jQuery(".inputName").css({ backgroundImage : "url(images/account_input_empty.gif)" });
	};
	// fill or empty email field onDefault
	if (jQuery(".inputEmail").val() == "") {
		jQuery(".inputEmail").css({ backgroundImage : "url(images/account_input_email.gif)" });
	} else {
		jQuery(".inputEmail").css({ backgroundImage : "url(images/account_input_empty.gif)" });
	};	
	
	// fill or empty clientName field onDefault
	if (jQuery(".clientName").val() == "") {
		jQuery(".clientName").css({ backgroundImage : "url(images/account_client_name.gif)" });
	} else {
		jQuery(".clientName").css({ backgroundImage : "url(images/account_input_empty.gif)" });
	};	
	// fill or empty clientPassword field onDefault
	if (jQuery(".clientPassword").val() == "") {
		jQuery(".clientPassword").css({ backgroundImage : "url(images/account_client_password.gif)" });
	} else {
		jQuery(".clientPassword").css({ backgroundImage : "url(images/account_input_empty.gif)" });
	};		
		
	// empty fiels onClick
	jQuery(".inputName, .inputEmail, .clientName, .clientPassword").click(function() {
		jQuery(this).css({ backgroundImage : "url(images/account_input_empty.gif)" });
	});
	// empty fiels onFocus
	jQuery(".inputName, .inputEmail, .clientName, .clientPassword").focus(function() {
		jQuery(this).css({ backgroundImage : "url(images/account_input_empty.gif)" });
	});
	
		
	// refill namefield onBlur
	jQuery(".inputName").blur(function() {
		if (jQuery(".inputName").val() == "") {
			jQuery(".inputName").css({ backgroundImage : "url(images/account_input_name.gif)" });
		} else {
			jQuery(".inputName").css({ backgroundImage : "url(images/account_input_empty.gif)" });
		};
	});
	// refill emailfield onBlur
	jQuery(".inputEmail").blur(function() {
		if (jQuery(".inputEmail").val() == "") {
			jQuery(".inputEmail").css({ backgroundImage : "url(images/account_input_email.gif)" });
		} else {
			jQuery(".inputEmail").css({ backgroundImage : "url(images/account_input_empty.gif)" });
		};
	});	
	// refill passfield onBlur
	jQuery(".clientName").blur(function() {
		if (jQuery(".clientName").val() == "") {
			jQuery(".clientName").css({ backgroundImage : "url(images/account_client_name.gif)" });
		} else {
			jQuery(".clientName").css({ backgroundImage : "url(images/account_input_empty.gif)" });
		};
	});
	// refill passfield onBlur
	jQuery(".clientPassword").blur(function() {
		if (jQuery(".clientPassword").val() == "") {
			jQuery(".clientPassword").css({ backgroundImage : "url(images/account_client_password.gif)" });
		} else {
			jQuery(".clientPassword").css({ backgroundImage : "url(images/account_input_empty.gif)" });
		};
	});
	
	
	
   jQuery('input[type="text"]').focus(function() {   
       if (this.value == this.defaultValue){   
           this.value = '';   
       }   
       if(this.value != this.defaultValue){   
           this.select();   
       }   
   });   
   jQuery('input[type="text"]').blur(function() {   
       if (jQuery.trim(this.value) == ''){   
//	   		alert('Bauke');
			this.value = (this.defaultValue ? this.defaultValue : '');   
       }   
    });   
	

	
	// let the the grey box in the left-column grow longer
	mainContentMidSection = jQuery("#mainContent #midSection").height();	
	leftColumnTopMid = jQuery(".leftColumn .topMid").height();	
	
	newHeightMoreInfo = (mainContentMidSection - leftColumnTopMid)-115;
	
	// voor IE6
	if (jQuery.browser.msie && jQuery.browser.version == 6){ 	
	} 	else {
		jQuery(".leftColumn .moreInfo").css("height",newHeightMoreInfo);
	}
	

		
	
	
	
	
	
	
	//tab menu - contact
	//count master-tabs
	//make jquery triggers
	//set remove all active
	//set .this active
	var n = jQuery(".tabMenu li").length;
	var letter;
	height_body = jQuery("body").height();
	
	
	
	for (var i=1; i < (n+1); i++){		//n = 3 means: 2 master-tabs
		if (i==1)	   {	letter = 'A';	}
		else if (i==2) {	letter = 'B';	}
		else if (i==3) {	letter = 'C';	}
		else if (i==4) {	letter = 'D';	}
		else if (i==5) {	letter = 'E';	}  
		else if (i==6) {	letter = 'F';	} 
		
		//alert (["#masterTabcontent"+letter]);
		
		plaatsMasterButtons(letter);	
	} 
	
	function plaatsMasterButtons(letter) {
		jQuery([".showUnit"+letter]+ " a").click(function() {
			jQuery('li').removeClass('active'); // make tab inactive
			jQuery(this).parents("li").addClass("active"); // make this tab active
			jQuery('.unit').removeClass('active'); // hide other content			
			jQuery("#unit"+letter).addClass('active'); // show this content
			return false;
		});
	}


	var n2 = jQuery(".tabMenuArchive li").length;
	var letter2;
	height_body2 = jQuery("body").height();
	
	
	
	for (var i2=1; i2 < (n2+1); i2++){		//n = 3 means: 2 master-tabs
		if (i2==1)	   {	letter2 = 'A';	}
		else if (i2==2) {	letter2 = 'B';	}
		else if (i2==3) {	letter2 = 'C';	}
		else if (i2==4) {	letter2 = 'D';	}
		else if (i2==5) {	letter2 = 'E';	}  
		else if (i2==6) {	letter2 = 'F';	} 
		
		//alert (["#masterTabcontent"+letter]);
		
		plaatsMasterButtons(letter2);	
	} 
		
	
	
	
	// RANDOM IMAGE ARRAY -> JQUERY + CYCLE EXTENTION
	var arraySize = 10;   			//aantal foto hokken	
	var waitForNextSlide = 3000;  	//wachttijd per slide in miliseconden
	
	
	for (var i=1; i < (arraySize+1); i++){	   		
		bouwBlok(i)
	} 		
	
	
	function bouwBlok(blokNo) {   	//set de blokken en pauzeer
		jQuery("#s"+blokNo).cycle({ 
			speed:   400, 
			nowrap: 1				//niet herstarten --> naar slide1			
			//end: talkMaster		//wat te doen na een loop
		});	 		
		jQuery("#s"+blokNo).cycle('pause'); 
	}	
	
	
	var randomInt;
	var prevNo = 0;
	var hoverCheck = false;	
	function talkMaster() { 			
		if (hoverCheck == false){				
			randomInt = jQuery.randomBetween(1, arraySize)					//bedenkt een random getal	
			
			if (randomInt == prevNo){									//praktisch nooit 2 maal hetzelfde 'random' getal					
				randomInt = jQuery.randomBetween(1, arraySize)				//bedenkt een random getal					
			}	
			
			else if (randomInt > arraySize){							//check voor problemen, > of < dan de verwachte waardes
				//alert ('randomInt > arraySize' + randomInt);
				randomInt = arraySize;
			}
			else if (randomInt < 1){	
				//alert ('randomInt < 1' + randomInt);
				randomInt = 1;
			}
			
			for (var i=1; i < (arraySize+1); i++){	   					//laat alle foto hokken pauzeren en beginnen op foto positie 1 (==0)			
				jQuery("#s"+i).cycle(0);  
				jQuery("#s"+i).cycle('pause'); 		 
			} 	
						
			startMaster(randomInt);	        							//start een random slide       
			prevNo = randomInt;	
		}	
	}	
	
	
	function startMaster(blokNo) { 										//terug naar positie 1 (==0) en ga verder (==resume)
		if (hoverCheck == false){				
			
			jQuery("#s"+blokNo).cycle(0);  
			jQuery("#s"+blokNo).cycle('resume');

			t = setTimeout(function(){
				talkMaster();	         								//start iedere x seconden de slideshow                               
			}, waitForNextSlide); 										// adjust your time here 	(bv. 3000)			
		}		
	}
	
	
		
	jQuery('#clients a').hover(function() { 									//denk aan de hooft div naam
		//jQuery(this).addClass('hover');
		hoverCheck = true;												//belangrijke check
		
		for (var i=1; i < (arraySize+1); i++){	   						//laat alle foto hokken pauzeren en beginnen op foto positie 1 (==0)			
			jQuery("#s"+i).cycle(0);  
			jQuery("#s"+i).cycle('pause'); 		 
		} 	
				
		jQuery(this).parents("li").cycle(1); 								//voor list items
		jQuery(this).parents("li").cycle('pause'); 
		clearTimeout(t); 
		
	}, function() {
		//jQuery(this).removeClass('hover');
		hoverCheck = false;												//belangrijke check
		
		jQuery(this).parents("li").cycle(1);
		jQuery(this).parents("li").cycle('resume'); 
		
		talkMaster();													//herstart de cycle na een hover actie
	});	
	
		
	talkMaster();														//start de cycle
}); // end ready function



