var removeNav;
var putNavBack;

function removeSubNav(elementName){
	if($(elementName).style.display != "none"){
		$(elementName).style.display = "none";
		$(elementName).setAttribute("style", "display: none;");
	}
}

function displaySubNav(elementName){
	$(elementName).style.display = "";
	$(elementName).setAttribute("style", "display: inline;");
}

function callSWF(){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="898" height="368" id="index" align="middle"> <param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="mainpic08.swf"/> <param name="quality" value="high" /> <param name="bgcolor" value="#ffffff" /> <embed src="mainpic08.swf" quality="high" bgcolor="#ffffff" width="898" height="368" name="index" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object>');
}

function show_hide_description(getSpans, whatClass){
	for(x=0; x < getSpans.length; x++){
		if(getSpans[x].getAttribute("class") == whatClass || getSpans[x].getAttribute("className") == whatClass){
			if(getSpans[x].style.display != "none"){
				getSpans[x].setAttribute("style", "display: none");
				getSpans[x].style.display = "none";
			}
			else{
				getSpans[x].setAttribute("style", "display: inline");
				getSpans[x].style.display = "inline";
			}
		} else {
			getSpans[x].setAttribute("style", "display: none");
			getSpans[x].style.display = "none";
		}
	}

}

window.onload = function(){

	//#################################################################################
		//COLLECTIONS SUB NAV
		$("nav_collections").onmouseover = function(){
			window.clearInterval(removeNav);
			window.clearInterval(putNavBack);

			//first make sure that the woo me isn't displayed
			removeSubNav("sub_nav_woome");
			removeSubNav("sub_nav_shop");

			//now display the subnav
			displaySubNav("sub_nav_collections");
		}

 
		$("nav_collections").onmouseout = function(){
			//only remove the nav if its NOT a collections page
			if(!$("collections-page")){
				removeNav = window.setInterval("removeSubNav('sub_nav_collections')",2*1000);
			}

			//if its a woo me page, put it back
			if($("register-page") || $("desktops-page") || $("recommends-page")){
				putNavBack = window.setInterval("displaySubNav('sub_nav_woome');",2*1000);
			}
		}

		//WOO ME SUB NAV
		$("nav_woome").onmouseover = function(){
			window.clearInterval(removeNav);
			window.clearInterval(putNavBack);

			//first make sure that the collections aren't displayed
			removeSubNav("sub_nav_collections");
			removeSubNav("sub_nav_shop");

			//now display the subnav
			displaySubNav("sub_nav_woome");
		}

		$("nav_woome").onmouseout = function(){
			//only remove the nav if its NOT a woo me page
			if(!$("register-page") && !$("desktops-page") && !$("recommends-page")){
				removeNav = window.setInterval("removeSubNav('sub_nav_woome')",2*1000);
			}

			//if its a collections page, put the nav back
			if($("collections-page")){
				putNavBack = window.setInterval("displaySubNav('sub_nav_collections');",2*1000);
			}
		}
		//SHOP SUB NAV
		$("nav_shop").onmouseover = function(){
			window.clearInterval(removeNav);
			window.clearInterval(putNavBack);

			//first make sure that the collections aren't displayed
			removeSubNav("sub_nav_collections");
			removeSubNav("sub_nav_woome");

			//now display the subnav
			displaySubNav("sub_nav_shop");
		}

		$("nav_shop").onmouseout = function(){
			//only remove the nav if its NOT a woo me page
			if(!$("register-page") && !$("desktops-page") && !$("recommends-page")){
				removeNav = window.setInterval("removeSubNav('sub_nav_shop')",2*1000);
			}

			//if its a collections page, put the nav back
			if($("collections-page")){
				putNavBack = window.setInterval("displaySubNav('sub_nav_collections');",2*1000);
			}
		}
	//#################################################################################

	//COLLECTIONS LARGE IMAGE POP UP WINDOW
	if($("collectionMainPhotoLink")){
		$("collectionMainPhotoLink").onclick = function(){
			window.open($("collectionMainPhotoLink").getAttribute("href"), "largePhoto", "status=0, toolbar=0, width=500, height=700");
			return false;
		}
	}
	
	//PRESS PAGE THUMBNAILS
	if($("pressListing")){
		var pageLinks = document.getElementsByTagName("a");

		for(var i=0; i < pageLinks.length; i++){
			if(pageLinks[i].getAttribute("class") == "pressLink" || pageLinks[i].getAttribute("className") == "pressLink"){
				pageLinks[i].onclick = function(){
					window.open(this.getAttribute("href"), "tearsheet", "status=0, toolbar=0, resizable=1, scrollbars=1, width=570, height=750");
					return false;
				}
			}
		}
	}
	
	if($("clientSection")){
		$("goToClientCollection").onchange = function(){
			window.location = $("goToClientCollection").value;
		}
	}
	
	if($("recommends-page")){
		$("design_dropper").onclick = function(){
			show_hide_description(document.getElementsByTagName("span"), "design_desc");
			return false;
		}
		$("misc_dropper").onclick = function(){
			show_hide_description(document.getElementsByTagName("span"), "misc_desc");
			return false;
		}
		$("fashion_dropper").onclick = function(){
			show_hide_description(document.getElementsByTagName("span"), "fashion_desc");
			return false;
		}
		$("photography_dropper").onclick = function(){
			show_hide_description(document.getElementsByTagName("span"), "photography_desc");
			return false;
		}
		$("travel_dropper").onclick = function(){
			show_hide_description(document.getElementsByTagName("span"), "travel_desc");
			return false;
		}
		$("models_dropper").onclick = function(){
			show_hide_description(document.getElementsByTagName("span"), "models_desc");
			return false;
		}
		$("diamonds_dropper").onclick = function(){
			show_hide_description(document.getElementsByTagName("span"), "diamonds_desc");
			return false;
		}
	}
}