//hide body until major changes take place
//alert("sdb");

//CSP sdb 070110 added this to allow for the Options and Settings dialog to show through in Pushpage2010 on IE8
$(document).ready(function(){
	var isMSIE = /*@cc_on!@*/false;
	if (isMSIE ==true){
		if(pdGlobal.currentPages[0].type=="application" && pdGlobal.currentPageLevel == 4){ 
			var $theOptionsLink = $("a[title*='Options']")
			var $theSettingsLink = $("a:contains('Settings')")
			var $theCancelApplyLink = $("td#btnClose")
			
			$($theOptionsLink).each(function(){
				$(this).click(function() {
					$("#Form1").removeAttr("id");
				});
			});		
			$("a:contains('Settings')").live("click",function() {
				$("#Form1").removeAttr("id");	
			});
			$($theCancelApplyLink).each(function(){
				$(this).click(function() {
					$("form[name*='Form1']").attr("id", "Form1");
				});
			});
		}
	}
});
//CSP sdb 030510 added a space between body and #PageBody, IE didn't like them close together
//document.write("<style>body #PageBody { display:none; }</style>");
//CSP sdb 030510 added this style to hide this div during a refresh in IE
//document.write("<style>#footerContainer { display:none; }</style>");

//CSP sdb 030910 added the .dropdown selector to fix the dropdown for Content Type: under Edit Page



$(document).ready(function(){
	$(".dropdown").css("visibility","visible");
});
var positioningAdjustment = 165,	//in px, from bottom of footer
	IEpositioningFix = 0;			//fixes IE disparity - in px, set to 0 (zero) if not needed

var	L1MenuArray = new Array(
	{pageid: 119620},
	{pageid: 119636},
	{pageid: 119651},
	{pageid: 119704},
	{pageid: 119820}
);

//CSP sdb 100510 added this for the new Podium search feature
$(document).ready(function(){
	$('#search').pdSearch({showButton:true,showButtonClass:'searchArea'});	
});
	
$(document).ready(function(){
	
	if(pdGlobal.currentPages[0] != null) {//see if it does it exsist
		if(pdGlobal.currentPages[0].type=="content" && pdGlobal.currentPages[0].id!=121282){ 
			$("#L1").css("display","block"); $("#L2MenuWrapperRepeat").css("display","block"); 
		}
		
		if(pdGlobal.currentPages[pdGlobal.currentPageLevel-1] && pdGlobal.currentPages[pdGlobal.currentPageLevel-1].type=="content"){ $(".sitelcol").css("display","none"); $(".sitepg").css("padding-left","72px"); }	//hide left column on content pages
		if($(".sitetph").html().length==0){ $(".sitetph").css("display","none"); }		//Check for task photo, hide border if necessary

		buildL2Menu(pdGlobal.currentPages[0].id);
		if(pdGlobal.currentPages[pdGlobal.currentPageLevel-1] && pdGlobal.currentPages[pdGlobal.currentPageLevel-1].type=="content"){  }
			else { $("#L2MenuWrapperRepeat").css("display","none"); /*$("#bannerContainer").css("height","140px"); */}
		
			switch(pdGlobal.currentPages[0].id) {
			case 119620: $("#L1_119620").addClass("on"); break;
			//case 119636: $("#L1_119636").addClass("on"); break;
			case 119636: $("#L1_119636").addClass("on"); $("#L2MenuWrapperRepeat").css("width","971px"); break;//CSP sdb 031809 stretch to find the Tour L2
			case 119651: $("#L1_119651").addClass("on"); $("#L2MenuWrapperRepeat").css("width","971px"); break;//CSP sdb 030209 stretch to find the Camp L2
			case 119704: $("#L1_119704").addClass("on"); break;
			case 119820: $("#L1_119820").addClass("on"); break;
			case 52302: $("#omni_52302").addClass("on"); break;
			case 123323: $("#MyEllisTitle").css("display","none"); break;//CSP sdb 022509 added this to hide the graphic
			case 123335: $("#MyEllisTitle").css("display","none"); break;//CSP sdb 022509 added this to hide the graphic
			case 121282: break;
			case 111709:
			default:
				$("#omni_111709").addClass("on");
				//show the MyEllis graphical page title on any app/portal type pages other than the "EllisToday" page
				$(".sitepg").css("padding-top","30px");
				$("#MyEllisTitle").css("display","block");
			break;
		}
	}	
	//CSP sdb 022509 added this to hide the graphic
	//if(pdGlobal.currentPages[pdGlobal.currentPageLevel-1].type=="portal"){  }
		//alert(pdGlobal.currentPages[0].id);
		//switch(pdGlobal.currentPages[0].id) {
			//case 119197: $("#MyEllisTitle").css("display","none");//my intention is to hide if on pageID 123335, but 119197 is what comes up
			//break;
				//default:
				//break;
	//}

	//any general fixes to make all these whacky things work correctly
		$(".galcap-11962").css("overflow","hidden");	//fixed gallery caption had overflow:auto - caused scroll bar to appear in IE

	//Display body after immediate changes
	$("body").css("display","block");

	//"wrap" the page (#Form1) with divs (actual wrapping seems to break podium irreparably, so we put some before, some after)
	$("#Form1")
		.before("<div id='beforeContainer'><div id='before1'><!-- --></div><div id='before2'><!-- --></div>")
		.before("<div id='psuedoAfterContainer'><div id='psuedoAfter1'><!-- --></div><div id='psuedoAfter2'><!-- --></div></div>")
		.before("<div id='pageBottom'><!-- --></div><div id='clearMe'><!-- --></div>");
		positionContainersNoConflict();
		setTimeout("positionContainersNoConflict()",250);
		setTimeout("positionContainersNoConflict()",1000);
		setTimeout("positionContainersNoConflict()",1500);

	$("#pageBottom").html("<img src='/images/spacer.gif' height='1' width='1111' border='0' alt=''>");
	//CSP sdb 030510 added this so as to show after a refresh in IE
	$("#footerContainer").css("display","block");
	positionContainersNoConflict();
	//bind a click event to the portal/app expand/collapse buttons
		//edit: changed selector to grab the expand/collapse buttons in any channel to work with podium update (12/3/08)
		$(window).load(function(){
			//CSP selector from the 12/3/08 change was @scr^ but IE didn't like it
			$("img[src*='/ftpimages/389/podium/style692/icons/collapse.png']").bind("click",function(){ positionContainersNoConflict();});
			$("img[src*='/ftpimages/389/podium/style692/icons/expand.png']").bind("click",function(){ positionContainersNoConflict(); });
		});
		
});

//recalculate our container top whenever the window is resized
$(window).resize(function(){ positionContainersNoConflict(); });

function positionContainersNoConflict(){
	//place the #psuedoAfterContainer div behind the footer
	var	containerTop = document.getElementById("footerContainer").offsetTop - positioningAdjustment,
		pageBottomTop = document.getElementById("footerContainer").offsetTop + document.getElementById("footerContainer").offsetHeight,
		addHeight;
	
	if(navigator.appName.indexOf("Mozilla")!=-1 && navigator.appName.indexOf("Firefox")!=-1  && navigator.appName.indexOf("Netscape")!=-1) { addHeight=150; }
	else if(navigator.appName.indexOf("Microsoft")!=-1) {
		addHeight=455;
		containerTop += IEpositioningFix;
		pageBottomTop += IEpositioningFix;
	}
	else { addHeight=485; }
		
	parent.document.getElementById("psuedoAfterContainer").style.top = containerTop;
	parent.document.getElementById("pageBottom").style.top = pageBottomTop;
	parent.document.getElementById("pageBottom").style.height = addHeight;
	//if(window.console && window.console.firebug){ console.log("Whats the frequency, Kenneth? "+pageBottomTop); }
}

//Search Functions

function submitSearch(){ __pdSiteSearch('The Ellis School - Search', document.getElementById("search").value); }
function SubmitOnEnter(evt){
	var charCode = (evt.which) ? evt.which : event.keyCode
	if(charCode == "13" || charCode == "26"){ submitSearch(); return false; }
}

function buildL2Menu(){
	var	menuString = "",
		allMenus = "",
		anchorTarget,
		level=2;
	//build out L2s for each L1 and write them ALL into the L2Menu area
	for(var i=0; i < L1MenuArray.length; i++){
		for(var h=0; h < pageList.length; h++){
			if(L1MenuArray[i].pageid == pageList[h].parentID && pageList[h].level == level){
				if(pageList[h].target == 1) { anchorTarget = "target='_blank'"; } else { anchorTarget = ""; }
				if(menuString.length > 0) { dividerDot = "<div class='divider'>&bull;</div>"; } else { dividerDot = ""; }
				if(menuString.length == 0) {
					menuString += "<ul id='L2Menu_"+L1MenuArray[i].pageid+"' class='L2Menu' style='display:none;'>";
					classFirst = "class='first'";
				} else { classFirst = ""; }
					menuString += "<li "+classFirst+">"+dividerDot+"<a id='L2Menu_"+pageList[h].pageID+"' class='L2MenuItem' href='"+pageList[h].pageURL+"' "+anchorTarget+">";
						menuString += "<div class='repeater'><div class='left'><div class='right'>";
							menuString += "<span class='textStyle'>"+pageList[h].pageName+"</span>";
						menuString += "</div></div></div>";
					menuString += "</a></li>";
			}
		}
		if(menuString.length > 0) {
			menuString += "</ul>";
			allMenus += menuString;
			menuString = "";
		}
	}
	if(allMenus.length > 0) { $("#L2MenuWrapperRight").html(allMenus); } else { $("#L2MenuWrapperRepeat").css("display","none"); }
	
//set hover states
	var timeout_hide, timeout_show, portal_timeout_hide, thisMenuID, thisButtonID;
	for(var j=0; j < L1MenuArray.length; j++){
	//show correct menu on button hover
		$("#L1_"+L1MenuArray[j].pageid).hover(
			function(){
				clearTimeout(timeout_hide); clearTimeout(timeout_show);
				$('.L2Menu').css('display','none');
				thisMenuID = "#L2Menu_" + $(this).attr("id").substring(3,$(this).attr("id").length);
				//alert(thisMenuID);
					if (thisMenuID == "#L2Menu_119636"){
						$("#L2MenuWrapperRepeat").css("width","911px");	
						
						$(thisMenuID).css('display','block');
					}
					else{
						$("#L2MenuWrapperRepeat").css("width","971px");//CSP sdb 030209 this is the default width
						$(thisMenuID).css('display','block');
					}
			},
			function(){
				thisMenuID = "#L2Menu_" + $(this).attr("id").substring(3,$(this).attr("id").length);
				timeout_hide = setTimeout(function(){ $(".L2Menu").css('display','none') },50);
				if(pdGlobal.currentPages[0]) { timeout_show = setTimeout(function(){ $('#L2Menu_'+pdGlobal.currentPages[0].id).css('display','block') },55); }
			}
		);
	//L2 item hover states
		$("a#L2Menu_+"+L1MenuArray[j].pageid+", li").hover(function(){ $("a.L2MenuItem",this).addClass("on"); }, function(){ $("a.L2MenuItem",this).removeClass("on"); 
		if (thisMenuID == "#L2Menu_119651" || pdGlobal.currentPages[0].id == "119651"){$("#L2MenuWrapperRepeat").css("width","971px");	$("#L2MenuWrapperRight").css("padding-right","0px"); $(thisMenuID).css('display','block'); } });
		//CSP nrm 012510 Moved this if statement to the removeClass("on") function, as the resize is what was causing the L2 menu to lose the last menu item.
	}
	
	//show L2 menu area on general L1 hover when on portal/application pages
		if(pdGlobal.currentPages[pdGlobal.currentPageLevel-1] && pdGlobal.currentPages[pdGlobal.currentPageLevel-1].type!="content"){
			$("#L1").hover(
			
				function(){
					clearTimeout(portal_timeout_hide);
					$("#L2MenuWrapperRepeat").css("display","block");
					if(navigator.appName.indexOf("Microsoft")!=-1) {$("#bannerContainer").css("margin-bottom","0px");}
				},
				function(){
					portal_timeout_hide = setTimeout(function(){
						$("#L2MenuWrapperRepeat").css("display","none");
						if(navigator.appName.indexOf("Microsoft")!=-1) {$("#bannerContainer").css("margin-bottom","1px");}
					},50);
				}
			);
		}
	//keep menu up on menu hover and keep hover state for button
		$(".L2Menu").hover(
			function(){
				clearTimeout(timeout_show); clearTimeout(timeout_hide); clearTimeout(portal_timeout_hide);
				$(".L2Menu").css('display','none'); $(this).css('display','block');
				$("#L2MenuWrapperRepeat").css("display","block");
				if(pdGlobal.currentPages[pdGlobal.currentPageLevel-1].type!="content" && navigator.appName.indexOf("Microsoft")!=-1) {
					$("#bannerContainer").css("margin-bottom","0px");
				}
				thisButtonID = "a#L1_" + $(this).attr("id").substring(7,$(this).attr("id").length);
					$(thisButtonID).addClass("jQueryhover");
			},
			function(){
				$(this).css('display','none');
				if(pdGlobal.currentPages[0]) { $('#L2Menu_'+pdGlobal.currentPages[0].id).css('display','block'); }
				if(pdGlobal.currentPages[pdGlobal.currentPageLevel-1].type!="content"){
					$("#L2MenuWrapperRepeat").css("display","none");
					if(navigator.appName.indexOf("Microsoft")!=-1) {$("#bannerContainer").css("margin-bottom","1px");}
				}
				thisButtonID = "a#L1_" + $(this).attr("id").substring(7,$(this).attr("id").length);
					$(thisButtonID).removeClass("jQueryhover");
			}
		);
	
	
	//show correct L1 menu and set stay state on current L2
	if(pdGlobal.currentPages[0]) { $("ul#L2Menu_"+pdGlobal.currentPages[0].id).css("display","block"); }
	if(pdGlobal.currentPages[1]) { $("a#L2Menu_"+pdGlobal.currentPages[1].id).addClass("stay"); }
}



