var menus = new Array(2)
        menus[0] = "work";
        menus[1] = "company";

    var selectors = new Array(4)
        selectors[0] = "name";
        selectors[1] = "type";
        selectors[2] = "year";
        selectors[3] = "location";

    var types = new Array(5)
        types[0] = "theater";
        types[1] = "dance";
        types[2] = "video";
        types[3] = "performance";
        types[4] = "installation";

    var locations = new Array(2)
        locations[0] = "newyork";
        locations[1] = "mass";
        
    var years = new Array (8)
        years[0] = "ohTen";
        years[1] = "ohNine";
        years[2] = "ohEight";
        years[3] = "ohSeven";
        years[4] = "ohSix";
        years[5] = "ohFive";
        years[6] = "ohFour";
        years[7] = "ohThree";

    function show(id) {
       var menuname = document.getElementById(id);
       if(menuname.style.display == 'none')
          menuname.style.display = 'block';
    }

    function hide(id) {
       var menuname = document.getElementById(id);
       if(menuname.style.display == 'block')
          menuname.style.display = 'none';
    }

      function resetHome() {    
        for(x = 0; x < menus.length; x++) {
          hide(menus[x]);
        }
        hideSelectors();
        hideTypes();
        hideYears();
        hideLocations();
        clearCookies();
      }

    function hideSelectors() {    
        for(x = 0; x < selectors.length; x++) {
          hide(selectors[x]);
          document.getElementById(selectors[x] + 'link').style.border = "none";
          document.getElementById(selectors[x] + 'rule').style.borderBottom = "none";
        }
    }

    function hideTypes() {    
        for(x = 0; x < types.length; x++) {
          hide(types[x]);
          document.getElementById(types[x] + 'link').style.border = "none";
          document.getElementById(types[x] + 'rule').style.borderBottom = "none";
        }
    }

    function hideYears() {    
        for(x = 0; x < years.length; x++) {
          hide(years[x]);
          document.getElementById(years[x] + 'link').style.border = "none";
          document.getElementById(years[x] + 'rule').style.borderBottom = "none";
        }
    }

    function hideLocations() {    
        for(x = 0; x < locations.length; x++) {
          hide(locations[x]);
          document.getElementById(locations[x] + 'link').style.border = "none";
          document.getElementById(locations[x] + 'rule').style.borderBottom = "none";
        }
    }

    function showSub(id) {
       resetHome();
       show(id);
       dash(id);
       createCookie('m1',id,1);
    }

    function showType(id) {
        hideTypes();
        dash(id);
        show(id);
        createCookie('m3',id,1);
    }

    function showYear(id) {
        hideYears();
        dash(id);
        show(id);
        createCookie('m3',id,1);
    }

    function showLocation(id) {
        hideLocations();
        dash(id);
        show(id);
        createCookie('m3',id,1);
    }

   function showSelector(id) {
       hideTypes();
       hideYears();
       hideLocations();
       hideSelectors();
       dash(id);
       show(id);
       eraseCookie('m3');
       eraseCookie('m4');
       createCookie('m2',id,1);
    }
   
   function dash(id) {
          for(x = 0; x < menus.length; x++) {
            if (menus[x]==id) {
              for(i = 0; i < menus.length; i++) {
                document.getElementById(menus[i] + 'link').style.border = "none";
                document.getElementById(menus[i] + 'rule').style.borderBottom = "none";
              }
              document.getElementById(id + 'link').style.border = "1px dashed #fff";
              document.getElementById(id + 'rule').style.borderBottom = "1px dashed #fff";
            }
          }
          for(x = 0; x < selectors.length; x++) {
            if (selectors[x]==id) {
              for(i = 0; i < selectors.length; i++) {
                document.getElementById(selectors[i] + 'link').style.border = "none";
                document.getElementById(selectors[i] + 'rule').style.borderBottom = "none";
              }
              document.getElementById(id + 'link').style.border = "1px dashed #fff";
              document.getElementById(id + 'rule').style.borderBottom = "1px dashed #fff";
            }
          }  
          for(x = 0; x < types.length; x++) {
           if (types[x]==id) {
             for(i = 0; i < types.length; i++) {
               document.getElementById(types[i] + 'link').style.border = "none";
               document.getElementById(types[i] + 'rule').style.borderBottom = "none";
             }
             document.getElementById(id + 'link').style.border = "1px dashed #fff";
             document.getElementById(id + 'rule').style.borderBottom = "1px dashed #fff";
           }  
          }
          for(x = 0; x < years.length; x++) {
            if (years[x]==id) {
              for(i = 0; i < years.length; i++) {
                document.getElementById(years[i] + 'link').style.border = "none";
                document.getElementById(years[i] + 'rule').style.borderBottom = "none";
              }
              document.getElementById(id + 'link').style.border = "1px dashed #fff";
              document.getElementById(id + 'rule').style.borderBottom = "1px dashed #fff";
            }
          }
          for(x = 0; x < locations.length; x++) {
            if (locations[x]==id) {
              for(i = 0; i < locations.length; i++) {
                document.getElementById(locations[i] + 'link').style.border = "none";
                document.getElementById(locations[i] + 'rule').style.borderBottom = "none";
              }
              document.getElementById(id + 'link').style.border = "1px dashed #fff";
              document.getElementById(id + 'rule').style.borderBottom = "1px dashed #fff";
            }
          }       
   }

   function topDash(id) {
      document.getElementById(id + 'link').style.border = "1px dashed #fff";
      document.getElementById(id + 'rule').style.borderBottom = "1px dashed #fff";
      document.getElementById(id + 'vertrule').style.borderRight = "1px dashed #fff";
   }

   function dashpagenav(id) {
       document.getElementById('imageslink').style.border = "none";
       document.getElementById('descriptionlink').style.border = "none";
       document.getElementById('creditslink').style.border = "none";
       document.getElementById('presslink').style.border = "none";
       document.getElementById('videoslink').style.border = "none";
       document.getElementById(id + 'link').style.border = "1px dashed #fff";
   }

   function showPageLayer(id) {
      hide('images');
      hide('description');
      hide('credits');
      hide('press');
      hide('videos');
      dashpagenav(id);
      show(id);
   }

// Cookie Handler
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


function showMenu(menu) {
    var menuone = readCookie(menu);
    if(menuone) {
       if(menu=='m4') {
	  document.getElementById(menuone).style.border = "1px dashed #fff";
       }
       else {
          show(menuone);
          dash(menuone);	
       };
    }
}

function settopnav(id) {
	eraseCookie('m1');
        eraseCookie('m2');
        eraseCookie('m3');
        eraseCookie('m4');
        createCookie('top',id,1);
}

function showtopnav() {
        var topvalue = readCookie('top');
        if(topvalue) {
	   topDash(topvalue);
        }
        else {
	   topDash('new');
        };
}

function dashlink(id) {
   var linkvalue = readCookie('m4');
   if(linkvalue) {
	document.getElementById(linkvalue).style.border = "none";
   };
   document.getElementById(id).style.border = "1px dashed #fff";
   eraseCookie('top');
   createCookie('m4',id,1);
}

function testCookie(m1,m2,m3,m4,top) {
        var menuonevalue = readCookie(m1);
        var menutwovalue = readCookie(m2);
        var menuthreevalue = readCookie(m3);
        var menufourvalue = readCookie(m4);
        var topvalue = readCookie(top)
        alert('The value of ' + m1 + ' is ' + menuonevalue + '.\nThe value of ' + m2 + ' is ' + menutwovalue + '.\nThe value of ' + m3 + ' is ' + menuthreevalue + '.\nThe value of ' + m4 + ' is ' + menufourvalue + '.\nThe value of ' + top + ' is ' + topvalue + '.');
}

function clearCookies() {
	eraseCookie('m1');
        eraseCookie('m2');
        eraseCookie('m3');
        eraseCookie('m4');
        eraseCookie('top');
}

function newUser() {
        if(document.referrer.indexOf('immediatemedium.org') == -1) {
	   clearCookies()
        }
}

function showStore(id) {
	resetHome();
        document.getElementById('worklink').style.border = "none";
        document.getElementById('workrule').style.border = "none";
        document.getElementById('companylink').style.border = "none";
        document.getElementById('companyrule').style.border = "none";
        dashlink(id);
}