// EAN

function menu_control(){
	
	var menu = document.getElementById("promo_submenu");
	var nbOptions = menu.childNodes.length;
	
	var logo = document.getElementById("brand_logo");
	
	//default
	setButtonActive(menu,"visible");
	
	//---create the download link by default
	var content = document.getElementById("promo_content");
	var txt = document.createTextNode("Download Rebate Forms");
	var downloadLink = document.createElement("a");
	downloadLink.appendChild(txt);
	downloadLink.href="documents/REBATES_FORMS/SUPRE REBATE FORMS.pdf";
	downloadLink.style.position = "absolute";
	downloadLink.style.textDecoration = "underline";
	downloadLink.style.width = "200px";
	downloadLink.style.color = "#FF6600";
	downloadLink.style.top = "130px";
	downloadLink.style.left = "550px";
		//open the link in a separate window
		downloadLink.target ="_blank";
	content.appendChild(downloadLink);
	
	
	for(var i = 0 ; i < nbOptions ; i++){
		
		menu.childNodes[i].onmouseover = function(){
			this.style.cursor = "pointer";	
			this.style.backgroundColor = "#3D1101";
			this.style.color = "#F6F4DF";
		}
		
		menu.childNodes[i].onmouseout = function(){
			
			if(!isActive( this , "visible" )){
				this.style.cursor = "default";	
				this.style.backgroundColor = "#E5E3CE";
				this.style.color = "#3D1101";
			}
		}
		
		menu.childNodes[i].onclick = function(){
			var theSection = getSection(this);	
			setEverybodyClass(menu,"visible", "invisible", theSection);
			
			
			switch(this.getAttribute("id")){
				case"Promotions_supre":				logo.src ="IMAGES/img_promotions/LOGO_supre.gif";
													if(downloadLink.style.visibility == "hidden"){
														downloadLink.style.visibility = "visible";
													}
													break;
													
													
				case"Promotions_skinScience":		logo.src ="IMAGES/img_promotions/LOGO_skinScience.gif";	
													if(downloadLink.style.visibility == "hidden"){
														downloadLink.style.visibility = "visible";
													}
													downloadLink.href="documents/REBATES_FORMS/Skinscience Rebate Catalog WEB.pdf";
													break;
				
				
				case"Promotions_fijiBlends":		logo.src ="IMAGES/img_promotions/LOGO_fijiBlend.gif";	
													downloadLink.style.visibility = "hidden";
													break;
													
													
				case"Promotions_devotedCreations":	logo.src ="IMAGES/img_promotions/LOGO_devotedCreations.gif";
													downloadLink.style.visibility = "hidden";
													break;
													
													
													
													
				case"Promotions_performanceBrands":	logo.src ="IMAGES/img_promotions/LOGO_performanceBrends.gif";
													if(downloadLink.style.visibility == "hidden"){
														downloadLink.style.visibility = "visible";
													}
													downloadLink.href="documents/REBATES_FORMS/PERFORMANCE BRANDS Rebate Forms.pdf";
													break;
			}
			
			//open the link in a separate window
			downloadLink.target ="_blank";
			
			setButtonActive(menu,"visible");
			cleanUp(menu,"invisible", "#3D1101", "#E5E3CE");
		}
	}
}




//--------------
function setEverybodyClass(coll, good, bad, restrict){
	
	restrict.className = good;
	
	
	for(var i = 0 ; i < coll.childNodes.length ; i++){
		
		var section_btn = getSection(coll.childNodes[i]);
			if( section_btn!= restrict )
			section_btn.className = bad;
	}
}


//--------------
function getSection(obj){
	var id = obj.getAttribute("id");
	var id_pure = id.substring(11);
	
	return document.getElementById("content_"+ id_pure);
}



//set button active
function setButtonActive(coll, good){
	
//	for(var i = 0 ; i < coll.childNodes.length ; i++){
		
		for(var i = 0 ; i < coll.childNodes.length ; i++){
			
			var section_btn = getSection(coll.childNodes[i]);
			if(section_btn.className == good){
				//alert(section_btn.getAttribute("id"));
				coll.childNodes[i].style.backgroundColor = "#3D1101";
				coll.childNodes[i].style.color = "#F6F4DF";
				
				//alert(coll.childNodes[i].style.color);
			}
	}
}


function cleanUp(coll, bad, color, bgColor){
	
	for(var i = 0 ; i < coll.childNodes.length ; i++){
	
		var section_btn = getSection(coll.childNodes[i]);
		if(section_btn.className == bad){
			coll.childNodes[i].style.color = color;
			coll.childNodes[i].style.backgroundColor = bgColor;
		}
	}
}



function isActive(btn, good){
	var section_btn = getSection( btn );
	
	return section_btn.className == good ? true : false;
}



