var navmenus=[];

function resizetobrowser(){chheight=document.body.offsetHeight;}
function attachmenu(id)
{
if (id)
{
	$("#"+id+" > li").hover(
		function(){try{$(this).addClass('hover');document.getElementById('container').className='hideinput';}catch(err){}},
		function(){try{$(this).removeClass('hover');document.getElementById('container').className='';}catch(err){}}
	);
} else {
	for(var i=0;i<navmenus.length;i++) {attachmenu(navmenus[i]);}
}
}


function echeck(str){	
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1) return false
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
	if (str.indexOf(at,(lat+1))!=-1) return false;
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false
	if (str.indexOf(dot,(lat+2))==-1) return false;
	if (str.indexOf(" ")!=-1) return false;
	return true					
}

mailform = {
label : {
	mandatory : "Niet alle verplichte velden zijn ingevuld",
	senderemailerror : "Uw emailadres is niet geldig",
	receiveremailerror :"Het emailadres van uw vriend is niet geldig!"
},
url : '/mailform',
hidden : true,
load : function() {
	if(mailform.hidden)
	{
		mailform.url = $("a.itemaction_mail").attr("href");
		$("body").append("<div name=\"mailform\" class=\"mailform_main\"><div class=\"containerheader\"></div><div class=\"container\"></div><div class=\"containerfooter\"></div>");
		$("div[name=mailform] div.container").load(mailform.url, function(){	
			$(".mailform_main input[type=reset]").click(mailform.reset);
			$(".mailform_main input[type=submit]").click(mailform.SendMail);
		});
		mailform.hidden = false;
	}
	else mailform.hide();
	return true;
},
hide: function(object) {
	mailform.hidden = true;
	$("div.mailform_main").hide("slow",function(){$(this).remove();})
},	
reset: function() {
	$("input:not(\"input.submit, input.reset\")").attr("value", "");
	$("textarea.comment").attr("value", "");
	mailform.hide();
	return false;
},
success: function(data) {
	$("div[name=mailform] div.container").html(data);
	var time = window.setTimeout('mailform.hide();', 5000);
},
SendMail: function()
{
	var senderemail = $("form#mailform input.senderemail").val();
	var sendername = $("form#mailform input.sendername").val();
	var receiveremail = $("form#mailform input.receiveremail").val();
	var receivername = $("form#mailform input.receivername").val();
	var comment = $("form#mailform textarea .comment").val();
	var title = $("div.middle h1:first").text().replace(/\n|\r\n|\t/g, '');
	if(title == "")
	{
		title = $("div.left_large h1:first").text().replace(/\n|\r\n|\t/g, '');
	}
	if(title == "")
	{
		title = $("div.fullpage h1:first").text().replace(/\n|\r\n|\t/g, '');
	}	
	if(title == "")
	{
		title = document.title;
	}
	
	$("#mailform input.pagetitle").val(title);
	var messg = [];
	if(senderemail=="" || sendername =="" || receiveremail=="" || receivername=="")
	{
		messg.push(mailform.label.mandatory);
	}
	if(!echeck(senderemail) )
	{
		messg.push(mailform.label.senderemailerror);
	}
	if(!echeck(receiveremail))
	{
		messg.push(mailform.label.receiveremailerror)
	}
	if(messg.length >0)	{
		alert(messg.join("\n"));
	} else {
		var submit = {submit:"1"}
		$("form#mailform").ajaxSubmit({url:mailform.url,success:mailform.success,data:submit})
	}
	return false;
}

};
$(function(){
$("a.itemaction_mail").click(function(){mailform.load();return false;});
$("form#headersearch a").click(function(){document.forms["headersearch"].submit();return false;});
$(".item .more").click(function()
{
	if($(this).parent().hasClass("opened"))
	{
		$(this).siblings(".article").slideToggle(1000,function(){
			$(this).css("display","none");});
		$(this).siblings(".intro").slideToggle(500);
		$(this).parent().removeClass("opened");
		$(this).html($(this).attr("tmore"));
	}
	else
	{
		$(this).siblings(".article").slideToggle(500);
		$(this).siblings(".intro").slideToggle(1000,function(){$(this).css("display","none");});
		$(this).parent().addClass("opened");

		$(this).html($(this).attr("tless"));

	}
	return false
});
});

roulatiescript=function(id)
{
	var next = $(".roulatie:not(.active)",id);
	if(next.length==0) 
	{
		return;
	}
	var nextid = Math.floor(Math.random()*next.length)
	var next = $(".roulatie:not(.active):eq("+nextid+")",id);
	var active = $(".roulatie.active",id);
	active.removeClass("active");
	next.addClass("active");
	active.fadeOut(500);
	next.fadeIn(500,
	function()
	{
		if($(this)[0].style.removeAttribute) $(this)[0].style.removeAttribute("filter");
	});
}
roulatiescript.init = function(id,interval,height)
{
	var init = $(".init",id);
	if(height)
		$(id).height(height);
	else
	$(id).height($(id).height());
	init.addClass("active");
	init.removeClass("init");
	init.fadeIn(0);
	window.setInterval("roulatiescript('"+id+"')",interval)
};
