(function($) {
  $.trim = function(str, replace) {
    replace = replace || '\\s';
    return str.replace(new RegExp('^' + replace + '*([\\S\\s]*?)' + replace + '*$'), '$1');
  };
})(jQuery);

$(document).ready(function() {

$("a#getPasword").click(function(e){
	e.preventDefault();
	$("#wwRegel").hide();
	$("input#Login").val('vraag wachtwoord aan');
	$("input#actie").val('mailWW');
});

$(".caoMiniNavi").each(function(){
  // HomeCaoItem_
  $(this).click(function(e){
    e.preventDefault();
    $(".caoItem").hide();
    $("#HomeCaoItem_"+$(this).text()).show();
    $(".caoMiniNavi").removeClass("active");
    $(this).addClass("active");
  });
});

checkBlokkenOpHome=function(){
  // #cont-visitaties
  // #cont-leden
  // #cont-voorpagina
  var maxHeight= Math.max($("#cont-leden").height(),$("#cont-visitaties").height());
  $("#cont-leden").height(maxHeight);
  $("#cont-visitaties").height(maxHeight);
  var middleOud=$("#cont-middle").height();
  
  var maxHeight2= Math.max($("#cont-middle").height(),$("#cont-voorpagina").height());
  $("#cont-middle").height(maxHeight2);
  $("#cont-voorpagina").height((maxHeight2-45));
  
  // stel dat rechter groter is dan linker
  if(middleOud<maxHeight2){
    var vergroting=maxHeight2-middleOud;
    $("#cont-leden").height(maxHeight+vergroting);
    $("#cont-visitaties").height(maxHeight+vergroting);
  }
}
checkBlokkenOpHome();

$(".pensioenMiniNavi").each(function(){
  // HomePensioenItem_
  $(this).click(function(e){
    e.preventDefault();
    $(".pensioenItem").hide();
    $("#HomePensioenItem_"+$(this).text()).show();
    $(".pensioenMiniNavi").removeClass("active");
    $(this).addClass("active");
  });
});


$("#loginForm").ajaxForm({
  success: function(responseText){
    $.fancybox({
      'width': 520, 
      'type' : 'iframe',
      'href' : '/verwerk_login.php',
      'height': 280,
      'onClosed':function() {
	location.reload(); 
      } 
    });
  }
});

$('#directNaarForum').fancybox({
  'width': 520, 
  'type' : 'iframe',
  'href' : '/verwerk_login.php',
  'height': 280,
  'onClosed':function() {
    location.reload(); 
  } 
});

$('#slider').each(function(){
  $(this).css({'position':'relative'});
  var i=0;
  var slideTimeout=3000;
  var itemSlideLength=$(".slide",this).length;
  $(".slide",this).css({'overflow':'hidden','position':'absolute','left':'0px','top':'0px'}).each(function(){
    $(this).attr('slideId',i);
    i++;
  });
  var startSlide=1;
  if(itemSlideLength>1){
    setTimeout("fadeNextSlide('"+startSlide+"')",slideTimeout);
  }
  fadeNextSlide=function(startSlide){
    // fade het de slide met het nummer in en fade de rest out
    $(".slide").each(function(){
      
      if( $(this).attr('slideId') ==startSlide){
	$(this).fadeTo("slow", 1);
      }else{
	$(this).fadeTo("slow", 0);
      }
    });
      
    
    // 
    startSlide++;
    if(startSlide===itemSlideLength){startSlide=0;}
    setTimeout("fadeNextSlide('"+startSlide+"')",slideTimeout);
  }
//  fadeTo("slow", 0);
  
});



//	$.fancybox(
//		'<h2>Hi!</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam quis mi eu elit tempor facilisis id et neque</p>',
//		{
//        		'autoDimensions'	: false,
//			'width'         		: 350,
//			'height'        		: 'auto',
//			'transitionIn'		: 'none',
//			'transitionOut'		: 'none'
//		}
//	);

// caoMiniNavi


//$("a#inline").fancybox({
//		'width': 520,
//		'height': 250,
//		'type' : 'iframe',
//		'onClosed':function() {
//                location.reload();
//		//alert('reload');
//                } 
//	});


// uitgelicht strook op home
//$("#uitgelichtList").css({'overflow':'hidden','position':'relative',width:'5000px',border:'1px solid red',height:'200px'})

//oke trim 
//- [htp:/w. ]
//alert($.trim($.trim('          ola                          '),'o'));


//alert(
//      $.trim($("a.link").text(),'[htp:/w. ]')
//      );
//$("a.link").each(function(){
//	var newtxt=$.trim($(this).text(),'[htp:/w. ]');
//	
//	$(this).text(newtxt);
////	alert(newtxt);
//	
//});

//$(".itemscroller").each(function(){
//	//$(this). = een div class='.itemscroller'
//	var items=$('.item',this);
//	var crollerBlock=this;
//	var counter=0;
//	if(items.length <= 6){
//		$('.control_left',crollerBlock).hide();
//		$('.control_right',crollerBlock).hide();
//	}else{
//		$('.control_left',crollerBlock).hide();
//		$('.control_right',crollerBlock).show();
//		$('.control_left',crollerBlock).click(function(e){
//			e.preventDefault();
//			if(counter > 0){
//				$('.itemcontainer_inner',crollerBlock).animate({"left": "+=158px"}, "slow");
//				counter--;
//				if(counter <= 0){
//					$('.control_left',crollerBlock).fadeOut();
//				}
//				if(counter+4 < items.length){
//					$('.control_right',crollerBlock).fadeIn();
//				}
//			}
//		});
//		$('.control_right',crollerBlock).click(function(e){
//			e.preventDefault();
//			if((counter+6) < (items.length)){
//				$('.itemcontainer_inner',crollerBlock).animate({"left": "-=158px"}, "slow");
//				counter++;
//				if(counter > 0){
//					$('.control_left',crollerBlock).fadeIn();
//				}
//				if((counter+6) >= (items.length)){				
//					$('.control_right',crollerBlock).fadeOut();
//				}
//				
//			}
//				
//		});
//	}
//	
//	//$('.itemcontainer_outer',crollerBlock).css({'overflow':'hidden'});
//	//$('.itemcontainer_inner',crollerBlock).css({'width':(items.length*230)+'px','position':'relative'});	
//});
//
//
//
//// agenda uitklap
//var agendaItems=$(".agendaItem").length;
//if(agendaItems > 3){
//	var expandText=$(".agendaLink a").text();
//	var collapsText="Verklein agenda...";
//	$(".agendaLink").show().toggle(
//	function(){
//		$(".agendaItem:gt(2)").show("fast");
//		$(".agendaLink a").text(collapsText);
//	},
//	function(){
//		$(this).show();
//		$(".agendaItem:gt(2)").hide("fast");
//		$(".agendaLink a").text(expandText);
//	}
//	);
//}else{
//	$(".agendaLink").hide();
//}
//$(".agendaItem:gt(2)").hide();
//
//// artikel uitklap
//var nieuwsterugtekst="&lt;&lt;";
//var nieuwsLeesmeetekst=$(".uitklapNieuws").html();
//$("a.uitklapNieuws").toggle(function(event){
//	var id=$(this).attr("itemId");
//	$(".bericht[itemId='"+id+"']").show("fast");
//	$(this).html(nieuwsterugtekst);
//	event.preventDefault();
//},function(){
//	var id=$(this).attr("itemId");
//	$(".bericht[itemId='"+id+"']").hide("fast");
//	$(this).html(nieuwsLeesmeetekst);
//	event.preventDefault();
//});
//$(".bericht").hide();
//$(".activeBericht").show();
//
//	
//
//
//
//$(".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=340;
//	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
	*/
});

