//determine which section this file is in
var tarray,docnav,subnav,subnav2;
docnav=""; subnav=""; subnav2="";

if (typeof(pageNum)=="string") {
	tarray = pageNum.split("."); 
	if (tarray.length>0) {
		docnav = tarray[0];
		if (tarray.length>1) {
			subnav = tarray[1];
			if (tarray.length>2) {
				subnav2 = tarray[2];
			}
		}
	}
}

//alert("pageNum: " + pageNum + "\ndocnav: " + docnav + "\nsubnav: " + subnav + "\nsubnav2: " + subnav2);

//Define global variables
var timerID = null;
var timerOn = false;
var timecount = 1000;
var what = null;
var newbrowser = true;
var check = true;//false;
var xd = 0;


window.onresize=winResize;


// makes topnav images "highlite" for currect section
function setNav() {
    alert("setNav");
    //alert(docnav);
	if ((docnav > 0 && docnav < 16) || docnav==23) {
		document.images[navArray[docnav]].src='/images/topnav/'+navArray[docnav]+'_lit.gif';
	}
}

// makes footer text links "active" for current section
function setFooterNav(x) {
	alert("setFooterNav");

	//alert(docnav + " " + x);
	//alert(x);
	if (docnav == x && docnav + "." + subnav != '19.2') {		
		document.write("<span class=\"navtextActive\">");
	} else if (pageNum == x) {
		//special case for order catalog, a subnav of promotions, but in the footer
		document.write("<span class=\"navtextActive\">");
	} else if (docnav + "." + subnav == x) {
		//special case for join us, a subnav of about us, but in the footer
		document.write("<span class=\"navtextActive\">");
	} else {
		document.write("<span>");
	}
}


// makes subnav text links "active" for current section
function setSubNav(x) {
	alert("setSubNav");

	//alert(subnav + " " + x);
	if (subnav == x) {
		document.write("<span class=\"subnavtextActive\">");
	} else {
		document.write("<span>");
	}
}


// makes subnav text links "active" for bridal and accessories sections
function setSubNav2(x) {
	//alert(qstring + " " + x);
	if (qstring.indexOf(x) > -1) {
		document.write("<span class=\"subnavtextActive\">");
	} else {
		document.write("<span>");
	}
}


// makes subnav text links "active" for current section
function setSubNav3(x) {
	//alert(subnav + " " + x);
	if (subnav2 == x) {
		document.write("<span class=\"subnavtextActive\">");
	} else {
		document.write("<span>");
	}
}

// unhlite function leaves the appropriate nav section lit on mouseout
function navUnHlite(x) {
	if (((x >= 0 && x < 16) || x==23) && docnav != x) {
		document.images[navArray[x]].src='/images/topnav/'+navArray[x]+'.gif';
	}
}


// Turns the layers on and off
function showLayer(layerName) {
	//alert(getRealPos(document.images["dbmainlogo"],"Left"));
	//alert(layerName+":"+document.getElementById(layerName).style.left);

	hideAll2();
	if(check){
		//alert(document.getElementById('welcome').className);
		document.getElementById('welcome').className="welcome_hide";
		if (what =="none"){
			return;
		}
		else if (what == "moz"){
			document.getElementById(layerName).style.visibility="visible";
		}
		else{
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
		}
	}
	else {// alert ("Please wait for the page to finish loading.");
		return;
	}
}
        
function showLayer2(layerName){
	if(check){
		if (what =="none"){
			return;
		}
		else if (what == "moz"){
			document.getElementById(layerName).style.visibility="visible";
		}
		else{
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"');
		}
	}
	else {// alert ("Please wait for the page to finish loading.");
		return;
	}
}

function hideLayer(layerName){
	if(check){
		if (what =="none"){
			return;
		}
		else if (what == "moz"){
			document.getElementById(layerName).style.visibility="hidden";
		}
		else{
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"');
		}

	}
	else {
		// alert ("Please wait for the page to finish loading.");
		return;
	}
}


function hideAll(){
	for (i=1;i<5;i++) {
		hideLayer("subnav"+i);
	}
	if (docnav == 0) {

		document.getElementById('welcome').className="welcome_show";
		show_welcome = 'true';
	}

	if (docnav>0 && docnav<5) {
		showLayer("subnav"+docnav);
	}
}

function hideAll2(){
	for (i=1;i<5;i++) {
		hideLayer("subnav"+i);
	}
}

function startTime() {
	if (timerOn == false) {
		timerID=setTimeout( "hideAll()" , timecount);
		timerOn = true;
	}
}


function stopTime() {
	if (timerOn) {
		clearTimeout(timerID);
		timerID = null;
		timerOn = false;
	}
}

function getRealPos(i,which) {
	iPos = 0;
	while (i!=null) {
		iPos += i["offset" + which];
		i = i.offsetParent;
	}
	return iPos;
}

//window.onresize=winResize;

function initMenus(){
	//alert ("Running Init");
	if (document.layers) {
		//  alert ("Running Netscape 4");
		layerRef="document.layers";
		styleSwitch="";
		visibleVar="show";
		screenSize = window.innerWidth;
		what ="ns4";
	} else if(document.all){
		//  alert ("Running IE");
		layerRef="document.all";
		styleSwitch=".style";
		visibleVar="visible";
		screenSize = document.body.clientWidth + 18;
		what ="ie";

	} else if(document.getElementById){
		//  alert ("Running Netscape 6");
		layerRef="document.getElementByID";
		styleSwitch=".style";
		visibleVar="visible";
		what="moz";

	} else {
		//alert("Older than 4.0 browser.");
		what="none";
		newbrowser = false;
	}

	//check = true;
	centerAllMenus();
}


function centerAllMenus() {
    //alert("centering menus");
	if (document.layers) {
		 if (window.innerWidth > 620) {
			xd = (window.innerWidth - 620) / 2;
		 }
		 /*if (window.innerHeight > 365) {
			yd = (window.innerHeight - 365) / 2;
		 }*/
		 for (i=1; i<7; i++) {
			document.layers["subnav"+i].left += xd;
			//document.layers[i].top += yd;
		    //document.layers[i].left += 2;
		 }
	} else if (document.all && !document.getElementsByTagName) {
		if (document.body.offsetWidth > 620) {
		    xd = (document.body.offsetWidth - 620) / 2;
		}
		/*if (document.body.offsetHeight > 365) {
		   yd = (document.body.offsetHeight - 365) / 2;
		}*/
		var theLeft;
		var theTop;
		var infolayers = ['subnav1','subnav2','subnav3','subnav4','subnav5','subnav6'];
		for (i=0;i<infolayers.length;i++) {
			eval('theLeft = parseInt(document.all.'+ infolayers[i] + '.style.left)');
			theLeft += xd;
			theLeft += 'px';
			eval('document.all.' + infolayers[i] + '.style.left = theLeft');
			/*eval('theTop = parseInt(document.all.' + infolayers[i] + '.style.top)');
			theTop += yd;
			theTop += 'px';
			eval('document.all.' + infolayers[i] + '.style.top = theTop');
		    */
        }
		//document.all.imcmain.style.visibility = visible;
	} else if (document.getElementsByTagName) {
		var aDivs = document.getElementsByTagName("div");
		if (document.all) {
           	 	//alert(document.body.offsetWidth);
			if (document.body.offsetWidth > 760) {
				//xd = (document.body.offsetWidth - 760) / 2;
                		//xd -= 10;
                		xd = -9;
			}
			/*if (document.body.offsetHeight > 365) {
				yd = (document.body.offsetHeight - 365) / 2;
			}*/
		} else {
			if (window.innerWidth > 760) {
				xd = (window.innerWidth - 760) / 2
			}
			/*if (window.innerHeight > 365) {
				yd = (window.innerHeight - 365) / 2
			}*/
		}
        	xd=-30;
        	
        	//alert("xd: " + xd);
		for (i=1; i < 7; i++) {
			//aDivID=aDivs[i].id;
			//document.getElementById("subnav"+i).style.left = parseInt(document.getElementById("subnav"+i).style.left) + xd + "px";
			document.getElementById("subnav"+i).style.left = (getRealPos(document.images["thelogo"],"Left") + xd) + "px";
            		//alert(document.getElementById("subnav"+i).style.left)
            		//document.getElementById(aDivID).style.top = parseInt(document.getElementById(aDivID).style.top) + yd + "px";
			//if (aDivs[i].id == "imcmain" || aDivs[i].id == "info0") {
			//	document.getElementById(aDivID).style.visibility = "visible";
			//}
           		//alert(i+":"+document.getElementById("subnav"+i).style.left);
		}
	}
    
    check = true;
    
    var mapping = Array("home","cars","wedding","balls","celebrations","corporate","contact");
    
	//alert("MM_swapImage('Image"+(parseInt(docnav)+1)+"','','images/"+mapping[docnav]+"_mo.gif',1)");
	eval("MM_swapImage('Image"+(parseInt(docnav)+1)+"','','images/"+mapping[docnav]+"_mo.gif',5)");
    if (docnav>0 && docnav<7) {
        showLayer("subnav"+docnav);
	if (subnav>0) {
		document.getElementById("nav"+docnav+subnav).className="subnavHighlight";
	}
    }

    //alert("menus centered");
}

function winResize() {
    //alert("onresize fired");
    centerAllMenus();
}