



function e(id)
{
	return document.getElementById(id)?document.getElementById(id):false;
}

// HEADER IMAGE  ---------------------------------------------------------------------------

function setRandomHeadImage(){
	var total_images = 27;
	var pic_num = Math.round((Math.random() * (total_images - 1 ))) + 1;
	if (pic_num >=1 && pic_num <= total_images) {
		pic_num = String(pic_num);
		if (pic_num.length == 1){
			pic_num = "0" + pic_num;
		}	
		if (e("header-image")){
			e("header-image").src = "/images/header_images/STY_pic_"+pic_num+".jpg"
		}
	}
}

// NAV FUNCTIONS ---------------------------------------------------------------------------


var nav_class_array = [];
var footer_class_array = [];
var out_timeout = 0;
var locked_open_nav_ele = -1;




function onMainNavOver( num , if_true , from_user, is_sub){
	
	self.clearTimeout(out_timeout);
	
	if (from_user && (!if_true)){
		 out_timeout = self.setTimeout("onMainNavOver('"+num+"' , false, false)", 1000) ; 
		 return;
	}

	if (if_true){
		resetNav("main");
		activateNav(num,"main", false, is_sub);
	} else {
		resetNav("main");
	}
}


function lockOpenSubNav(nav_ele){
	locked_open_nav_ele = nav_ele
	onMainNavOver(locked_open_nav_ele, true, true);	
}



function onFooterNavOver(num , if_true){
	
	if (if_true){
		activateNav(num,"footer");
	} else {
		resetNav("footer");
	}

}
var total_main_ids = "-";
var total_footer_ids = "-";
function activateNav(num , mode_str, init_only, is_sub , total_ids){
	
	if (mode_str == "main"){
		//var total_ids = 3;		
		if (total_main_ids == "-"){
			total_main_ids = total_ids;
			for (var g = 0 ; g < total_main_ids ; g++){
				nav_class_array[g] = "-";
			}
			
			
		} else {
			total_ids = total_main_ids ;
			
		}
		var id_prefix = "nav_";
		var subnav = true;
		var on_class = "nav-cell-on";
		var off_class = "nav-cell-off";
		var class_array = nav_class_array;
					
	} else if (mode_str == "footer"){
	
		if (total_footer_ids == "-"){
			total_footer_ids = total_ids;
			for (var g = 0 ; g < total_footer_ids ; g++){
				footer_class_array[g] = "-";
			}
			
		} else {
			total_ids = total_footer_ids ;
		
		}
		
		//var total_ids = 5;
		var id_prefix = "footer_nav_";
		var subnav = false;
		var on_class = "footer-nav-on";
		var off_class = "footer-nav-off";
		var class_array = footer_class_array;
	}
	
	if (num == "-"){
		return;
	}
	
	for (var  k = 0 ; k < total_ids ; k++){
		
		if (e(id_prefix+ String(k))){

				if ((!init_only)&&String(class_array[k] ) == "-" ){
					class_array[k] = e(id_prefix + String(k)).className
				} 
				
			if ( Number(num) == k){
			
				e(id_prefix + String(k)).className=on_class;
				
				if ((!init_only) && subnav){
					if (e("subnav_" + String(k))){
						e("subnav_" + String(k)).style.display  = "";
						
						if (is_sub){
							//e("subnav_" + String(k)).className = "sub-nav-table-on";
						}
						
					} 
				}
				
			} else {
			
				if ((!init_only) && subnav){
					if (e("subnav_" + String(k))){
						e("subnav_" + String(k)).style.display  = "none";
						e("subnav_" + String(k)).className = "sub-nav-table";
					} 
				}
				
				e(id_prefix + String(k)).className=off_class;
			}
		}
	}
}


function resetNav(mode_str){
	if (mode_str == "main"){
		var total_ids = total_main_ids;
		var id_prefix = "nav_";
		var subnav = true;
		var on_class = "nav-cell-on";
		var class_array = nav_class_array;
	} else if (mode_str == "footer"){
		var total_ids = total_footer_ids;
		var id_prefix = "footer_nav_";
		var subnav = false;
		var on_class = "footer-nav-on";
		
		var class_array = footer_class_array;
	}
	////////////////////////////////////////////////////////////////////////////////////
	for (var  k = 0 ; k < total_ids ; k++){
		if (e(id_prefix + String(k))){
			if (String(class_array[k] ) != "-" ){
				if (subnav){
					if (e("subnav_" + String(k))){						
						//if (class_array[k-1] == on_class){
						if (String(locked_open_nav_ele) != String(k)){
							e("subnav_" + String(k)).style.display = "none";
						}
						//} else {
						//	e("subnav_" + String(k)).style.display = "none"; 
						//}
						//	e("subnav_" + String(k)).className = "sub-nav-table";
					} 
				}
				e(id_prefix + String(k)).className = class_array[k];
			}
		}
	}
	if (locked_open_nav_ele > -1){
		if (mode_str == "main"){
			e("subnav_" + String(locked_open_nav_ele)).style.display = "";
		}
	}
}

// PRODUCT LINK ---------------------------------------------------------------------------

function rollProductLink(num , is_over){
	if (e("prod_link_" + num)){
		if (is_over){
			e("prod_link_" + num).style.textDecoration = "underline";
		} else {
			e("prod_link_" + num).style.textDecoration = "";
		}
	}
}

// RANGE PRODUCT LINK ---------------------------------------------------------------------------

range_out_timeout =  "";
roll_out_range_num = "1"
function rollRangeProductLink(num , is_over, self_called){

	
	self.clearTimeout(range_out_timeout);
	
	

	if (e("prod_link_" + num)){
		if (is_over){
			rollRangeProductLink(roll_out_range_num , false, true);
		
			e("prod_link_" + num).style.textDecoration = "underline";
			
			if (e("prod_link_" + num)){
				if (e("product_title")){
					e("product_title").innerHTML = e("prod_link_" + num).innerHTML;
				}
			}
			
			if (e("product_text_" + num)){
				if (e("product_text")){
					e("product_text").innerHTML = e("product_text_" + num).innerHTML;
				}
			}		
			
			if (e("info_table")){
				e("info_table").style.display = "";
			}
		} else {
			if (!self_called){
				roll_out_range_num = num;
				range_out_timeout = self.setTimeout("rollRangeProductLink('"+num+"' , false, true)", 100) ; 
			} else {
				e("prod_link_" + num).style.textDecoration = "";
				if (e("info_table")){
					e("info_table").style.display = "none";
				}
			}
		}
	}
}

function onShapeChange(obj){
		if (obj){
			var int_index = obj.selectedIndex;
			var str_shape_value = obj.options[int_index].value;
			var int_size_len = obj.options.length;
			// turn off all 2ndary combos
			for (var j = 0 ; j <=int_size_len ; j++){
				if(e("size_select_" + j)){ 
					e("size_select_" + j).options[0].selected = true;
					e("size_select_" + j).style.display = "none";
				}
			}
			// switch the correct combo on 
			if(e("size_select_" + int_index)){		
				e("size_select_" + int_index).style.display = "";
				e("spa_size").value = e("size_select_" + int_index).value;
			}

			if (int_index == 0){
				// Show all shapes as a guide
				if (e("all_sizes_table")){
					e("all_sizes_table").style.display = "";
				}		
				if (e("size_diagram_table")){
					e("size_diagram_table").style.display = "none";
				}	
			} else {
				// Show the size diagram for this shape.
				if (e("all_sizes_table")){
					e("all_sizes_table").style.display = "none";
				}		
				if (e("size_diagram_table")){
					e("size_diagram_table").style.display = "";
				}
				// Hide all image diagrams
				for (var s = 1 ; s <= int_size_len ; s++){
					if (e("size_diagram_" + s)){
						e("size_diagram_" + s).style.display = "none";						
					} 
				}
				// Show the appropriate one.
				if (e("size_diagram_" + int_index)){
					e("size_diagram_" + int_index).style.display = ""
					
				}

			}			
		}	
}

function combonav(combo)
{
	
	var val = e(combo).value;
	//alert(val);
	if(val!='')
	{	
		
		document.location = val;
	}
}
