function initSubNav(){
	if (document.getElementById){
	//turns current subnav item on except on homepage
		if (document.getElementById('subnav')){
			var subnav = document.getElementById('subnav');  	//finds subnav element
			var subnavas = subnav.getElementsByTagName('a'); 	//finds all anchors within subnav
			for (var a=0; a<subnavas.length; a++){		//cycles through each link
				var currenthref=String(subnavas[a].href);	//assigns current link href to a string
				var currentloc=String(document.location);	//assigns current document url to a string
			
				//if the current link href matches the document url the anchor is given a class
				if (unescape(currenthref)==unescape(currentloc)){
					subnavas[a].className="hi"
				}
			}
	  	}
	}
if (document.getElementById('bodyuse')) {initUse(), createRequestObject()};
if (document.getElementById('bodyindustry')) {initIndustry(), createRequestObject()};
if (document.getElementById('previous')) {initPrevNext(), initCat()};
if (document.getElementById('publication')) Pub();
}

function addAnEvent( target, eventName, functionName){
        eval('target.on'+eventName+'=functionName');
}

function byLinks(){
	if (document.getElementById('subnav')){
		var ulink = document.getElementById('byuse');
		addAnEvent(ulink,'click',initUse);
	}

	if (document.getElementById('subnav')){
		var ilink = document.getElementById('byindustry');
		addAnEvent(ilink,'click',initIndustry);
	}
	
}


// This finds on links and turns them off
function onSwitch(){
	var findon=document.getElementsByTagName("a");
	var linkon;
	for(var i=0;i<findon.length;i++){
		linkon = findon[i];
		if(linkon.className == "on"){
			linkon.className = "off";
		}
	}
}

//===========================================

function createRequestObject() {
  FORM_DATA = new Object();
    // The Object ("Array") where our data will be stored.
  separator = ',';
    // The token used to separate data from multi-select inputs
  query = '' + this.location;
  qu = query
    // Get the current URL so we can parse out the data.
    // Adding a null-string '' forces an implicit type cast
    // from property to string, for NS2 compatibility.
  query = query.substring((query.indexOf('?')) + 1);
    // Keep everything after the question mark '?'.
  if (query.length < 1) { return false; }  // Perhaps we got some bad data?
  keypairs = new Object();
  numKP = 1;
    // Local vars used to store and keep track of name/value pairs
    // as we parse them back into a usable form.
  while (query.indexOf('&') > -1) {
    keypairs[numKP] = query.substring(0,query.indexOf('&'));
    query = query.substring((query.indexOf('&')) + 1);
    numKP++;
      // Split the query string at each '&', storing the left-hand side
      // of the split in a new keypairs[] holder, and chopping the query
      // so that it gets the value of the right-hand string.
  }
  keypairs[numKP] = query;
    // Store what's left in the query string as the final keypairs[] data.<
  for (i in keypairs) {
    keyName = keypairs[i].substring(0,keypairs[i].indexOf('='));
      // Left of '=' is name.
    keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1);
      // Right of '=' is value.
    while (keyValue.indexOf('+') > -1) {
      keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1);
        // Replace each '+' in data string with a space.
    }
    keyValue = unescape(keyValue);
      // Unescape non-alphanumerics
    if (FORM_DATA[keyName]) {
      FORM_DATA[keyName] = FORM_DATA[keyName] + separator + keyValue;
        // Object already exists, it is probably a multi-select input,
        // and we need to generate a separator-delimited string
        // by appending to what we already have stored.
    } else {
      FORM_DATA[keyName] = keyValue;
        // Normal case: name gets value.
    }
  }
  return FORM_DATA;
}
FORM_DATA = createRequestObject();
  // This is the array/object containing the GET data.
  // Retrieve information with 'FORM_DATA [ key ] = value'.


//===========================================


function initCat(){
		var thiscat = FORM_DATA['cat'];
		if (thiscat == "retailers"){
	var use = document.getElementById('use');
	var ind = document.getElementById('industry');
	use.className = 'none';
	ind.className = 'block';
	onSwitch();
	document.getElementById('byindustry').className = 'on';
		}
		if (thiscat == "foodspirit"){
	var use = document.getElementById('use');
	var ind = document.getElementById('industry');
	use.className = 'none';
	ind.className = 'block';
	onSwitch();
	document.getElementById('byindustry').className = 'on';
		}
		if (thiscat == "hospitality"){
	var use = document.getElementById('use');
	var ind = document.getElementById('industry');
	use.className = 'none';
	ind.className = 'block';
	onSwitch();
	document.getElementById('byindustry').className = 'on';
		}
		if (thiscat == "consumer"){
	var use = document.getElementById('use');
	var ind = document.getElementById('industry');
	use.className = 'none';
	ind.className = 'block';
	onSwitch();
	document.getElementById('byindustry').className = 'on';
		}
		if (thiscat == "cultural"){
	var use = document.getElementById('use');
	var ind = document.getElementById('industry');
	use.className = 'none';
	ind.className = 'block';
	onSwitch();	
	document.getElementById('byindustry').className = 'on';
		}
		if (thiscat == "anniversaries"){
	var use = document.getElementById('use');
	var ind = document.getElementById('industry');
	use.className = 'none';
	ind.className = 'block';
	onSwitch();
	document.getElementById('byindustry').className = 'on';
		}
		if (thiscat == "entertainment"){
	var use = document.getElementById('use');
	var ind = document.getElementById('industry');
	use.className = 'none';
	ind.className = 'block';
	onSwitch();
	document.getElementById('byindustry').className = 'on';
		}
}


function initUse(){
	if (document.getElementById('subnav')){
		var use = document.getElementById('use');
		var ind = document.getElementById('industry');
		use.className = 'block';
		ind.className = 'none';
		onSwitch();
		on = document.getElementById('byuse');
  		on.className = "on";
	}
}

function initIndustry(){
	if (document.getElementById('subnav')){
	var use = document.getElementById('use');
	var ind = document.getElementById('industry');
	use.className = 'none';
	ind.className = 'block';
	onSwitch();
	on = document.getElementById('byindustry');
  	on.className = "on";
	}
}




document.getElementsByClassName = function(clsName){
    var retVal = new Array();
    var elements = document.getElementsByTagName("*");
    for(var i = 0;i < elements.length;i++){
        if(elements[i].className.indexOf(" ") >= 0){
            var classes = elements[i].className.split(" ");
            for(var j = 0;j < classes.length;j++){
                if(classes[j] == clsName)
                    retVal.push(elements[i]);
            }
        }
        else if(elements[i].className == clsName)
            retVal.push(elements[i]);
    }
    return retVal;
}


window.onload = initSubNav;