$(document).ready(function(){
	/*LIGHTBOX*/
	$('a.lightbox').lightBox();
	/*EINDE LIGHTBOX*/
	/*DIVS AANKLIKBAAR MAKEN EN DOEL OPHALEN VAN LINK*/
	$('a.divlink').each(function(){
		var link = $(this).attr('href');
		$(this).parents('div').eq(0).click(function(){
			window.location = link;
		});
	});
	$('a.divlink_r').each(function(){
		var link = $(this).attr('href');
		$(this).parents('div').eq(0).parents('div').eq(0).click(function(){
			window.location = link;
		});
	});
	/*EINDE AANKLIKBARE DIVS*/
	/*NABESTELLEN*/
	$(".uitgaves img").simpletooltip().click(function(){
		if($(this).parent().next('input').attr("checked"))
		{
			$(this).parent().next('input').attr("checked",false);
		}
		else
		{
			$(this).parent().next('input').attr("checked",true);
		}
	});
	/*NABESTELLEN*/
	
	/*MENU*/
	$('#menu ul li ul').not(".selected").hide();
	$('#menu > ul > li').hover(function(){
		if($(this).find("ul").hasClass("selected")){
			$("ul li ul").not(".selected").stop(true,true).hide();
			if($(this).find("ul").css("display")=="none"){
				$(this).find("ul").stop(true,true).fadeIn("normal");
			}
			$(this).children("a").addClass("mouse_selected");
		}else{
			$("ul li ul").stop(true,true).hide();
			$(this).find("ul").stop(true,true).fadeIn("normal");
			$(this).children("a").addClass("mouse_selected");
		}
		$('div').not('#menu').mouseover(function(){
			$("ul li ul").not('.selected').hide();
			$('#menu ul.selected').fadeIn("normal");
			$('div').not('#menu').unbind('mouseover');
		});
	},function(){
		$(this).children("a").removeClass("mouse_selected");
	});	
	$('#menu').mouseover(function(event) {
	  event.stopPropagation();
	})
	/*EINDE MENU*/
	
	$("a[href^='http://'],a[href^='www.'],a[rel='external']").not("a[href^='http://www.publish.nl'],a[href^='http://publish.nl']").attr('target','_blank');
	
	/*RATINGS*/
	$('.ratings').each(function(){
		var ratingwaarde = $(this).html();
		var breedte = (65 / 10) * ratingwaarde;
		$(this).html("").append("<div class='sterretjes'></div><div class='vulling'></div>");
		$(this).children('.vulling').css("width",breedte+'px');
	});
	$(document).mousemove(function(){
		$('.vulling').fadeIn("slow");
		$(document).unbind('mousemove');
	});
	/*EINDE RATINGS*/
	
	/*Margins bepalen voor blokjes rechterkant*/
	$('#content_right .blokje').each(function(){
		if($(this).prev("div").hasClass("blokje") && $(this).prev("div").hasClass("evenblokje")){
			$(this).addClass("onevenblokje");
		}else{
			$(this).addClass("evenblokje");
		}
	});
	/*Margins bepalen voor banner rechterkant*/
	$('#content_right .banner_right').each(function(){
		if($(this).prev("div").hasClass("blokje"))
		{
			$(this).addClass("banner_minmargin");
		}
	});
	
	/*Classes meegeven aan formulier elementen*/
	$("input[type=text], input[type=password]").addClass("input_tekst");
	$("input[type=radio]").addClass("input_radio");
	$("input[type=checkbox]").addClass("input_checkbox");
	$("input[type=image], input[type=submit]").addClass("input_button");
	$("label[for]").each(function(){
		if($('#'+$(this).attr('for')).attr('type')=='checkbox')
		{
			$(this).addClass("labelforcheckbox");
		}
	});
	/* Registreren, datum masken*/
	$.mask.definitions['1']='[10]';
	$.mask.definitions['2']='[210]';
	$.mask.definitions['3']='[3210]';
	$("#geboortedatum").mask("39-19-2999");
	$("#cadeau_geboortedatum").mask("39-19-2999");
	/*Einde datum masken*/
	/*Nu in publish uitklapvensters*/
	$('.uitklapvenster').toggle();
	$('.uitklapbutton').mouseover(function(){
		$(this).addClass("uitklapbuttonhover"); 
	}).mouseout(function(){
		$(this).removeClass("uitklapbuttonhover"); 
	}).toggle(function(){
		$(this).addClass("uitklapbuttonopen").next(".uitklapvenster").slideDown();
	},
	function(){
		$(this).removeClass("uitklapbuttonopen").next(".uitklapvenster").slideUp();
	});

	/*Classes bepalen voor oneven artikelen*/
	$('.artikel:odd').addClass("oneven");
	
	/*Classes bepalen voor oneven reacties*/
	$('.reactie:odd').addClass("oneven");
	
	/*Classes bepalen voor de eerste td of th in een tabel*/
	$('.table tr td:first-child').addClass("first_td");
	$('.table tr th:first-child').addClass("first_th");
	
	/*Class aanmaken voor aanpassen formulieren*/
	$("#h1_balk:contains('aanpassen') + form").addClass("account");
	
	/*Hover voor rubrieken IE6*/

	if ($.browser.msie && $.browser.version=="6.0") {
		$('.rubriek_l').mouseenter(function(){
			$(this).addClass("hover");
		}).mouseleave(function(){
			$(this).removeClass("hover");
		});
		$('.rubriek').mouseenter(function(){
			$(this).addClass("rubriek_hover");
		}).mouseleave(function(){
			$(this).removeClass("rubriek_hover");
		});
		$('.artikel').mouseenter(function(){
			$(this).addClass("artikel_hover");
		}).mouseleave(function(){
			$(this).removeClass("artikel_hover");
		});
	}
	successMessage();
    errorMessage();
    
	/*Latest features*/
	$(".eightbox").hide().eq(0).show();
    var myFile = document.location.toString();
    if (myFile.match('#')) {
        // click the navigation item corresponding to the anchor
        var myAnchor = myFile.split('#')[1];
		var myAnchorType = myAnchor.split('=')[0];
		var myAnchorId = myFile.split('=')[1];
        if(myAnchorType == 'lightbox'){
            $("#lb_"+myAnchorId+".lightbox").lightBox().trigger('click').parents(".eightbox").show().siblings().hide();
			var hoeveelste2 = $(".feature_vlakken .eightbox").index($("#lb_"+myAnchorId+".lightbox").parents(".eightbox"));
			$(".nummering a").eq(hoeveelste2).addClass("selected").siblings().removeClass("selected");
			$(".weergave span:first").html(hoeveelste2+1);
        }
    }
	$(".nummering a").not(".not a").click(function(){
		$(".nummering a").removeClass("selected");
		var hoeveelste = $(this).parent().children("a").index(this);
		$(".nummering a").eq(hoeveelste).addClass("selected");
		$(".weergave span:first").html(hoeveelste+1);
		$(".feature_vlakken .eightbox").eq(hoeveelste).show().siblings().hide();
		return false;
	});
	/*Einde Latest features*/
	/*File upload stylen*/
		$("input[type=file]").filestyle({ 
			image: "/tp_images/kies_bestand.gif",imageheight:21,imagewidth:100,width:100
		});
	/*Einde file-upload*/
});

$(function() {
	$('.cb_select').wrap("<div class='specialselect'></div>");
	$('.cb_select').before("<div class='selectheader'>Maak u keuze</div>");
	
	$('.specialselect select').toChecklist({
		addScrollBar : false
	});
	$('.specialselect > div:odd').addClass("select_absolute").css(
		'display', 'none'
	);
	$('.specialselect').click(function(event){
		 event.stopPropagation();
	 });
	$('.specialselect > div:even').click(function () {
		$(this).toggleClass("uitgeklapt").next().slideToggle();
		if($(this).hasClass("uitgeklapt")){
			$(document).click(function(){
				$('.uitgeklapt').toggleClass("uitgeklapt").next().slideToggle();
			})
		}else{
			$(document).unbind('click');
		}
	});
});

function confirmBackground(){
    var box = document.createElement('div');
    box.id = 'ajaxBg';
    document.body.appendChild(box);
}
function myConfirm(tekst, obj){
    confirmBackground();
    hrefs = ((eval("obj"))?obj.href:'#');
    var box = document.createElement('div');
    box.className = 'confirm';
    box.id = 'confirm';
    document.body.appendChild(box);
    document.getElementById('confirm').innerHTML = "<div class=\"confirm_title\">Waarschuwing</div><p>"+tekst+"</p><div class=\"confirm_buttons\"><input type=\"button\" value=\"Annuleren\" onclick=\"myConfirmDelete()\" /><input type=\"button\" onclick=\"window.location='"+hrefs+"'\" value=\"Akkoord\" /></div>";
    return false;
}
function myConfirmDelete(){
    myBgDelete();
    document.body.removeChild(document.getElementById('confirm'));
}
function myBgDelete(){
    document.body.removeChild(document.getElementById('ajaxBg'));
}

jQuery.fn.center = function () {
    this.css("position","fixed");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}


function successMessage() {
    if($('.success').length){
        confirmBackground();
        //$('.success').center();
        $('.success').css({
            'z-index' : '2000',
            'background-color' : '#FEF8E4',
            'border' : '2px solid #525252',
            'display' : 'block'
        });
        /*setTimeout(function(){
            $('.success').fadeOut("normal", myBgDelete);
        }, 2500);*/
        $('.success').append('<input type="button" value="Ok" onclick="$(\'.success\').fadeOut(\'normal\', myBgDelete);" />');
    }
}
function errorMessage() {
    if($('.error').length){
        confirmBackground();
        //$('.error').center();
        $('.error').css({
            'z-index' : '2000',
            'background-color' : '#FEF8E4',
            'border' : '2px solid #525252',
            'display' : 'block'
        });
        /*setTimeout(function(){
            $('.error').fadeOut("normal", myBgDelete);
        }, 3000);*/
        $('.error').append('<input type="button" value="Ok" onclick="$(\'.error\').fadeOut(\'normal\', myBgDelete);" />');
    }
}