$(document).ready(function(){
	var menuOptions = {
		direction:"down",
		showL3s:true,
		speed:400
	};
	willow.getMenu("45148|45149|45150|45151|45260|45152|45153",function(data){
		$("#nav").menu(data.menu,menuOptions);
		var footMenu = data.menu,menuString = "";
		for(var i = 0; i < footMenu.length; i++){
			if(i == footMenu.length-1)
			{
				menuString+="<li class='footL1li lastFnav'><a id='footL1_"+footMenu[i].id+"' class='footL1a' href='"+footMenu[i].url+"'>"+footMenu[i].title+"</a>";
				if(footMenu[i].L2.length > 0){
					menuString+="<ul class='footerL2'>";
					for(var j = 0; j < footMenu[i].L2.length; j++){
						menuString+="<li><a href='"+footMenu[i].L2[j].url+"'>"+footMenu[i].L2[j].title+"</a></li>";
						}
					menuString+="</ul>";
				}
				menuString+="</li>";
			}
			else
			{
				menuString+="<li class='footL1li'><a id='footL1_"+footMenu[i].id+"' class='footL1a' href='"+footMenu[i].url+"'>"+footMenu[i].title+"</a>";
				if(footMenu[i].L2.length > 0){
					menuString+="<ul class='footerL2'>";
					for(var j = 0; j < footMenu[i].L2.length; j++){
						menuString+="<li><a href='"+footMenu[i].L2[j].url+"'>"+footMenu[i].L2[j].title+"</a></li>";
						}
					menuString+="</ul>";
				}
				menuString+="</li>";
			}
		}
		$("#footL1").append(menuString);
	});

	var options = {
		sid:270,
		gid:12202,
		pager:"#pager",
		speed:8000
	}
	
	$("#news").newsticker(options);
	
	// Podium search
	$('#search').pdSearch({showButton:true, showButtonClass:'searchButton', showButtonText:''});
});

// Opens mml player
function openMML(consoleid, galleryid, mediaid, mediatype) {
	var pGallery = (galleryid > 0)?'&gallery_id=' + galleryid:'';
	var pMedia = (mediaid > 0)?'&mediatype=' + mediatype +'&mediaid=' + mediaid:'';
	window.open('/podium/MediaLibrary/player/default.aspx?console_id=' + consoleid + pGallery + pMedia + '&browse=yes&recent=yes', '_blank', 'location=no, menubar=no, scrollbar=no, status=no, resizable=no, height=497, width=700');
}

function submitSearch(){
	window.location = "/podium/default.aspx?t=52392&q="+document.getElementById("search").value+"&pt=Polytechnic School Search";
}

function SubmitOnEnter(evt){
	var charCode = (evt.which) ? evt.which : event.keyCode
	if(charCode == "13" || charCode == "26"){
		submitSearch();
		return false;
	}
}

var t = new Array();
var to;
var newsnow;    	
function runfade(){
	var q = 0;
	var x = document.getElementsByTagName("div");
	for (var i=0;i<x.length;i++){
		if(x[i].id.substring(0,2)=='ne'){
			t[q]= x[i].id
			q++;	
		}
	}
	if(t.length > 0){
		newsnow=0;
		opacity=100;
		tpx = t[newsnow]
		getmyObj(tpx).style.display='';
		to = window.setTimeout("fadeout("+opacity+")", 5000);	
	}
}
function fader(opacity){
	//alert(opacity);
	var obj = new getmyObj('fader');
	obj.style.opacity = (opacity / 100); 
	obj.style.MozOpacity = (opacity / 100); 
	obj.style.KhtmlOpacity = (opacity / 100); 
	obj.style.filter = "alpha(opacity=" + opacity + ")"; 
}
function getmyObj(obj){
	if (document.getElementById)
		return document.getElementById(obj)
	else if (document.all)
		return document.all[obj]
}
function fadein(opacity){
	if (opacity < 100) {
		fader(opacity);
		opacity += 5;
		to = window.setTimeout("fadein("+opacity+")", 30);
	}
	else{
		to = window.setTimeout("fadeout("+opacity+")", 5000);	
	}
}
function fadeout(opacity){
	if (opacity > 0) {
		opacity -= 5;
		fader(opacity);
		 to = window.setTimeout("fadeout("+opacity+")", 30);
	}
	else{	
		fader(opacity);
		tpx = t[newsnow]
		getmyObj(tpx).style.display='none';
		newsnow++;
		if (newsnow>=t.length) {
			newsnow=0;
		}
		tpx = t[newsnow]
		getmyObj(tpx).style.display='';
		to = window.setTimeout("fadein("+opacity+")", 100);
	}
}
function pause() {
	clearTimeout(to);
	fader(100);
}
function resume() {
	clearTimeout(to);
	to = window.setTimeout("fadeout(100)", 5000);
}
//----------------------script doubled for events!!!!!!-----------------------
