
$(document).ready(function(){

	// List Menu
	var Current = "";
	$(".TopMenu").hover(
		function(){
			if(Current.length > 0){	$("#ShowMenu"+Current).hide();	}
			var Items = $("#ShowMenu"+$(this).attr('ref')+" a");
			if(Items.length>0){
				$("#ShowMenu"+$(this).attr('ref')).css('top', $(this).attr('offsetTop')+$(this).attr('offsetHeight')-10);
				$("#ShowMenu"+$(this).attr('ref')).css('left', $(this).attr('offsetLeft')-10);
				$("#ShowMenu"+$(this).attr('ref')).fadeIn().fadeTo('fast',0.85);
			}
			Current = $(this).attr('ref');
		},
		function(){
			$(".subMenu").hide();
		}
	);
	$(".subMenu").bind("mouseover",function(){$(this).show();});
	$(document).click(function(){$(".subMenu").hide();});
	$(document).scroll(function(){$(".subMenu").hide();});

	$("h1").wrap("<div class='H1Background'></div>");

	// Page Part
	$("#PagePart").lavaLamp({
		fx: "backout",
		speed: 700,
		click: function(event, menuItem){
			return false;
		}
	});

	// News Part
	$("#NewsPart").lavaLamp({
		fx: "backout",
		speed: 700,
		click: function(event, menuItem){
			return false;
		}
	});

	var re = /(\?|&|;)af=(\w\w\/\d+)(&|;)?/;
	if(re.test(window.location.search)){
		SetCookie("__af",RegExp.$2+"/"+new Date().getTime(),90);
		if(document.referrer){	SetCookie("__ar",document.referrer,90);	}
	}else{
		if(document.referrer){
			re = /^(https:\/\/)|(http:\/\/www\.terasic\.com)/;
			if(!re.test(document.referrer)){	SetCookie("__ar",document.referrer,90);	}
		}
	}

	// seekAttention
	$(".SeekAttention").seekAttention();

	// ColorBox
	$("a[rel='lightbox']").colorbox();
	$("a[href$='.jpg']").colorbox();
	$("a[href$='.png']").colorbox();
});

function SetCookie(name,value){
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	if(expires != null){
		var LargeExpDate = new Date();
		LargeExpDate.setTime(LargeExpDate.getTime() + expires * 1000 * 3600 * 24);
	}
	document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : ("; expires=" +LargeExpDate.toGMTString())) + "; path=/;";
} 

