$(document).ready(function() {

	// Slide
	$("#usermenu-style > li > a.expanded + ul").hide("medium");
	$("#usermenu-style > li > a").click(function() {
		$(this).toggleClass("expanded").toggleClass("collapsed").find("+ ul").slideToggle("medium");
	});
});

function picturePreview(id, action)
{
	if (action=="1")
	{
		document.getElementById(id).style.display = "inline"
	}
	else if (action=="0")
	{
		document.getElementById(id).style.display = "none"
	}
}

function setCookie(name, value, expires, path, domain, secure)
{
	var today = new Date();
	today.setTime( today.getTime() );

	if(expires)
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function changeLanguage(lang, nexturl)
{
	setCookie("language", lang, 30, "/", "midgaardshop.com", "");
	window.location=nexturl;
}

function changeView(type, nexturl) {

	setCookie("viewtype", type, 30, "/", "midgaardshop.com", "");
	window.location=nexturl;
}

function changeSortBy(type, nexturl) {

	setCookie("sortby", type, 30, "/", "midgaardshop.com", "");
	window.location=nexturl;
}

function changeProductsCount(number, nexturl) {

	setCookie("productsshown", number, 30, "/", "midgaardshop.com", "");
	window.location=nexturl;
}

function chooseSubmit(selected, deleteid) {
	document.cartform.cartsubmitbutton.name = selected;

	if(deleteid != '')
	{
		document.cartform.deleteproduct.value = deleteid;
	}

	document.cartform.submit();
}

function changePayment(selected, nexturl) {
	document.cartform.cartsubmitbutton.name = selected;
	document.cartform.action = nexturl;
	
	document.cartform.submit();
}
