// Corners #navigation
$(document).ready( function(){
  DD_roundies.addRule('.rounded', '20px 20px 0 0', true);
  DD_roundies.addRule('.button, .button a, .interactionblock, a#submit, a#submit2', '10px', true);
  DD_roundies.addRule('input[type="text"], textarea', '8px', true);
  DD_roundies.addRule('.textarea', '8px', true);
});

// Clouds
$(document).ready(function() {
	
	$("a[rel^='prettyPhoto']").prettyPhoto({theme: 'facebook',slideshow:5000, autoplay_slideshow:false});
	
	$("select.productamount").change(function(){
		$("input[type='hidden']").val("1");
		$(this).parents("form").submit();
	});
	$("#contentCenterRight1 a:not(.teaserBlock):eq(1)").css({marginRight: "0"});
	$("#submit").click(function(){
		$("input[type='hidden']").val("2");
		$(this).parents("form").submit();			
	});
	$("fieldset p").click(function(){
		$(this).find("input").focus();
	});
	
	if (getCookie("cloudSmallMarginTop") == "") {
		if (document.getElementById("logo")) {
			var marginTopValueSmall=Math.floor(Math.random()*171); // For CSS insertion
			var marginTopValueMedium=Math.floor(Math.random()*171); // For CSS insertion
			var marginTopValueLarge=Math.floor(Math.random()*171); // For CSS insertion
		} else if (document.getElementById("logo2")){
			var marginTopValueSmall=Math.floor(Math.random()*51); // For CSS insertion
			var marginTopValueMedium=Math.floor(Math.random()*51); // For CSS insertion
			var marginTopValueLarge=Math.floor(Math.random()*51); // For CSS insertion
		}
		$("#cloudSmall").css("marginTop", marginTopValueSmall);
		$("#cloudMedium").css("marginTop", marginTopValueMedium);
		$("#cloudLarge").css("marginTop", marginTopValueLarge);
		setTimeout("animation()",300);
	} else {
		var marginTopValueSmall=getCookie("cloudSmallMarginTop");
		var marginTopValueMedium=getCookie("cloudMediumMarginTop");
		var marginTopValueLarge=getCookie("cloudLargeMarginTop");
		var marginLeftValueSmall=getCookie("cloudSmallMarginLeft");
		var marginLeftValueMedium=getCookie("cloudMediumMarginLeft");
		var marginLeftValueLarge=getCookie("cloudLargeMarginLeft");
		var cloudSmallTimer=getCookie("cloudSmallTimer");
		$("#cloudSmall").css("marginLeft", marginLeftValueSmall);
		$("#cloudMedium").css("marginLeft", marginLeftValueMedium);
		$("#cloudLarge").css("marginLeft", marginLeftValueLarge);
		$("#cloudSmall").css("marginTop", marginTopValueSmall);
		$("#cloudMedium").css("marginTop", marginTopValueMedium);
		$("#cloudLarge").css("marginTop", marginTopValueLarge);
		setTimeout("animation()",300);
	}
});
		
function animation(){
	cloudSmall();
	cloudMedium();
	cloudLarge();	
}

function cloudSmall(){
	/*if (getCookie("cloudSmallMarginLeft") == "") {*/
		if (document.getElementById("logo")) {
			var marginTopValue=Math.floor(Math.random()*171);
		} else if (document.getElementById("logo2")){
			var marginTopValue=Math.floor(Math.random()*51);
		}
		$("#cloudSmall").animate({marginLeft:"100%"},120000, "linear").animate({marginLeft:"-15%", marginTop: marginTopValue}, 0)
		setTimeout("cloudSmall()",120000);
	/*} else {
		var marginLeftValueSmall=getCookie("cloudSmallMarginLeft");
		var withoutPercentage= marginLeftValueSmall.replace("%", "");
		if (withoutPercentage >= 10) {
			var speed=Math.floor(((100-withoutPercentage)/100)*120000);
		} else {
			var speed=120000;
		}
		var marginTopValue=Math.floor(Math.random()*171);
		$("#cloudSmall").animate({marginLeft:"100%"},speed, "linear").animate({marginLeft:"-15%", marginTop: marginTopValue}, 0)
		setTimeout("cloudSmall()",speed);
	}*/
}
		
function cloudMedium(){
	/*if (getCookie("cloudMediumMarginLeft") == "") {*/
		if (document.getElementById("logo")) {
			var marginTopValue=Math.floor(Math.random()*171);
		} else if (document.getElementById("logo2")){
			var marginTopValue=Math.floor(Math.random()*51);
		}
		$("#cloudMedium").animate({marginLeft:"100%"},100000, "linear").animate({marginLeft:"-15%", marginTop: marginTopValue}, 0)
		setTimeout("cloudMedium()",100000);
	/*} else {
		var marginLeftValueMedium=getCookie("cloudSmallMarginMedium");
		var withoutPercentage= marginLeftValueMedium.replace("%", "");
		if (withoutPercentage >= 10) {
			var speed=Math.floor(((100-withoutPercentage)/100)*100000);
		} else {
			var speed=100000;
		}
		var marginTopValue=Math.floor(Math.random()*171);
		$("#cloudMedium").animate({marginLeft:"100%"},speed, "linear").animate({marginLeft:"-15%", marginTop: marginTopValue}, 0)
		setTimeout("cloudMedium()",speed);
	}*/
}
	
function cloudLarge(){
	/*if (getCookie("cloudLargeMarginLeft") == "") {*/
		if (document.getElementById("logo")) {
			var marginTopValue=Math.floor(Math.random()*171);
		} else if (document.getElementById("logo2")){
			var marginTopValue=Math.floor(Math.random()*51);
		}
		$("#cloudLarge").animate({marginLeft:"100%"},70000, "linear").animate({marginLeft:"-15%", marginTop: marginTopValue}, 0)
		setTimeout("cloudLarge()",70000);
	/*} else {
		var marginLeftValueLarge=getCookie("cloudLargeMarginLeft");
		var withoutPercentage= marginLeftValueLarge.replace("%", "");
		if (withoutPercentage >= 10) {
			var speed=Math.floor(((100-withoutPercentage)/100)*70000);
		} else {
			var speed=70000;
		}
		var marginTopValue=Math.floor(Math.random()*171);
		$("#cloudLarge").animate({marginLeft:"100%"},speed, "linear").animate({marginLeft:"-15%", marginTop: marginTopValue}, 0)
		setTimeout("cloudLarge()",speed);
	}*/
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{
		c_start=c_start + c_name.length+1;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		}
	  }
	return "";
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString()+";path=/");
}

$(window).unload(function(){
	var cloudSmallMarginTop = $("#cloudSmall").css("marginTop");
	setCookie("cloudSmallMarginTop",cloudSmallMarginTop,31);
	var cloudSmallMarginLeft = $("#cloudSmall").css("marginLeft");
	setCookie("cloudSmallMarginLeft",cloudSmallMarginLeft,31);
	var cloudMediumMarginTop = $("#cloudMedium").css("marginTop");
	setCookie("cloudMediumMarginTop",cloudMediumMarginTop,31);
	var cloudMediumMarginLeft = $("#cloudMedium").css("marginLeft");
	setCookie("cloudMediumMarginLeft",cloudMediumMarginLeft,31);
	var cloudLargeMarginTop = $("#cloudLarge").css("marginTop");
	setCookie("cloudLargeMarginTop",cloudLargeMarginTop,31);
	var cloudLargeMarginLeft = $("#cloudLarge").css("marginLeft");
	setCookie("cloudLargeMarginLeft",cloudLargeMarginLeft,31);
});
