/* Predefined variables */
$(document).ready(function() {

	// Animatie background
	AnimateBackground();
	
	// Animatie logo's
	// AnimatePartnerLogos();
 // AnimateSponsorLogos();
 // AnimateSubsidentenLogos();
	
	// Menu follow	
	MenuFollow();

	// Email check 
	Emailcheck();


	/* Clear & Restore input */
	$('input.clearInput').bind({
		focus: function(){ $(this).val(''); },
		blur:  function(){ if ($(this).val() == "") $(this).val($(this)[0].defaultValue); }
	});


 $('a[rel*=newsletter_extended]').click( function() {
     var linkje = this.href;
     $('#nieuwsbriefblok').addClass("nieuwsbriefblok_big"); 
     $('#nieuwsbriefblok').load(linkje);
     return false;
 });		

 $('ul.blog').localScroll();
	
 $('a[rel*=program_item]').click( function() {
     var pos = this.name;
     var linkje = this.href;
     $(this).addClass("programma_item_big"); 
     GetContent('item_',linkje,pos);   
     return false;
 });		

 $('a[rel*=program_item]').mouseover( function() {
     var pos = this.name;
     $('#overlay_'+pos).removeClass('overlayitem_inactive'); 
     $('#overlay_'+pos).addClass('overlayitem_active'); 
     return false;
 });		

 $('a[rel*=program_item]').mouseout( function() {
     var pos = this.name;
     $('#overlay_'+pos).removeClass('overlayitem_active'); 
     $('#overlay_'+pos).addClass('overlayitem_inactive'); 
     return false;
 });		

	// Sortering  
 $('a[rel*=sort_impressie]').click( function() {
     var linkje = this.href;
     var pos = this.name;
     GetContent('impressie_viewer',linkje,pos,'100%',0);   
     return false;
 });


 //Fancybox
 $('a[rel*=single_image]').fancybox({
    'padding'		: 0,
    'titleShow'	: true,
	   'titlePosition' 		: 'inside'
 });

 $('a[rel*=single_video]').fancybox({
    'padding'		: 10,
    'titleShow'	: true,
	   'titlePosition' 		: 'inside',
  		'width'				    : '75%',
		  'height'			    : '75%',
    'autoScale'       : false,
    'transitionIn'	  : 'none',
		  'transitionOut'   : 'none',
		  'type'				    : 'iframe'
 });

  broadFooter();
		
});

$(window).resize(function()  { broadFooter(); });

function broadFooter()
{
    var currentWidth = $('#footer').width();
    var windowWidth = $(window).width();
    var diffWidth = windowWidth-990;        
    $('#footer').css({ width: windowWidth, left: -(diffWidth/2) });
}

function GetContent(divje,pad,pos){
     $('#'+divje+pos).load(pad+'/ajax/', function() {
          //$.scrollTo(this, {top:"=100px",duration: 1000, axis:"y"});		
          return false;
     });
}

function MenuFollow(speed,cooldown){
      var menuIsOpen = true;
      var animReady  = false;

      setTimeout(function(){ animReady  = true; },cooldown);

     	$(window).scroll(function () {
          if (menuIsOpen && animReady) menuClose();
     	});


      function menuClose()
      {
          animReady = false;

          $('#menu-container').animate({ left: '-100%'},speed,function(){
                  setTimeout(function(){
                    menuIsOpen = false;
                    animReady  = true;
                  },cooldown);
                  $('#menu-open a').bind({
                        mouseover:     function(){
                                      if (!menuIsOpen && animReady)
                                      {
                                         menuOpen();
                                         $('#menu-open').animate({left: '100%'},5)
                                         $('#menu-open').unbind();
                                      }
                                   }
                        //mouseover: function(){ $(this).animate({left: '99%'},250) },
                        //mouseout:  function(){ $(this).animate({left: '100%'},250) }

                  });
          });
      }
      function menuOpen()
      {
          animReady = false;
          $('#menu-container').animate({ left: '0'},speed, function(){
              setTimeout(function(){
                menuIsOpen = true;
                animReady  = true;
              },cooldown);
          }); 
      }
}

function AnimateBackground() {
    /*
		$.fn.supersized.options = {  
			startwidth: 640,  
			startheight: 480,
			vertical_center: true,
			slideshow: true,
			navigation: false,
			transition: 1, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
			pause_hover: false,
			slide_counter: false,
			slide_captions: false,
			slide_interval:20000  
		};
   $('#supersize').supersized(); 
   */
};


function AnimatePartnerLogos() {
	$('#slider').nivoSlider({
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		animSpeed:500,
		pauseTime:3000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:false, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '', //Replace this with...
		controlNavThumbsReplace: '', //...this in thumb Image src
		keyboardNav:false, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
};


function AnimateSponsorLogos() {
	$('#slider2').nivoSlider({
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		animSpeed:500,
		pauseTime:3000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:false, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '', //Replace this with...
		controlNavThumbsReplace: '', //...this in thumb Image src
		keyboardNav:false, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
};

function AnimateSubsidentenLogos() {
	$('#slider3').nivoSlider({
		effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
		animSpeed:500,
		pauseTime:3000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:false, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '', //Replace this with...
		controlNavThumbsReplace: '', //...this in thumb Image src
		keyboardNav:false, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
};

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

function Emailcheck(){
	$("#Nieuwsbrief_Waarde").keyup(function(){ validate();	});
	$("#nieuwsbriefForm").submit(function(){ validate();	});


 function validate(){

		var email = $("#Nieuwsbrief_Waarde").val();
		if(email != 0)
		{
		if(isValidEmailAddress(email))
		{
			$("#validEmail").css({ "background-image": "url('/images/buttons/validYes.png')" });
   return true;

		} else {
			$("#validEmail").css({ "background-image": "url('/images/buttons/validNo.png')" });
   return false;
		}
		} else {
			$("#validEmail").css({ "background-image": "none" });
   return false;
		}

 }
}