var xmouse=0;
var ymouse=0;
//
var unearthWindow="";
var unearthWidth=250;
var unearthHeight=400;
var lostWindow="";
var lostWidth=250;
var lostHeight=screen.availHeight-unearthHeight;
//
var scrollX;
var scrollY;
//
var winWidth;
var winHeight;
var browserWidth;
var browserHeight;
//
var hasPrivate=false;
var id;
var key;
//
var currFeature="na";
// getelementbyid snipet
if(!document.getElementById){
  if(document.all)
  document.getElementById=function(){
    if(typeof document.all[arguments[0]]!="undefined")
    return document.all[arguments[0]]
    else
    return null
  }
  else if(document.layers)
  document.getElementById=function(){
    if(typeof document[arguments[0]]!="undefined")
    return document[arguments[0]]
    else
    return null
  }
}
function updateWindowSize(){
	if (self.innerHeight) // all except Explorer
	{
		winWidth = self.innerWidth;
		winHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		winWidth = document.documentElement.clientWidth;
		winHeight = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		winWidth = document.body.clientWidth;
		winHeight = document.body.clientHeight;
	}

	browserWidth=parent.outerWidth;
	browserHeight=parent.outerHeight;

}

function updateScroll(){
	if (self.pageYOffset) // all except Explorer
	{
		scrollX = self.pageXOffset;
		scrollY = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		scrollX = document.documentElement.scrollLeft;
		scrollY = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		scrollX = document.body.scrollLeft;
		scrollY = document.body.scrollTop;
	}
}
//
// rollover
//
function showRollOver(id){
	var rollover=document.getElementById(id);
	rollover.style.display="block";
	rollover.style.top=ymouse+"px";
	rollover.style.left=xmouse+20+"px";
}
//
// rollout
//
function hideRollOver(id){
	document.getElementById(id).style.display="none";
}
//
// update mouse position
//
function getMousePosition(){
	// Detect if the browser is IE or not.
	// If it is not IE, we assume that the browser is NS.
	var isIe = document.all?true:false
	// If NS -- that is, !IE -- then set up for mouse capture
	if (!isIe) document.captureEvents(Event.MOUSEMOVE)
	// Set-up to use getMouseXY function onMouseMove
	document.onmousemove = getMouseXY;
}

//
// Main function to retrieve mouse x-y pos.s
//
function getMouseXY(e) {
	// Detect if the browser is IE or not.
	// If it is not IE, we assume that the browser is NS.
	var isIe = document.all?true:false
	if (isIe) {
		// grab the x-y pos.s if browser is IE
		var left, top;
		if(document.documentElement){
			left=document.documentElement.scrollLeft;
			top=document.documentElement.scrollTop;
		}else{
			left=document.body.scrollLeft;
			top=document.body.scrollTop;
		}
		xmouse = event.clientX + left;
		ymouse = event.clientY + top;
	} else {
		// grab the x-y pos.s if browser is NS
		xmouse = e.pageX;
		ymouse = e.pageY
	}
	// catch possible negative values in NS4
	if (xmouse < 0){xmouse = 0}
	if (ymouse < 0){ymouse = 0}
}
//
// Main menu
//
function initMainMenu(){
	var btns=["features", "contest", "try", "story", "messages", "store", "apacsite"];
	for(var i=0;i<btns.length;i++){
		document.getElementById(btns[i]+"_rollover").style.display="none";
		var btn=document.getElementById(btns[i]+"_menu");
		btn.rollover=btns[i];
		btn.onmousemove=function(){
			showRollOver(this.rollover+"_rollover");
		};
		btn.onmouseout=function(){
			hideRollOver(this.rollover+"_rollover");
		}
		switch (btns[i]){
			case "features":
			btn.onmouseup=function(){
				scrollToSection("pockets_feature");
			}
			break;
			case "contest":
			btn.onmouseup=function(){
				openUnearth();
			}
			break;
			case "try":
			btn.onmouseup=function(){
				scrollToSection("puton_btn");
			}
			break;
			case "story":
			btn.onmouseup=function(){
				scrollToSection("history_btn");
			}
			break;
			case "messages":
			btn.onmouseup=function(){
				scrollToSection("dishdirt_btn");
			}
			break;
			case "store":
			btn.onmouseup=function(){
				window.open("../../index.html?redirect=storelocator","Store_Locator");
				_hbPageView("store_locator",hbx.mlc);
			}
			break;
			case "apacsite":
			btn.onmouseup=function(){
				_hbPageView("brand_site",hbx.mlc);
				window.open("../../index.html","Levis_Brandsite");
			}
			break;
		}
	}

	var btn=document.getElementById("sound_menu");
	btn.isSoundOn=false;
	btn.onmouseup=function(){
		if(this.isSoundOn){
			document.getElementById("music_frame").src="../black.html";
			this.isSoundOn=false;
			this.value="Sound on";
		}else{
			document.getElementById("music_frame").src="../music.html";
			this.isSoundOn=true;
			this.value="Sound off";
		}
	}
	btn.onmouseup();
	var btn=document.getElementById("home_menu");
	btn.onmouseup=function(){
		document.location="../index.html";
	}
}
//
// features
//
function initFeatures(){
	var features=["pockets","patch","stitch","vintage","waistband","linings","finishing","fit"];
	for(var i=0;i<features.length;i++){
		var sel=document.getElementById(features[i]+"_select");
		sel.feature=features[i];
		sel.onchange=function(){
			var optionValue=this.options[this.selectedIndex].value
			if(optionValue!="na"){
				scrollToSection(optionValue+"_feature");
			}
			this.selectedIndex=0;
		}
		var txt=document.getElementById(features[i]+"_text");
		txt.style.display="none";
		var read=document.getElementById(features[i]+"_read");
		read.status=true;
		read.feature=features[i];
		read.value="read>";
		read.onmouseup=function(){
			if(this.status){
				this.status=false;
				this.value="<fold";
				showFeatureTxt(this.feature);
			}else{
				this.status=true;
				this.value="read>";
				currFeature="na";
				document.getElementById(this.feature+"_text").style.display="none";
			}
		}
		var lost=document.getElementById(features[i]+"_lost");
		lost.onmouseup=function(){
			openLost();
		}
	}
}
function initOthers(){
	var hiddenParts=["puton", "history", "bury_message","public_messages", "private_message"];
	for(var i in hiddenParts){
		document.getElementById(hiddenParts[i]).style.display="none";
	}
}
function showFeatureTxt(id){
	if(currFeature!="na"){
		var read=document.getElementById(currFeature+"_read");
		read.status=true;
		read.value="read >";
		document.getElementById(currFeature+"_text").style.display="none";
	}
	_hbPageView("view_feature",hbx.mlc);
	document.getElementById(id+"_text").style.display="block";
	currFeature=id;
}
function scrollToSection(id){
	var feature=document.getElementById(id);
	updateWindowSize();
	window.scrollTo(feature.offsetLeft-winWidth/2, feature.offsetTop-winHeight/2);
}
//
// copper nuggets
//
function setOpacity(obj, opacity){
	obj.style.filter = 'alpha(opacity=' + opacity+ ')';
	obj.style.opacity=opacity;
}
function initNuggets(){
	for(var i=0;i<10;i++){
		var nugget=document.getElementById("nugget"+i);
		//alert(i+": "+nugget);
		setOpacity(nugget, 0);
		//nugget.style.display="none";
		nugget.onmouseover=function(){
			_hbPageView("view_nugget",hbx.mlc);
			setOpacity(this, 100);
		}
		nugget.onmouseout=function(){
			setOpacity(this, 0);
		}
	}
}
function openLost(){
	updateWindowSize();
	var sw=screen.availWidth;
	var miniw=lostWidth;
	var minh=lostHeight;
	var isIe = document.all?true:false
	if(unearthWindow!=""){
		if(isIe){
			minh=screen.availHeight-unearthHeight-100;
		}else{
			minh=screen.availHeight-unearthWindow.outerHeight-(unearthWindow.outerHeight-unearthWindow.innerHeight);
		}
	}
	window.resizeBy((sw-miniw)-winWidth-10,0);
	updateWindowSize();
	var top=window.top;
	var left;
	if(isIe){
		left=sw-miniw;
	}else{
		left=browserWidth;
	}
	window.moveTo(0, window.top);
	if(lostWindow!=""){
		lostWindow.focus();
	}else{
		lostWindow=window.open("lost.html?random="+Math.random(), "lost", "scrollbars=1,toolbars=0,status=0,width="+miniw+", height="+minh+", resize=0, left="+left+", top="+top);
		lostWindow.focus();
	}
}
function openUnearth(){
	updateWindowSize();
	var sw=screen.availWidth;
	var miniw=unearthWidth;
	var minh=unearthHeight;
	var isIe = document.all?true:false
	if(lostWindow!=""){
		if(isIe){
			minh=screen.availHeight-lostHeight-100;
		}else{
			minh=screen.availHeight-lostWindow.outerHeight-(lostWindow.outerHeight-lostWindow.innerHeight);
		}
	}
	window.resizeBy((sw-miniw)-winWidth-10,0);
	updateWindowSize();
	var top=screen.availHeight-minh;
	var left;
	if(isIe){
		left=sw-miniw;
	}else{
		left=browserWidth;
	}
	window.moveTo(0, window.top);
	if(unearthWindow!=""){
		unearthWindow.focus();
	}else{
		unearthWindow=window.open("../unearth.html", "unearth", "scrollbars=1,toolbars=0,status=0,width="+miniw+", height="+minh+", resize=0, left="+left+", top="+top);
		unearthWindow.focus();
	}
}
function resizeWindow(){
	updateWindowSize();
	if(lostWindow==""&&unearthWindow==""){
		var sw=screen.availWidth;
		window.resizeBy(sw-winWidth-5,0);
	}
}
window.onbeforeunload=function(){
	if(unearthWindow){
		unearthWindow.close();
	}
	if(lostWindow){
		lostWindow.close();
	}
}
function showHistory(){
	_hbPageView("history",hbx.mlc);
	document.getElementById("history").style.display="block";
}
function hideHistory(){
	document.getElementById("history").style.display="none";
}
function showPuton(){
	document.getElementById("puton").style.display="block";
	document.getElementById("puton_frame").src="puton.html";
	document.getElementById("puton_posts_frame").src="../view_photos_px.asp?random="+Math.random()*99999;
	var expandPuton_btn=document.getElementById("expandPuton_btn");
	expandPuton_btn.value="<fold";
	expandPuton_btn.onmouseup=hidePuton;
}
function hidePuton(){
	document.getElementById("puton").style.display="none";
	document.getElementById("puton_frame").src="../black.html";
	document.getElementById("puton_posts_frame").src="../black.html";
	var expandPuton_btn=document.getElementById("expandPuton_btn");
	expandPuton_btn.value="expand>";
	expandPuton_btn.onmouseup=showPuton;
}
function showPublicNotes(){
	document.getElementById("public_messages").style.display="block";
	document.getElementById("bury_message").style.display="block";
	document.getElementById("notes_frame").src="../public_notes_px.asp?random="+Math.random()*99999;
	document.getElementById("bury_note_frame").src="../bury_note.html";
	if(hasPrivate){
		document.getElementById("private_message").style.display="block";
		document.getElementById("private_note_frame").src="../private_note_px.asp?key="+key+"&id="+id;
	}
	var uncover_btn=document.getElementById("uncover_btn");
	uncover_btn.value="<fold";
	uncover_btn.onmouseup=hidePublicNotes;
}
function hidePublicNotes(){
	document.getElementById("public_messages").style.display="none";
	document.getElementById("bury_message").style.display="none";
	document.getElementById("notes_frame").src="../white.html";
	document.getElementById("bury_note_frame").src="../white.html";
	if(hasPrivate){
		document.getElementById("private_message").style.display="none";
		document.getElementById("private_note_frame").src="../white.html";
	}
	var uncover_btn=document.getElementById("uncover_btn");
	uncover_btn.value="uncover>";
	uncover_btn.onmouseup=showPublicNotes;
}
function checkPrivateNote(){
	var params=document.location+""
	params=params.split("?");
	if(params.length<2){
		return;
	}
	params=params[1].split("&");
	for(var i=0;i<params.length;i++){
		var param_arr=params[i].split("=");
		if(param_arr[0].toLowerCase()=="key"){
			key=param_arr[1];
		}else if(param_arr[0].toLowerCase()=="id"){
			id=param_arr[1];
		}
	}
	if(key&&id){
		hasPrivate=true;
		showPrivateNote();
	}
}
function showPrivateNote(id,key){

	showPublicNotes();
	scrollToSection("public_messages");
}