$(document).ready(



	function()

	{

		initMenu();

		initFooterSearch();

		initContestForm();

		initCommentForm();

		initExternalLinks();

		initMailtoLinks();

		initBannerLinks();

		initSlideLinks();		

		initReleaseSlide();

		initLuisterpaal();

		

	

		$('#lightbox .photo a').lightBox();

		

		$('a').focus(function() {

     		if(this.blur)this.blur();

		});





  	}	



);



function initMenu() {

	

	$('.nav li').each( function() {



		var curclass = $(this).attr('class');

	

		if(curclass.indexOf('-sel') == -1) {

			$(this).mouseover( function() { 

				$(this).attr("class", curclass + "-sel");

			});

			

			$(this).mouseout( function() {

				$(this).attr("class", curclass);

			});	

		}

		

		$(this).click(function() {

		

			location.href = $(this).find("a").attr("href");

			return false;

		});

		

	});

				

}





function initReleaseSlide() {



		

	$('#release_thumbs a').click(function() {

		

		//get visible item

		var detailed_item_id = $('#release_items div:visible').attr("id");

		

		//hide visible item

		$('#' + detailed_item_id).addClass("hide");

		$('#' + detailed_item_id).hide();

		

		var thumbid = $(this).attr("id");	

		var div_id = thumbid.slice(6);

		

		//get hidden details

		var hid_thumb_src = $('#release_thumbs a:hidden').find("img").attr("src");

		var hid_thumb_alt = $('#release_thumbs a:hidden').find("img").attr("alt");

		

		//replaced thumb details

		var rep_thumb_src = $('#thumb_' + div_id).find("img").attr("src");

		var rep_thumb_alt = $('#thumb_' + div_id).find("img").attr("alt");

		

		//set new hidden thumb image 

		$('#release_thumbs a:hidden').find("img").attr("src", rep_thumb_src);

		$('#release_thumbs a:hidden').find("alt").attr("src", rep_thumb_alt);

		$('#release_thumbs a:hidden').attr("id" ,thumbid);



		//show item details

		//$('.releases #' + div_id).fadeIn("slow");

		

		$('.releases #' + div_id).show();

		$('.releases #' + div_id).removeClass("hide");

		

		//change thumbnail details

		$('#thumb_' + div_id).find("img").attr("src", hid_thumb_src);

		$('#thumb_' + div_id).find("img").attr("alt", hid_thumb_alt);

		$('#thumb_' + div_id).attr("id", "thumb_" + detailed_item_id);

		

		return false;

		

	});

	

}



function initBannerLinks() 

{

	$('.contest').each( function() {

		

		$('.contest .price').click(function()

		{

			location.href = $('.contest .price a').attr("href");

		});



	});

}



function initFooterSearch() 

{

	$('#searchform #search').mousedown(function()

	{

		$('#searchform #search').addClass('active');	

	});

	

	$('#searchform #search').mouseup(function()

	{

		$('#searchform #search').removeClass('active');	

		

		if($('#searchform #keyword').val() != "Zoek in deze site") {

			location.href = "/page/zoek/"  + $('#searchform #keyword').val();

		}

		

	});

	

	$('#searchform').submit(function()

	{

		if($('#searchform #keyword').val() != "Zoek in deze site") {

			location.href = "/page/zoek/"  + $('#searchform #keyword').val();

		}

		

		return false;

		

	});	



	$('#searchform #keyword').click(function() 

	{

		if($(this).val() == "Zoek in deze site") {

			$(this).val("");	

		}

	});	

}



function initContestForm()

{

	$('#contestform #sendanswer').mousedown(function()

	{

		$('#contestform #sendanswer').addClass('active');	

	});

	

	$('#contestform #sendanswer').mouseup(function()

	{

		$('#contestform #sendanswer').removeClass('active');	

	});

}



function initCommentForm() 

{	

		$(".commentform").each(

	

			function()

			{				

				var def_name 	= $(this).find('#name').val();

				var def_email 	= $(this).find('#email').val();

				var def_comment = $(this).find('#comment').val();

				

				 $(this).find('#name').click(function() 

				{

					if($(this).val() == def_name) {

						$(this).val("");	

					}

				});	

				 $(this).find('#email').click(function() 

				{

					if($(this).val() == def_email) {

						$(this).val("");	

					}

				});

				 $(this).find('#comment').click(function() 

				{

					if($(this).val() == def_comment) {

						$(this).val("");	

					}

				});		

			

			}

		);

	

		$('.commentpanel').click(function()

		{

			var id = $(this).attr("id");

			var data = id.split("_");

			var dataId = parseInt(data[1]);

			

			//close comments

			if($(this).attr("rel") == "close") {

				$('#articleitem_' + dataId + ' .commentcontainer').slideUp("slow");

				$('#linktop_' + dataId).text($(this).text().replace("verberg", "toon"));

				$('#linktop_' + dataId).attr( { rel : "open"} );

				$('#linktop_' + dataId).removeClass('arrowup');

				$('#linktop_' + dataId).addClass('arrowdown');

			}

			else { 

				$('#articleitem_' + dataId + ' .commentcontainer').slideDown("slow");

				$('#linktop_' + dataId).text($(this).text().replace("toon", "verberg"));

				$('#linktop_' + dataId).attr( { rel : "close"} );

				$('#linktop_' + dataId).removeClass('arrowdown');

				$('#linktop_' + dataId).addClass('arrowup');

			}



			return false;

		});



}



function initSlideLinks() 

{ 

	$('.agendaitem .event .details').click(function()

	{

		var detail = $(this).attr('id').split("_");

		var id = detail[1];

		var action = detail[0];

		

		if($(this).hasClass("open")) {

			$('#item_' + id).slideDown("normal");

			$('#item_' + id).removeClass("hidden");

		}

		else {

			$('#item_' + id).slideUp("normal");

		}

		

		return false;

	});

}



function initExternalLinks()

{	

	$("a[rel='external']").attr( { target: "_blank" } ).each( function() {

		

		var str = $(this).html();

		

		if(str.indexOf('http://') == 0) {

			var newstr = $(this).html().slice(7);

			$(this).html(newstr); 

		}

		

	});

}



function initLuisterpaal() {

	

	  $('a[rel="luisterpaal"]').click(function(){

		window.open(this.href, 'luisterpaal', 'width=651,height=637,toolbar=no,location=no,directories=no,status=0,resizable=no,scrollbars=no,menubar=no');

		return false;

	  });

}



function initMailtoLinks()

{

	$("a[rel='mail']").each(

	

		function()

		{

			var href = $(this).attr('href');

			$(this).attr( 'href', "mailto:" + replace( href, "[at]", "@") );		

		

		}

	);

	

}