// JavaScript Document
$(document).ready(function() {
		
	
	$('.showreacties').click(function(){
		$('.reageerholder').slideToggle('slow');
		return false;
	});
	
	$('.star_uiteind').mouseover(function(){
		var id = $(this).attr('rel');
		id = parseInt(id);
		$('.star_uiteind').removeClass('selectstar_uiteind');
		
		$('.star_uiteind').each(function(){
			if($(this).attr('rel') <= id ){
				$(this).addClass('selectstar_uiteind');
			}
		});
		
		return false;								 
	});
	
	$('.star_uiteind').mouseleave(function(){
		var id = $(this).attr('rel');
		id = parseInt(id);
		
		$('.star_uiteind').removeClass('selectstar_uiteind');
		
		$('.star_uiteind').each(function(){
			if($(this).attr('rel') <= id ){
				$(this).removeClass('selectstar_uiteind');
			}
		});
		
		return false;								 
	});
	
	
	$('.star_uiteind').live('click',function(){
		var id = $(this).attr('rel');
		id = parseInt(id);
		var webshopid = $('.beoordeling_uiteind').attr('lang');
		webshopid = parseInt(webshopid);
		$.post('ajax/beoordeling.php',{id:id,webshopid:webshopid},function(data){
			if($.trim(data) == 'true'){
				$.post('ajax/getbeoordeling.php',{webshopid:webshopid},function(data1){
					$('#eindbeoordeling_groot').html(data1+"/10");
				});
			}
		});
		
		$('.star_uiteind').removeClass('selectstar_uiteind');
		
		$('.star_uiteind').each(function(){
			if($(this).attr('rel') <= id ){
				$(this).addClass('selectstar_uiteind');
			}
		});
		
		$('.star_uiteind').unbind('mouseover mouseleave');
		return false;
	});
	
	
	$('.star_bestel').live('click',function(){
		var id = $(this).attr('rel');
		id = parseInt(id);
		$('#sterren_bestel').val(id);
		$('.star_bestel').removeClass('selectstar');
		
		$('.star_bestel').each(function(){
			if($(this).attr('rel') <= id ){
				$(this).addClass('selectstar');
			}
		});
		
		$('.star_bestel').unbind('mouseenter mouseleave');
		return false;
	});
	
	$('.star_levering').live('click',function(){
		var id = $(this).attr('rel');
		id = parseInt(id);
		$('#sterren_levering').val(id);
		$('.star_levering').removeClass('selectstar');
		
		$('.star_levering').each(function(){
			if($(this).attr('rel') <= id ){
				$(this).addClass('selectstar');
			}
		});
		
		$('.star_levering').unbind('mouseenter mouseleave');
		return false;
	});
	
	$('.star_service').live('click',function(){
		var id = $(this).attr('rel');
		id = parseInt(id);
		$('#sterren_service').val(id);
		$('.star_service').removeClass('selectstar');
		
		$('.star_service').each(function(){
			if($(this).attr('rel') <= id ){
				$(this).addClass('selectstar');
			}
		});
		
		$('.star_service').unbind('mouseenter mouseleave');
		return false;
	});
	
	$('.star_eind').live('click',function(){
		var id = $(this).attr('rel');
		id = parseInt(id);
		$('#sterren_eind').val(id);
		$('.star_eind').removeClass('selectstar');
		
		$('.star_eind').each(function(){
			if($(this).attr('rel') <= id ){
				$(this).addClass('selectstar');
			}
		});
		
		$('.star_eind').unbind('mouseenter mouseleave');
		return false;
	});
	
	$('.iframe_nieuw').live('click',function(){
		var jump = $(this).attr('href');
		$('#reviewschrijven').show();
		$('html, body').animate({scrollTop: $("#reviewschrijven").offset().top});
		return false;
	});
	
	$('.schrijfreview').live('click',function(){
		$('#reviewschrijven').show();
		$('html, body').animate({scrollTop: $("#reviewschrijven").offset().top});
		return false;
	});
	
	bindToForm('#reactiebutton','#reactieform');
	bindToForm('#deelbutton','#deelform');
	bindToForm('#nbbutton','#nbform');
	bindToForm('#nbbuttonhome','#nbformhome');
		
	bindToZoek();
	bindCodeClicks();
	omenom();
	initLightbox();
});

function bindToZoek(){
	$('#zoekform').bind('submit',function(){
		var zoek = $('#zoekbox').val().replace('&','');
		window.location.href = BASEHREF+'zoek/'+zoek;
		return false;								  
	});
}

function bindCodeClicks(){
	$('.codeopen').click(function(){
		var el = $(this);
		$.post('ajax/getcode.php',{id:el.attr('rel')},function(data){
			el.parent().html(data);	
			//popunder = window.open(BASEHREF+'out/'+el.attr('rel'),'_blank','toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');
			//popunder.blur();
			//window.focus();
		});
		//return false;
	});
	
	$('.codeopen2').click(function(){
		var el = $(this);
		$.post('ajax/getcode2.php',{id:el.attr('rel')},function(data){
			el.parent().html(data);	
			//popunder = window.open(BASEHREF+'out/'+el.attr('rel'),'_blank','toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');
			//popunder.blur();
			//window.focus();		
			});
		//return false;
	});
	
	$('.codeopen3').click(function(){
		var el = $(this);
		$.post('ajax/getcode3.php',{id:el.attr('rel')},function(data){
			el.parent().html(data);	
			//popunder = window.open(BASEHREF+'out/'+el.attr('rel'),'_blank','toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');
			//popunder.blur();
			//window.focus();		
			});
		//return false;
	});
	
}

function initLightbox(){
	$("a.overlay").fancybox({
		'zoomSpeedIn':			300, 
		'zoomSpeedOut':			300, 
		'overlayShow':			true,
		'frameWidth':			960,
		'frameHeight':			500,
		'hideOnContentClick':	false
	});
	
	
	
	
	$("a.iframe").fancybox({
		'zoomSpeedIn':			300, 
		'zoomSpeedOut':			300, 
		'overlayShow':			true,
		'width':				800,
		'height':				600,
		'hideOnContentClick':	false,
		'onClosed' :
			function() {
				$("#reviewschrijven").show();
			}
	});
}

function bindToForm(button,form){
	$(button).click(function(){
		$(form).submit();		
		return false;
	});
}

function omenom() {
	$('.rijkleur:odd').removeClass("omenom_blauw");
	$('.rijkleur:even').addClass("omenom_blauw");
}
