//Mr. King's Pop-Up Maker
function popUp(URL,ID,S,R,W,H) {
	window.open (URL,ID,"menubar=0,scrollbars="+S+",resizable="+R+",width="+W+",height="+H);
}

function MM_jumpMenu(targ,selObj,restore) {
	var test = selObj.options[selObj.selectedIndex].value;
	if (test) {
		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	}
	if (restore) selObj.selectedIndex=0;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


//preload nav images
MM_preloadImages('/_catalogs/masterpage/img/nav_on_01.gif')
MM_preloadImages('/_catalogs/masterpage/img/nav_on_02.gif')
MM_preloadImages('/_catalogs/masterpage/img/nav_on_03.gif')
MM_preloadImages('/_catalogs/masterpage/img/nav_on_04.gif')
MM_preloadImages('/_catalogs/masterpage/img/nav_on_05.gif')
MM_preloadImages('/_catalogs/masterpage/img/nav_on_06.gif')
MM_preloadImages('/_catalogs/masterpage/img/nav_on_07.gif')
MM_preloadImages('/_catalogs/masterpage/img/nav_on_08.gif')

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//AJAX include_______________________________________________

function include(xUrl,xId) {

  var xmlhttp = false;

  /*@cc_on @*/

  /*@if (@_jscript_version >= 5)

  // JScript gives us Conditional compilation, we can cope with old IE versions.

  // and security blocked creation of the objects.

  try {

    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

   } catch (e) {

      try {

        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (E) {

        xmlhttp = false;

      }

   }

  /*@end @*/

  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {

    xmlhttp = new XMLHttpRequest();

  }

  xmlhttp.open("GET", xUrl,true);

  xmlhttp.onreadystatechange=function() {
          if (xmlhttp.readyState==4) {
                document.getElementById(xId).innerHTML = xmlhttp.responseText;
          }
  }

  xmlhttp.send(null)
}



//dhtml menu_______________________________________________
//This is the new java file



var runOnce = 0;
function positionMenu() { //first called from HTML to initialize menu
	
	//run once
	runOnce = 1;
	if (!runOnce) {
		//alert("running once");
		runOnce = 1;
		
		//add omouse events to menu
		menuObj_nav = document.getElementById("navRow1")
		menuObj_nav.onmouseover = hideAllDivs_timer_cancel
		menuObj_nav.onmouseout = hideAllDivs_timer_start
		
		menuObj_hidden = document.getElementById("hiddenMenu")
		menuObj_hidden.onmouseout = hideAllDivs_timer_cancel

/*
		menuObj_7 = document.getElementById("dropDown_7")
		menuObj_7.onmouseout = hideAllDivs_timer_start
		menuObj_7.onmouseover = hideAllDivs_timer_cancel
*/
		


		//menuObj_hidden.onmouseout = hideAllDivs_timer_start
		//loginFormObj.onmouseover = hideAllDivs_timer_start
	}

	hideAllDivs();
	/*
	if (window.innerWidth) { //ff
		var browserWidth = window.innerWidth - 17;
	} else if (document.all) { //ie
		var browserWidth = document.body.clientWidth;
	}
	*/
	var browserWidth = document.documentElement.clientWidth; //ff or ie
	
	if (browserWidth > 946) {
		var pos = (browserWidth - 946) / 2;
	} else {
		var pos = 0;
	}
	document.getElementById("hiddenMenu").style.position = "absolute";
	document.getElementById("hiddenMenu").style.top = "145px";
	document.getElementById("hiddenMenu").style.left = pos+"px";
}
window.onresize = positionMenu;

function hideDiv(id) {
	var id = "dropDown_"+id;
	if (document.getElementById) {
		document.getElementById(id).style.display = 'none';
	}
}

function showDiv(id) {	
	var id = "dropDown_"+id;
	hideAllDivs();
	startTimeOut();
	//show menu
	if (document.getElementById) {
		document.getElementById(id).style.display = 'block';
	}
}

var timeOut = null;
function hideAllDivs_timer_start() {
	clearTimeout(timeOut)
	timeOut=setTimeout("hideAllDivs()",3000)
}
function hideAllDivs_timer_cancel() {
	alert("hideAllDivs_timer_cancel")
	clearTimeout(timeOut)
}

function hideAllDivs() {
	//hide all menus
	//alert("hideAllDivs")
	var i=1
	for (i=1;i<=8;i++) {
		var id = "dropDown_"+i;
		document.getElementById(id).style.display = "none";
	}
}

var timeOut = 0;
function startTimeOut() {
	//alert("x");
	clearTimeout(timeOut)
	timeOut=setTimeout("hideAllDivs()",3000)
	
}



//random background image_________________________________________
function randomBG() {

	var rootDir = "/pages/img/backgrounds/";
	//var rootDir = "/img/backgrounds/";

	//show random background for homepage

	var images = new Array()
	images[0] = "clubPrograms.jpg"
	images[1] = "socialRec.jpg"
	images[2] = "inTheGym.jpg"
	images[3] = "futureNow.jpg"
	images[4] = "creativeLab.jpg"
	images[5] = "techCenter.jpg"
	images[6] = "communityCenter.jpg"
	images[7] = "extracurricular.jpg"
	
	var imageIndex = Math.floor( Math.random()*images.length );

	//show specific background for each channel (8)
	
	var dirs = new Array();
	dirs[0] = "/ClubPrograms"
	dirs[1] = "/SocialRec"
	dirs[2] = "/InTheGym"
	dirs[3] = "/FutureNow"
	dirs[4] = "/CreativeLab"
	dirs[5] = "/TechCenter"
	dirs[6] = "/CommunityCenter"
	dirs[7] = "/Extracurricular"

	var n = 0;
	var str = location.pathname;
	for (n in dirs) {
		var searchStr = dirs[n];

		//search for dir in location.path
		if ( str.indexOf(searchStr) > -1) {
			//document.write("JK.debug > found "+dirs[n]+" in location.pathname")
			imageIndex = n;
		}

	}


	//change background image
	document.body.style.backgroundImage='url(' + rootDir + images[imageIndex]+ ')'
}



//randomAds______________________________________________

function randomAds() {

	//alert("randomAds");

	var rootDir = "/pages/inc/ads/";
	

	//for certain pages of the site, show specific ads

	var str = location.pathname;
	var show_large_01 = "";
	var show_small_01 = "";
	var show_small_02 = "";
	var show_small_03 = "";
	
	//BEGIN if-then statements for each page
	if (str.indexOf("/Pages/Default.aspx") == 0) { //home page
		var show_large_01 = "0";
		var show_small_03 = "0";
	}
	if (str.indexOf("/TechCenter") == 0) { //tech center directory
		var show_large_01 = "0";
	}
	//END if-then statements for each page
	
	
	//large ads
	var images = new Array()
	images[0] = "08.Election.promo.300x250.jpg"
	images[1] = "skillTechBasic.jpg"
	images[2] = "skillTech2.jpg"
	images[3] = "DAS.jpg"
	
	var URLs = new Array()
	URLs[0] = "/CommunityCenter/InTheClub/Pages/Default.aspx"
	URLs[1] = "/TechCenter/SkillTechI"
	URLs[2] = "/TechCenter/SkillTech2"
	URLs[3] = "/TechCenter/DigitalArtsSuite"
	
	var imageIndex = Math.floor( Math.random()*images.length );
	if (show_large_01) {var imageIndex = show_large_01}

	document.getElementById("_ad_large_01").src = rootDir + "large/" + images[imageIndex];
	document.getElementById("_ad_large_01_url").href = URLs[imageIndex];


	//small ad 01
	var images = new Array()
	images[0] = "careerLaunch.jpg"
	images[1] = "keystone.jpg"
	
	var URLs = new Array()
	URLs[0] = "/ClubPrograms/ClubProgramDetails/CareerLaunch"
	URLs[1] = "/Extracurricular/Keystone"
	
	var imageIndex = Math.floor( Math.random()*images.length );
	if (show_small_01) {var imageIndex = show_small_01}

	
	document.getElementById("_ad_small_01").src = rootDir + "small/" + images[imageIndex];
	document.getElementById("_ad_small_01_url").href = URLs[imageIndex];


	//small ad 02
	var images = new Array()
	images[0] = "moneyMatters.gif"
	images[1] = "triplePlay.jpg"
	
	var URLs = new Array()
	URLs[0] = "/ClubPrograms/ClubProgramDetails/MoneyMatters"
	URLs[1] = "/ClubPrograms/ClubProgramDetails/Pages/default.aspx#tripleplay"

	var imageIndex = Math.floor( Math.random()*images.length );
	if (show_small_02) {var imageIndex = show_small_02}

	
	document.getElementById("_ad_small_02").src = rootDir + "small/" + images[imageIndex];
	document.getElementById("_ad_small_02_url").href = URLs[imageIndex];


	//small ad 03
	var images = new Array()
	images[0] = "Ad_Sm_DigArtsFest.jpg"
	images[1] = "YOY.jpg"

	var URLs = new Array()
	URLs[0] = "/CreativeLab/DigitalArtsFestivals/Pages/Digitalartsfestival.aspx"
	URLs[1] = "/Extracurricular/YOY"
	
	var imageIndex = Math.floor( Math.random()*images.length );
	if (show_small_03) {var imageIndex = show_small_03}
	
	document.getElementById("_ad_small_03").src = rootDir + "small/" + images[imageIndex];
	document.getElementById("_ad_small_03_url").href = URLs[imageIndex];

}



//init_______________________________________________
function init() {
	//positionMenu() //to fix FF "late scrollbar appear" bug
}