// page initialization
jQuery(document).ready(function(){

	pid = $('body').attr("class");
	
	$("div#mainNav ul.mainlevel_nav").superfish({delay:200,animation:{opacity:"show"},speed:150,dropShadows:false,autoArrows:false});

	if (pid == "pageHome") {
		$('#bkgdPic').cycle({ 
			fx:      'fade', 
			timeout: 5000,
			speed:   1500,
			random:  1,
			pause:   0
		});
		
		dist = 290;
		le = $("div#videoList ul li").length;
		lx = le - 2;
		$("div#videoList ul li:first").clone().insertAfter("div#videoList ul li:eq("+lx+")");
				
		$("div#videoScrollRight img").click(function(){
			le = $("div#videoList ul li").length;
			lf = $("div#videoList").css("left");
			le = le/2;
			qu = 0 - ((le - 1) * dist)+"px";
			if (lf != qu) $("div#videoList").animate({"left": "-="+dist+"px"}, "medium");
			else {
				$("div#videoList").css("left","0px");
				$("div#videoList").animate({"left": "-="+dist+"px"}, "medium");
			}
		});

		$("div#videoScrollLeft img").click(function(){
			le = $("div#videoList ul li").length;
			lf = $("div#videoList").css("left");
			if (lf != "0px") $("div#videoList").animate({"left": "+="+dist+"px"}, "medium");
			else {
				to = 0-(((le/2)-1) * dist);
				$("div#videoList").css("left",(to+"px"));
				$("div#videoList").animate({"left": "+="+dist+"px"}, "medium");
			}
		});

		
	} else if (pid == "pageSub") {
		var n = jQuery("div#bkgdPic > img").length;
		nx = rndm(n);
		if (nx < 0) nx = 0;
		if (nx > (n-1)) nx = (n-1); 
		$("div#bkgdPic img:eq("+nx+")").css("display","block");
	}

	
});

function rndm(n) { return Math.round((Math.random())*n); }

// open a new window and bring it to the front
function jsWindow(u,w,o) {
	jsOpen = window.open(u,w,o);
	jsOpen.window.focus();
}

// open printable page
function printPage(u) {
	jsWindow(u,"Printing","width=600,height=500,scrollbars=1");
}

