/*****************************/
/*** Drop down menu  *****/
/*** From http://javascript-array.com/scripts/jquery_simple_drop_down_menu/  *****/
/*****************************/

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;
var ddhdr = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_off();
   ddmenuitem = $(this).find('ul').css('display', 'block'); 
   ddhdr = $(this).find('a.nav_link').addClass('active');
}

function jsddm_off()
{  if(ddmenuitem) ddmenuitem.css('display', 'none');
    if(ddhdr) ddhdr.removeClass('active');
}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('display', 'none');
}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_off, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('#jsddm > li').bind('mouseover', jsddm_open)
    $('#jsddm > li').bind('mouseout',  jsddm_timer)});

document.onclick = jsddm_close;

/*****************************/
/*** Dropdown for ReadingRoom *****/
/*****************************/


toggle = false;
function revealRRTitle(pubTitle1, pubTitle2) {
toggle = toggle ? false : true;
show = toggle ? "visible" : "hidden";
document.getElementById(pubTitle1).style.visibility=show;
document.getElementById(pubTitle2).style.visibility=show;
n = toggle ? document.getElementById(pubTitle2).offsetHeight : 0;
document.getElementById(pubTitle1).style.height=n;
toggle = false;
}


/***********************************************************************************************/
//font resizer
baseSize = 9;
function checkFontSetting() {

	if (document.cookie.indexOf("fontSize")>=0) {
		cookieVal = document.cookie.split("fontSize=")[1];
		baseSize=0;
		changeType(cookieVal*1)
	}
}

function changeType(sizeDiff) {
	baseSize += sizeDiff;
	if (baseSize < 30 && baseSize > 5) {
		if(document.getElementById("articleText")){
		document.getElementById("articleText").style.fontSize = baseSize + "pt" ;
		document.cookie = "fontSize="+baseSize+";path=/";
		}
	}
}

// popup window	& Legacy Functions
wdth=640;ht=580;scrl=1;rs=1;name="Immaterial";
function popwin(file,wdth,ht,name,scrl,rs) { 
// POPUP WINDOW SIZE ADJUSTMENTS
var size = 'width=' + wdth + ',height=' + ht;
if (scrl)	{ size += ',resizable,status';}
if (rs)		{ size += ',scrollbars';}

p = open(file, name, size); 
p.focus();
}



/*****************************/
/*** Image Viewer Pop Up Issue 10 Legacy *****/
/*****************************/

function openBrWindow(theURL,winName,features) { 
     window.open(theURL,winName,features); 
} 


/*****************************/
/*** Munge Function *****/
/*****************************/

function munge(p1,p2) {
     var box = p1 + p2;
     var a = "@";
     var dom = "cabinetmagazine";
     var dot = ".";
     var tld = "org";
     alert("You can reach us at: " + box + a + dom + dot + tld);
}

/*****************************/
/*** Image Viewer Popup *****/
/*****************************/

function openViewer(imagePath,imgNum) {
	str = "/sitewide/pop.php?imagePath=" + imagePath + "&imgNum="  + imgNum
	window.open (str,"pic","height=550,width=550,scrolling=auto,scrollbars")
	}

/*****************************/
/*** Media Viewer Popup *****/
/*****************************/
function openMedia(mediaType,mediaPath) {
	features = "";
	mediaString = "/sitewide/mediaplayer.php";
	if (mediaType=="audio") {
	features+="height=140,width=360"
	mediaString+="?mediaType=audio";
	}
	else {
	features+="height=390,width=360"
	mediaString+="?mediaType=video";
	}
	mediaString+="&mediaPath="+mediaPath
	mediaWin = window.open(mediaString,"mediaWin",features);
	mediaWin.focus();
}



/*****************************/
/*** OLD down menu  *****/
/*****************************/

function nullit() {return true;}
//window.onerror = nullit

var NS = (navigator.appName == "Netscape");
mac = navigator.appVersion.indexOf("Mac");
if (mac>=0) {mac=1} else {mac=0}
IE4 = (document.all) ? true : false; 
NS4 = (document.layers) ?  true : false;
NS6a = document.getElementById;
if(NS6a && NS) {NS6=true} else {NS6=false}
if ((IE4) || (NS4) || (NS6)) {dhtml=1;}

if(NS4){ origWidth = innerWidth ; origHeight = innerHeight; pageurl = self.location;}

function re() {
	if (NS4) {if (innerWidth != origWidth || innerHeight != origHeight){ 
	location.reload(true) 
	}}}
	window.onResize = re;

if (NS4){origWidth = innerWidth;origHeight = innerHeight;}

/***********************************************************************************************/	
px = ""; 
menuOn = -1; 
menuTopFixed = 53; 
ext = 10;
layerLeftPos = 0; 
flashPresent = 0; 
layerDims_y = new Array;
layerDims_x = new Array;
//
menuLeftPosition = new Array(190,255,331,388,438,513,580);// adjust for menu heads
adjustment = 2;

function MakeArray(n){
	this.length = n
		for (var i = 1; i<=n; i++) {
		this[i] = new Image()
	   }
	   return this;
	}

var menuImageName = new Array("nav_issu","nav_info","nav_evnt","nav_art","nav_subscr","nav_shop","nav_srch")
num = 0
	
if (document.images) {
		header_Over = new MakeArray(7);
		header_Out = new MakeArray(7);
		for (imgX=0;imgX<7;imgX++){
		header_Out[imgX] = new Image(); 
		header_Out[imgX].src = "/sitewide/images/" + menuImageName[imgX] + "_off.gif";
		header_Over[imgX] = new Image();
		header_Over[imgX].src = "/sitewide/images/" +menuImageName[imgX] + "_on.gif";
		}
	}
	
function headerOver(num){ 
	eval ("document." + menuImageName[num] + ".src ='" + header_Over[num].src +"'")
	if ((num != section)){ // turns off the section indicator
		eval ("document." + menuImageName[section] + ".src ='" + header_Out[section].src +"'")
		}
	}

function headerOut(num){ 
	if ((num != section)){}
	eval ("document." + menuImageName[num] + ".src ='" + header_Out[num].src +"'")
	}
 
function refConstructor(refElement) {
	if (NS6) {var prefix = "document.getElementById('" + refElement + "')"}
	if (IE4) {var prefix = "document.all." + refElement}
	if (NS4) {var prefix = "document." + refElement}
	return prefix;
	}
 
function menuInit() { 
	for (menuNumber = 0;menuNumber<7;menuNumber++) {
		layerRef =  refConstructor("menu" + menuNumber);
		layerDims_y[menuNumber]  = (IE4 || NS6) ? eval(layerRef + ".offsetHeight + menuTopFixed") : eval(layerRef + ".clip.height + menuTopFixed");
		layerDims_x[menuNumber]  = (IE4 || NS6) ? eval(layerRef + ".offsetWidth + 5") : eval(layerRef + ".clip.width + 5");
	}
	//if (flashPresent==1){ toggleFlash("visible") }
	}
 
function reportEvent(menuEvents) {
	var layerRef 	=	refConstructor("menu" + menuOn)
	mousePos_y  	=	(IE4) ? event.y + menuTopFixed : menuEvents.pageY + menuTopFixed
	mousePos_x  	=	(IE4) ? event.x : menuEvents.pageX
	minMousePos_y 	=	(IE4) ? (menuTopFixed - document.body.scrollTop - 50) : (menuTopFixed-50);
  	if(	(mousePos_y >(layerDims_y[menuOn] + menuTopFixed + ext)) || ((mousePos_y - menuTopFixed) < minMousePos_y ) || 	(mousePos_x < (layerLeftPos - 10)) || (mousePos_x > (layerDims_x[menuOn] + layerLeftPos)))	{ 
		(IE4 || NS6) ? eval(layerRef + ".style.visibility = 'hidden'") : eval(layerRef + ".visibility = 'hidden'");
		headerOut(menuOn);
		if ((num != section) || (num==0 && section==0)){ // turns the section indicator back on
		eval ("document." + menuImageName[section] + ".src ='" + header_Over[section].src +"'")
		}
		//if (flashPresent==1){ toggleFlash("visible") }
 		if (IE4 || NS6) { document.onmousemove = null }
		else{ document.releaseEvents(Event.MOUSEMOVE) }
		}
	}
 
function menu(menuCall) {
	headerOver(menuCall);
	layerRef =  refConstructor("menu" + menuOn)
	if (menuOn != menuCall && menuOn != -1){
		(IE4 || NS6) ? eval(layerRef + ".style.visibility = 'hidden'") : eval(layerRef + ".visibility = 'hidden'");
		if (menuOn>=0) { 
			headerOut(menuOn) 
			}
		}
	menuOn = menuCall;
	
	if(dhtml){
		layerLeftPos = (IE4 || NS6) ? ( (document.body.offsetWidth - 740)/2 + menuLeftPosition[menuOn] + adjustment ) : ((innerWidth - 740)/2 + menuLeftPosition[menuOn] + adjustment);
		layerRef =  refConstructor("menu" + menuOn);
		(IE4 || NS6) ? eval(layerRef + ".style.left =" + layerLeftPos) : eval(layerRef + ".left =" + layerLeftPos);

		if (flashPresent==1){ toggleFlash("hidden") }
		if(menuOn<5) { // shop and search do not have menus
			(IE4 || NS6) ? eval(layerRef + ".style.visibility = 'visible'") : eval(layerRef + ".visibility = 'visible'");
		}
		if(document.layers) {document.captureEvents(Event.MOUSEMOVE)};
		document.onmousemove = reportEvent 
		if (IE4) 	{ document.onmouseover = null }
		else		{ document.releaseEvents(Event.MOUSEOVER)};
		}
	} 
	
function toggleFlash(show) {
		if (IE4){document.all.flashLayer.style.visibility = show;}
		if (NS4){document.flashLayer.visibility=show;}
		if (NS4 && (show=="visible")){
		document.flashLayer.top = "0";}
		if (NS6 && (show=="hidden")){
		document.getElementById("flashLayer").style.top = "-300px";	}
		if (NS6 && (show=="visible")){
		document.getElementById("flashLayer").style.top = "0px";}
		}
   
window.onload = menuInit;

section = 0;
if (document.URL.lastIndexOf("information")>=0) section = 1;
if (document.URL.indexOf("events")>=0 ) section = 2;
if (document.URL.indexOf("subscribe")>=0)  section = 4;
if (document.URL.lastIndexOf("art")>=0)  section = 3;
if (document.URL.indexOf("shop")>=0)  section = 5;
if (document.URL.indexOf("search")>=0)  section = 6;

if (IE4 || NS6) {
document.write("<link rel=\"stylesheet\" href=\"/sitewide/cabinetie.css\" type=\"text/css\">\n")
}
