﻿
/****************************************
*
*   navigation.js
*
****************************************/


/****************************************
*   Left Navigation
****************************************/



/* DOMOnLoad Helper - Start */

/* for Mozilla */
if (document.addEventListener) {
   document.addEventListener("DOMContentLoaded", registerCat, false);
}

// for Internet Explorer (using conditional comments)
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
    if (this.readyState == "complete") {
     registerCat(); // call the onload handler
     }
};
/*@end @*/


/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            clearInterval(_timer);
            registerCat(); // call the onload handler
        }
    }, 10);
}


// Helper to show open Categories soon after DOM is loaded
function registerCat()
{
    // quit if this function has already been called
    if (arguments.callee.done) 
        return;

    // flag this function so we don't do the same thing twice
    arguments.callee.done = true;
    
    if(document.cookie.indexOf("OpenCats=") != -1)
    {    
         menu_status = StringToArray();
         showSelected(menu_status);    
    }
    hideSelect();    
}

/* for other browsers */
WindowOnLoad(registerCat);




/* DOMOnLoad Helper - End */




// OnLoad Helper
function WindowOnLoad(OnLoadFunction)
{
	var CurrentOnLoad = (this.onload) ? this.onload : function () {};
		
	this.onload = function () {CurrentOnLoad(); OnLoadFunction(); resize(); MM_preloadImages(); selectTopNav()};
}


// Show/Hide Array
menu_status = new Array();

// If Category is expanded then hide and vice versa
function showHide(theid){
    if (document.getElementById) {        
        var switch_id = document.getElementById(theid);       
        if(menu_status[theid] != 'show') {
           switch_id.className = 'show';
           menu_status[theid] = 'show'; 
           for(var cat in menu_status)
           {
                if(cat != theid)
                {
                    switch_id = document.getElementById(cat);
                    switch_id.className = 'hide';
                    menu_status[cat] = 'hide';
                }                
           }          
        }
        else{
           switch_id.className = 'hide';
           menu_status[theid] = 'hide';
        }
        document.cookie = "OpenCats=" + ArrayToString(menu_status);              
    }        
}

// menu_status ToString to save in cookie 'OpenCats'
function ArrayToString (array)
{
    var string = "";
    for(var menu in array)
    {
        string += menu + ":" + array[menu] + ",";
    }
    string += ";";
    return string;
}

// Read from cookie 'OpenCats'
function StringToArray()
{
    var a = document.cookie;
    var OpenCats = "";
    var StartIndex = a.indexOf("OpenCats=") + 9;
    OpenCats = a.substring(StartIndex, a.length);
    OpenCats = OpenCats.substring(0, OpenCats.lastIndexOf(","));     
    
    var tmpArr = new Array();
        
    while(OpenCats != "")
    {	 
	    var MenuIndex = OpenCats.indexOf(":");
	    var ValueIndex = OpenCats.indexOf(",");
	    var menu = "";
	    var value = "";
	
	    if(ValueIndex == -1) {
		    menu = OpenCats.substring(0, MenuIndex);	    
		    value = OpenCats.substring(MenuIndex+1, OpenCats.length);
		    OpenCats = "";
	    }
	    else {
	    	menu = OpenCats.substring(0, MenuIndex);
	    	value = OpenCats.substring(MenuIndex+1, ValueIndex);
	    	OpenCats = OpenCats.substring(ValueIndex+1, OpenCats.length);  
	    }
						
	    tmpArr[menu] = value;	    	    	
    } 
    return tmpArr;       
}

// Show open Categories
function showSelected (menu_status)
{        
    for(var element in menu_status)
    {        
        if (document.getElementById)
        {
             var switch_id = document.getElementById(element);              
             switch_id.className = menu_status[element];                         
        }
    }
}




/****************************************
*   Top Navigation
****************************************/

function selectTopNav()
{        
    var path = window.location.href;
    var currPage = (path).slice(path.lastIndexOf("/")+1, path.lastIndexOf("."));       
    
    if(document.getElementById(currPage) != null)          
        document.getElementById(currPage).className = 'selected';                
}



/****************************************
*   Product Navigation
****************************************/
function resize()
{    
    if(document.getElementById("seleted") != null)
    {                                                        
        var img = document.Form1.initImg.value;        
        SelectImage(img, document.Form1.txtColorID.value);                          
    }   
}

function hideSelect()
{    
    if(document.getElementById("seleted") != null)
    {        
        if(document.Form1.txtColorID.value == "-1")
            document.getElementById("seleted").style.display = 'none';  
        else
            document.getElementById("seleted").style.display = 'block';                                   
    }       
}


/****************************************
*   History
****************************************/

function MM_preloadImages() { //v3.0
  var d=document;
  if(d.images)
  { if(!d.MM_p)
     d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
    for(i=0; i<a.length; i++)
      if (a[i].indexOf("#")!=0)
      { d.MM_p[j]=new Image;
        d.MM_p[j++].src=a[i];
      }
  }  
}

function MM_swapImgRestore(id) { //v3.0
  if(document.getElementById("c" + id.substring(5, id.length)).style.display == 'none')
    document.getElementById(id).src = 'images/history/' + id.substring(5, id.length) + '_off.png';
}

function MM_swapImage(id, imgArr) { 
  for(i=0; i<imgArr.length; i++)
  {          
     if(id == imgArr[i])
        document.getElementById(imgArr[i]).src = 'images/history/' + imgArr[i].substring(5, id.length) + '_on.png';
     else
        document.getElementById(imgArr[i]).src = 'images/history/' + imgArr[i].substring(5, id.length) + '_off.png';
  }
}

function MM_changeImage(id)
{
    document.getElementById(id).src = 'images/history/' + id.substring(5, id.length) + '_on.png';
}

function MM_showPanel(id) { 
  var i, century;
  var imgArr = new Array ("Image1600", "Image1700", "Image1800", "Image1900");
  var tmpArr = new Array ('c1600', 'c1700', 'c1800', 'c1900'); 
  MM_swapImage(id, imgArr); 
  id = "c" + id.substring(5, id.length);   
  document.getElementById(id).style.display = 'block';
  for(i=0;i<tmpArr.length;i++)
  {
     century = tmpArr[i] + "";     
     if(century != id)   
        document.getElementById(century).style.display = 'none';                 
  }   
}