/*$(document).ready(function(){
	//goFullScreen(201,0)
	
	//Cufon.replace('a', { hover: {color: '#3769A0'} });
	//Cufon.replace('	#altContent h1, #altContent span, .menuTitle, .HTMLcontent h1, .HTMLcontent span, .HTMLcontent p, .HTMLcontent li,.HTMLcontent label, #FXup, #Submenu, footer a, footer span, header', { fontFamily:'DIN' });
	
	
	Cufon.replace('.menuItem, .SubmenuItem', {  fontFamily:'DIN', hover: {color: '#3769A0'} });
	//Cufon.replace('h1' ,{  fontFamily:'DIN' });
	
	
	
	//$('.menuItem').mouseover(onMenuItemOver);
	//$('.menuItem').mouseout(onMenuItemOut); 
})*/


/*
 *		Vlaggetjes
 */
$(function(){
	if(	$('#vlag_nl').attr('src').indexOf('not')!=-1 ) {
		$('#vlag_nl').hover(showNLflags,showENflags)
	}else{
		$('#vlag_en').hover(showENflags,showNLflags)
	}
})

function showNLflags(){
	$('#vlag_en').attr('src','/_images/gb_not.png')
	$('#vlag_nl').attr('src','/_images/nl.png')
}

function showENflags(){
	$('#vlag_en').attr('src','/_images/gb.png')
	$('#vlag_nl').attr('src','/_images/nl_not.png')
}





function goFullScreen(id,count,time){
	if(time == null) time = 0.1
	
	var loadUrl		=	'/_php/show_projectMedia.php';
	$('#fullScreenMedia').load(loadUrl,{projectID:id,currentBlok:count-1, startTime:time}, 
		function(response, status, xhr) {
			scaleImages()
			$('#wrapper').animate2({top:'-100%'}, 1000);
			
			$('#mediaHolder img').click(goNormalScreen)
			
			//$.address.path(currentPage+" ")
		}
	)
}
function goNormalScreen(){
	$('#wrapper').animate2({top:'0%'}, 1000, function(){
		$('#fullScreenMedia').html('')
	});
}

function onMenuItemOver(){
	$(this).css({'color':'#3769A0'})
	//Cufon.refresh();
}

function onMenuItemOut(){
	$(this).css({'color':'black'})
	//Cufon.refresh();
}

function onMenuActive(name){
	$('.menuItem').attr('class', 'menuItem' )
	
	if(name==''){
		$('#MENUhome').attr('class', 'menuItem activeMenu' )
	}else{
		//alert('home')
		$('#MENU'+name).attr('class', 'menuItem activeMenu' )
	}
	
	
	//Cufon.replace('a', { hover: {color: '#3769A0'} });
	Cufon.refresh();
}

function onSocialOver(){
	$(this).animate2({bottom:8}, 300);
}function onSocialOut(){
	$(this).animate2({bottom:0}, 300);
}

function startSlideSocial(){
	var counter	=	0;
	$('.socialMedium').each(function(){
		$(this).delay(1500+counter*200).animate({bottom:8}, 300,function(){
			$(this).animate({bottom:0}, 300)
		});
		counter++
	})
}



var map = null;
function onPageLoaded(){
	//Start render
	var curHTML	=	$currentBlok.html().toLowerCase()
	if(curHTML.indexOf('bad request')!= -1	||  curHTML.indexOf('bad request')!= -1){
		openNewContent(currentPage)
	}else{		
		if(	$currentBlok.find('.HomeBlok').length==0 ){
			startBackSwitching();
			
			/*
			 *
			 *		LET IT SNOW!
			 *
			 */
			
			if(		$('.snowfall-flakes').length == 0	){
				//$('#background').snowfall({flakeCount:$(window).width()/50, round : true, minSize: 5, maxSize:8});
			}else{
				//$('.snowfall-flakes').animate({'opacity':1},500)
			}
			
			
		}
		
		if(	$currentBlok.find('.HomeBlok').length>0 ){
			loadHome()
			//$('.snowfall-flakes').animate({'opacity':0},500)
		}else if(	$currentBlok.find('.DienstBlok').length>0 ){
			initDiensten()
		}else if(	$currentBlok.find('#bingMap').length==1 ){
			//CONTACT
			startSlideSocial()
			$('.socialMedium').mouseover(onSocialOver);
			$('.socialMedium').mouseout(onSocialOut);
			
			$('#bingMap').delay(1).queue(function(){
				map = new VEMap('bingMap');
				mapOptions = new VEMapOptions();
				mapOptions.BirdseyeOrientation 	=	VEOrientation.South;
			
	       		map.LoadMap(
	        		new VELatLong(52.088282631377677, 5.12937581641221), 
	        		18, 
	        		VEMapStyle.Birdseye,
	        		false,
	        		VEMapMode.Mode2D,
	        		true,
	        		0,
	        		mapOptions
	       		);
			})
			
	       	
	       	//init form checks
	       	$('#contactForm').submit(checkContactForm);
	       	$('#nieuwsbriefForm').submit(nieuwsBriefForm);
	       	
	       	
	       	//TESTIMONIALS
		}else if( $currentBlok.find('#testimonialOverzicht').length != 0 ){
			var $overzicht		=	$currentBlok.find('#testimonialOverzicht');
			var pagina			=	0;
			var pagemax			=	Math.ceil($('.testimonial0, .testimonial1').length /4)-1;
			$('#prevTestimonials').hide()
			
			$('#nextTestimonials').click(function(){
				pagina++
				$('#testimonialOverzicht').animate2({'left':-pagina*100+'%'},1000)
				
				
				$('#prevTestimonials').show('slow')
				if(pagina==pagemax){
					$('#nextTestimonials').hide('slow')
				}
			})
			$('#prevTestimonials').click(function(){
				pagina--
				$('#testimonialOverzicht').animate2({'left':-pagina*100+'%'},1000)
				
				$('#nextTestimonials').show('slow')
				if(pagina==0){
					$('#prevTestimonials').hide('slow')
				}
			})
		}/*else if(	$currentBlok.find('#flashContent').length != 0	){
			$('#background').snowfall('clear');
		}*/
		
		else if(!hasFlashInstalled && $currentBlok.find('#flashContent').length != 0 ){
			// CASES WITHOUT FLASH
			initCases();
		}
		
		if( $currentBlok.find('#bingMap').length<1 ){
			$('.ero, .ero-progressAnimation, .VE_Panel_el, #MSVE_navAction_palette').remove()
		}
	}
}

function removeTestimonial(){
	//$currentBlok.find('#testimonialOverzicht .testimonial:first').remove()
}

function checkContactForm(){
	var formValid	=	true;
	var mail 		=	$('#contactForm #email1').val();
	var phone		=	$('#contactForm #tel').val();
	var name 		=	$('#contactForm #naam').val();
	
	if( name.length <7 	){
		formValid	=	false;
		$('#contactForm #naam').css('border-color','red');
	}else{
		$('#contactForm #naam').css('border-color','')
	}
	
	if( !CheckPhone(phone)	){
		formValid	=	false;
		$('#contactForm #tel').css('border-color','red');
	}else{
		$('#contactForm #tel').css('border-color','')
	}
	
	
	
	if(	!CheckMail(mail) ){
		formValid	=	false;
		$('#contactForm #email1').css('border-color','red');
	}else{
		$('#contactForm #email1').css('border-color','')
	}
	
	if(formValid){
		var sendData	=	{  	naam		: name,		email 		: mail,		tel			: phone		};
		$.post('/_php/send_mail.php', sendData, function(response){
			$('.infoBlokBig h1:first').html('Bedank voor je interesse');
			$('.infoBlokBig span:first').html('We nemen zo spoedig mogelijk contact met u op.');
			$('#contactForm').html('')
			Cufon.refresh();
		});
	}
	
	return false;
}



function nieuwsBriefForm(){
	var formValid	=	true;
	var mail 	=	$('#nieuwsbriefForm #email2').val();
	
	if(	!CheckMail(mail) ){
		formValid	=	false;
		$('#nieuwsbriefForm #email2').css('border-color','red');
	}else{
		$('#nieuwsbriefForm #email2').css('border-color','')
	}
	
	if(formValid){
		var sendData	=	{  	email : mail, 	format : 'h', 	id : "frmSS1"};
		$.post('http://www.fxmedia.nl/nieuwsbrief/form.php?form=1', sendData, function(response){
			$('.infoBlokBig h1:nth-child(2)').html('Bedank voor je interesse');
			$('.infoBlokBig span:last').html('Vanaf nu blijft u volledig op de hoogte van FXmedia.');
			$('#nieuwsbriefForm').html('')
			Cufon.refresh();
		});
	}
	
	return false;
}


function CheckMultiple1(frm, name) {
	for (var i=0; i < frm.length; i++){
		fldObj = frm.elements[i];
		fldId = fldObj.id;
		if (fldId) {
			var fieldnamecheck=fldObj.id.indexOf(name);
			if (fieldnamecheck != -1) {
				if (fldObj.checked) {
					return true;
				}
			}
		}
	}
	return false;
}

function CheckMail(mail) {
	var email_re = /[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i;
	return email_re.test(mail);
}

function CheckPhone(number){
	//var phone_re = /^(\d{3}-?\d{7}|\d{4}-?\d{6}|\d{10})$/;
	//return phone_re.test(number);
	return (number.length > 9);
}
