$(document).ready(function() {

$("a.beeldbankImg").fancybox({
	'titlePosition'  : 'inside'
});

$(".vacaturesUitklap").each(function(){
	var vacId=$(this).attr("vacId");
	$("#vacaturesText_"+vacId).css('display','none');
	$(this).css('cursor','pointer');
	$(this).click(function (e) {
		e.preventDefault();
		$("#vacaturesText_"+vacId).slideToggle("slow");
	});
});

$("#homeSlide").each(function(){
	var timeoutID;
	var items=$('.slide',this);
	var crollerBlock=this;
	var counter=0;
	var maxBlocks=items.length;
	var idBlockInt=0;
	var _width=$(this).width();
	var _height=310;
	var _tijd=6000;
	var container=$('.container',this);
	var naviBlokjes=$('#homeSlideNavi li a');
	var timeoutID;
	
	naviBlokjes.each(function(i){
		$(this).click(function (e) {
			e.preventDefault();
			clearTimeout(timeoutID);
			idBlockInt=$(this).attr('slideId');
			showHomeItem();
		});
	});
		
	$(this).css({height:_height+'px',overflow:'hidden',top:'-10px'});
	items.show();	
	items.each(function(i){
		$(this).css({position:'absolute',left:+(_width*i)+'px',width:_width+'px',border:'none',top:'10px'});
	});
	container.css({position:'relative',left:'0px'});
	
	var showHomeItem= function (){
		$('#homeSlideNavi a').removeClass('active');
		$('#SlideNaviNr'+idBlockInt).addClass('active');
		//alert(idBlockInt);
	  container.stop(true).animate({"left": (idBlockInt*_width*-1)/1+"px"}, "slow");
		timeout();
	}
	var timeout=function (){
		timeoutID=setTimeout(function() {
			idBlockInt++;
			if(idBlockInt >= maxBlocks) idBlockInt=0;
			showHomeItem();
			 }, _tijd); 
	}
	timeout();
});


	$('form .filterSoort, form .filterOrder').change(function () {
		window.location.href = $(this).val();
		});

	$(".itemHover").hover(
	      function () {
	        $(".overItem-"+$(this).attr('itemid')).css("background-color","WhiteSmoke");//AliceBlue
	      },
	      function () {
	        $(".overItem-"+$(this).attr('itemid')).css("background-color","transparent");
	      }
	    );
	$(".itemHover").each(function(){
	//	$(this).css({cursor:'pointer',position:'relative'}).before("<span style='position:absolute;width:"+$(this).width()+"px;height:"+$(this).height()+"px;background-color:green;' class='bgBlock-"+$(this).attr('itemid')+"'></span>");
		$(this).css({cursor:'pointer',position:'relative'});
		$(this).click(function () {
	     window.location.href = $(this).attr('page');
	    });
	});


	$('input[name=emailadres]').focus(function(){
				if($(this).val()=='E-mail adres')
					$(this).val('');
	}).blur(function(){
		if($(this).val()=='')
					$(this).val('E-mail adres');
	});

/*

//$(".limitIntro").each(function (i) {
//       tempLength=$(".limitIntro").val().length;
//});
var tempLength=0;
if($(".limitIntro").length>0) {
       tempLength=$(".limitIntro").val().length;
       $(".limitIntro").after('<br><span id=limitIntro_counter>Karakters over:'+(170 - tempLength )+'</span>')
					.keyup(function () {
						var left = 170 - $(this).val().length;
						$('#limitIntro_counter').text('Karakters over: ' + left);
				});
}


	
	$("a.galleryImg").fancybox({
				'titlePosition'  : 'inside'
	});
	
	$('.slideshow').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
	
	$('input[name=gebruikersnaam]').focus(function(){
				if($(this).val()=='gebruikersnaam')
					$(this).val('');
	}).blur(function(){
		if($(this).val()=='')
					$(this).val('gebruikersnaam');
	});
	$('input[name=emailadres]').focus(function(){
				if($(this).val()=='E-mail adres')
					$(this).val('');
	}).blur(function(){
		if($(this).val()=='')
					$(this).val('E-mail adres');
	});
	
	$('input[name=q]').focus(function(){
				if($(this).val()=='doorzoek de site')
					$(this).val('');
	});
	
//	function verwerkNietOk(reactieId){
//		alert reactieId;
//	//$.get("verwrek_nietOK.php", { name: "John", time: "2pm" } );
//	}

	$(".nietOK").click(function(event) {
		$(this).blur();
			event.preventDefault();
			$.get("/verwrek_nietOK.php", { item: $(this).attr('reactieId')}
//			, function(data){	     alert("Data Loaded: " + data);	   }
    );
			alert("Dat deze reactie niet ok is wordt doorgegeven. Het kan even duren voordat het verwerkt is.");
	});
	
	$('.ratingActive').starRating({
                        clickable:true,
												
                        showNumber:false,
                        ratingUrl:'/rate.php?',
                        paramId: 'item'
                        
   });

	$('.ratingPasive').starRating({
                        clickable:false,
                        hoverable :false,
                        rating:3,
                        showNumber:false
   });
	
	$('A[rel="uceeradio"]').click( function() {
		      radioWindow=window.open( $(this).attr('href'),'uceeradio','width=800, height=500, location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no' );
		      if (window.focus) {radioWindow.focus()}
		      return false;
		  });

// ik kan er een functie of plugin van schrijven.
// widt's kan je uitlezen
// ik moet nog iets met die hoogte doen!
// en ik moet er 1 functie van maken ipv 3!
// 
//		nieuwsteArtikelen
//		meestBekekenArtikelen
//		bestGewaardeerdeArtikelen

function tabSlider(tabClassNamesArray,ref){
	this.tabClassNamesArray=tabClassNamesArray;
	this.tabClassNamesCopyArray=this.tabClassNamesArray;
	this.sliderMainX=0;	
	this.sliderwidth=$("."+this.tabClassNamesArray[0]).width();
	this.reference=ref;
	
	for(var i=0; i < this.tabClassNamesArray.length; i++) {
		$("."+this.tabClassNamesArray[i]+"Link")
		.attr("i",i)
		.attr("ref",this.reference)
		.bind('click', function() {
			i=$(this).attr("i");
			reference=$(this).attr("ref");
			_this=window[reference];
			var verplaatsing=_this.sliderMainX-(i*_this.sliderwidth);
			if(verplaatsing < 0){
				verplaatsing="-="+Math.abs(verplaatsing);
			}
			if(verplaatsing >= 0){
				verplaatsing="+="+Math.abs(verplaatsing);
			}
			for(var j=0; j < _this.tabClassNamesCopyArray.length; j++) {
				//alert(verplaatsing)
				$("."+_this.tabClassNamesCopyArray[j]).animate({"left": verplaatsing+"px"}, "slow" );
				//alert("."+_this.tabClassNamesCopyArray[j]);
			}
			_this.sliderMainX=(i*_this.sliderwidth);		
			for(var j=0; j < _this.tabClassNamesCopyArray.length; j++) {
				$("."+_this.tabClassNamesCopyArray[j]+"Link").removeClass('active');
			}			
			$(this).addClass('active');
			return false;
		});
	}
	this.testFunc=function(){
		alert(window[this.reference].tabClassNamesArray.length);
	}
}

ReactieTabs = new tabSlider(["laatsteReacties","populaireReacties"],'ReactieTabs');
homeTabs = new tabSlider(["nieuwsteArtikelen", "meestBekekenArtikelen", "bestGewaardeerdeArtikelen"],'homeTabs');


// homeTabs.testFunc()
// ReactieTabs.testFunc()


		  
	$(".mp3").jmp3({
			backcolor: "000000",
			forecolor: "00ff00",
			width: 200,
			showdownload: "false",
			showfilename: "false"
	});
	
	$("a.medium").fancybox({
		'width': 520, 
		'height': 360,
		'onClosed':function() {
                location.reload(); 
                } 
		});
		
	$("#loginForm").ajaxForm({
        success: function(responseText){
            $.fancybox({
							'width': 520, 
							'type' : 'iframe',
							'href' : '/verwerk_login.php',
							'height': 360,
							'onClosed':function() {
					                location.reload(); 
					                } 
						});
        }
    });
	
		// submit form on change selectbox
		$('form .changeOnUpdate').change(function () {
		$(this).parents('form').submit();
		});
		
		$("#animateHeadDown").click(function(){
	     $(".visual .im1").slideUp();
	       $(".visual").animate({ 
	        height:"500px"
	      }, 400 );
	 		});
		$("#animateHeadUp").click(function(){
	     $(".visual .im1").slideDown();
	       $(".visual").animate({ 
	        height:"142px"
	      }, 400 );
	    });
	
	// uitgelicht
	var idBlockInt=1;
//	var maxBlocks=Number( $("#uitgelicht .navigatie a:last").text() ) ;
	var maxBlocks=Number($(".homeslide #slide_navi li").length) ;
//	alert(maxBlocks);
	var timeoutID;
//	$("#uitgelicht .navigatie a").click(function(event){
	$(".homeslide #slide_navi li a").click(function(event){
//	idBlockInt=Number($(this).text());	
		idBlockInt=Number($(this).attr("num"));		
		clearTimeout(timeoutID);
		
		showHomeItem();
		event.preventDefault();
		this.blur();
	});
	function showHomeItem(){
		//alert(idBlockInt);
		var idBlock="uitL"+idBlockInt.toString();
		// zet de boxen uit en de nieuwe aan
		
		$(".uitgelichtbox").fadeOut("slow");
	
		$("#"+idBlock).fadeIn("slow");
		// set de juiste navigatie bolletje aan
		$(".homeslide #slide_navi li a").removeClass("active");

		$(".homeslide #slide_navi li a").each(function (i){
        //if ( $(this).text() == idBlockInt ){
        
        if ( $(this).attr("num") == idBlockInt ){
          $(this).addClass("active");
        }
     });
      
		// 
		timeout();
	}
	function timeout(){
		timeoutID=setTimeout(function() { 
			idBlockInt++;
			if(idBlockInt > maxBlocks) idBlockInt=1;
			showHomeItem();
			//timeout();
			 }, 8000); 
	}
	if(maxBlocks > 1)	timeout();
	// end uitgelicht
	*/
});

