posi=0;

function showLabel(msg,posz){
	posi=posz;
    $('#msglabel').html(msg);
    $('#msglabel').fadeIn();    
}

function hideLabel(msg){
    $('#msglabel').css("display","none");
    $('#msglabel').html();
}

var RecaptchaOptions = {
    theme : 'clean'
 };


$(document).ready(function() {

    $('.bs-itemfull').hover(function(e){
    	if(posi<18){
	   		$('#msglabel').css("left",e.pageX+20);
   			$('#msglabel').css("top",e.pageY+10);
   		} else {
	   		$('#msglabel').css("left",e.pageX-340);
   			$('#msglabel').css("top",e.pageY-180);
		}
   	});


	$('#content').fadeIn('slow', function() {
        //start banner rotation
		rotation = setInterval("rotateBanner()",6000);        
      });
});

var currentbanner=1;
function rotateBanner(){
	currentbanner++;
	if(currentbanner==banners.length){
		currentbanner=1;
	}
	midleftChange(currentbanner,'',banners[currentbanner]);
}

function slideIt(item){
	if ($('#'+item).is(":hidden")) {
		$('#'+item).slideDown();
	} else {
		$('#'+item).slideUp();
	}	
}

function slideIt2(item){
	$('.agendahidden').each(function(index) {
		if($(this).is(":hidden")) { } else {
			$(this).slideUp();
		}
	});

	$('#'+item).slideDown();
	
}


var active=0;

function slideDiv(item2){
	active=1;
	var checkdd = [];	
	checkdd[0]="conference";
	checkdd[1]="festival";
	checkdd[2]="about";
	
	for (i=0;i<checkdd.length;i++){
		var item = checkdd[i];
		if(item==item2){
			if ($('#dropdown_'+item).is(":hidden")) {
				$('#dropdown_'+item).slideDown();
			} 
		} else {
			if ($('#dropdown_'+item).is(":hidden")) {
			} else {
				$('#dropdown_'+item).slideUp();
			}
		}	
	}
}


function timeHide(){
	active=0;
	var timeo = setTimeout("hideDiv()",1000);
}

function hideDiv(){
	if(active==0){
		$('#dropdown_conference').slideUp();
		$('#dropdown_festival').slideUp();
		$('#dropdown_about').slideUp();
	}
}

function midleftChange(nr,link,newimg){
	$('#midleft_mask').html("<img src='http://www.jazzdag.nl/img/midleft-mask-"+nr+".png' />");

	$('#midright_content').fadeOut('fast',function(){
		$('#midright_content').html("<a href='"+link+"'><img src='http://www.jazzdag.nl/assets/image.php?width=563&image=/content/img/homeitems/"+newimg+".jpg' border=0 width=563 /></a>");
		$('#midright_content').fadeIn('slow',function(){
			$('#midright_back').html("<a href='"+link+"'><img src='http://www.jazzdag.nl/assets/image.php?width=563&image=/content/img/homeitems/"+newimg+".jpg' border=0 width=563 /></a>");	
		});
	});
}


function changelan(lan){
	if(lan==1){ 
		lan=2;	
	} else {
		lan=1;	
	}
	var pathname = window.location.pathname;
	if(pathname.substr(pathname.length-1,1)=="/"){
		pathname=pathname.substr(0,pathname.length-1);
	}
	document.location.href=pathname+'/?lan='+lan;
}

function midleftSelect(nr,link,newimg){
	if(link!=''){
		document.location.href=link;
	}	
}

jQuery(document).ready(function(){

	$('input').focusin(function(){
		//p=$(this).offset();
		movearrows();
	});
		
	  setInterval(function(e) {
          // Do something every 2 seconds
		 $('#content').hover(function(e){
				//clearQueue()
				var x = e.pageX;
				var y = e.pageY-26;
		
				// $('#arrowbot').animate({
				// 	left:e.pageX
				// },'slow');
				
				// $('#arrowright').animate({
				//	top:e.pageY
				// },'slow');
		
				//$('#debug').html(x+" "+y);
		
	});
		  
    }, 1000);
	

	
	$('textarea').focusin(function(){
			p=$(this).offset();
			movearrow(p.top);
	});

	$('a').hover(function(){
			p=$(this).offset();
			movearrow(p.top);
	});
	
   	
});

function movearrows(e){


}


function subscribe(email,voornaam,achternaam){
	$.ajax({
	 	url: 'http://www.jazzdag.nl/pages/sub.php?email='+escape(email)+'&voornaam='+escape(voornaam)+'&achternaam='+escape(achternaam),
  		success: function(data) {
	    	$('#newsletterform').html(data);
    	}
  	});
}

function validate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   return reg.test(address);
}


function validateme(){
	var email = document.forms['newsletter'].email.value;
	var voornaam  = document.forms['newsletter'].voornaam.value;
	var achternaam  = document.forms['newsletter'].achternaam.value;
	
	error='';
	if(email=='' || validate(email)==false || email=='Your email address'){		error += "Email address \n";	}
	if(voornaam=='' || voornaam=='Your first name'){							error += "First Name \n";				}
	if(achternaam=='' || achternaam=='Your last name'){							error += "Last Name \n";				}
	
	if(error==""){
		//document.forms['newsletter'].submit();
		subscribe(email,voornaam,achternaam);
	} else {
		alert("Vul aub de onderstaande velden juist in:\n Please enter the following field(s) correctly:\n\n"+error);
	}
}



/** VIDEO PREVIEW FUNCTIONS **/

function startLoopVideo(id){
	videoid=id;
	videoloop=1;
	videointerval = setInterval("loopVideo()",500);
}

function endLoopVideo(){
	clearInterval(videointerval);
	document[videoid].src = "http://img.youtube.com/vi/"+videoid+"/1.jpg";
}

function loopVideo(){
	videoloop++;
	if(videoloop==4){
		videoloop=1;
	}
	document[videoid].src = "http://img.youtube.com/vi/"+videoid+"/"+videoloop+".jpg";
}
