var d = document;


/** BEGIN SET LINKS **/

function resetlinks() {

    d.getElementById('news').className = 'news';
    d.getElementById('faq').className = 'faq';
    d.getElementById('services').className = 'services';
    d.getElementById('aboutus').className = 'aboutus';
    d.getElementById('onlinecatalogs').className = 'onlinecatalogs';
    d.getElementById('contactinfo').className = 'contactinfo';
    // d.getElementById('teamsales').className = 'teamsales';
    d.getElementById('photogallery').className = 'photogallery';
    d.getElementById('specialoffers').className = 'specialoffers';

}

function setlink(link) {

  resetlinks();

  switch(link) {
    case 'aboutus':
    case 'news':
    case 'services':
    case 'onlinecatalogs':
    case 'faq':
    case 'contactinfo':
    case 'teamsales':
    case 'photogallery':
    case 'specialoffers':
      d.getElementById(link).className = link+'link';
      break;
  }

}

/** END SET LINKS **/


/** BEGIN PAGE LOADER **/

var openwindows = new Array();
var winclosed = new Array();

function newwin(place) {

  if (openwindows[place] && !openwindows[place].closed) {
    winclosed[place] = false;
  } else {
    winclosed[place] = true;
  }

  if (!winclosed[place]) {
    openwindows[place].focus();
  } else {
    openwindows[place] = window.open(place,'','');
  }

}

function switchpage(page) {

      frames['mainiframe'].location.href = page;
      // frames['mainiframe'].location.replace(page);

}

function goto(place,nw) {

  if (nw) {
    newwin(place);
  } else {
    switchpage(place+'.html');
    resizemain();
  }

}

/** END PAGE LOADER **/


/** BEGIN CONTENT SIZER **/

function getelementsize(hw, element) {

  switch(hw) {
    case 'h': // height
      return d.getElementById(element).scrollHeight;
      break;
    case 'w': // width
      return d.getElementById(element).scrollWidth;
      break;
  }

}

function resizemain() {

  var WidthPlusScrollbar = 0;
  var HeightPlusScrollbar = 0;

  innerHnum = getelementsize("h","logo") +
              getelementsize("h","spacer") +
              getelementsize("h","info") +
              getelementsize("h","footer") + 12;

  if (typeof window.innerWidth != "undefined") {
    WidthPlusScrollbar = window.innerWidth;
    HeightPlusScrollbar = window.innerHeight;
  }
  else if (d.documentElement && typeof d.documentElement.offsetWidth != "undefined" && d.documentElement.offsetWidth != 0) {
    WidthPlusScrollbar = d.documentElement.offsetWidth;
    HeightPlusScrollbar = d.documentElement.offsetHeight - 4;
  }
  else if (d.body && typeof d.body.offsetWidth != "undefined") {
    WidthPlusScrollbar = d.body.offsetWidth;
    HeightPlusScrollbar = d.body.offsetHeight;
  }

  newiframeheight = HeightPlusScrollbar - innerHnum;
  if (newiframeheight < 360) {
    d.getElementById('mainiframe').height = 360;
  }
  else {
    d.getElementById('mainiframe').height = newiframeheight;
  }

}

/** END CONTENT SIZER **/


/** BEGIN EASTER EGG **/

var clicks = 0;

function question() {

  switch(clicks) {
    case 0:
      alert("Easter Egg!");
      clicks++;
      break;
    case 1:
      alert("Ok, you've had your fun...");
      clicks++;
      break;
    case 2:
      alert("Are you done clicking me yet?");
      clicks++;
      break;
    case 3:
      alert("Ok, now you're starting to irritate me!");
      clicks++;
      break;
    case 4:
      alert("Come on... five times, really?!");
      clicks++;
      break;
    case 5:
      alert("Do you have OCD?");
      clicks++;
      break;
    case 6:
      alert("You must know Pavlov...");
      clicks++;
      break;
    case 7:
      alert("Now you're just being rude.");
      clicks++;
      break;
    case 8:
      alert("Ouch... that one hurt!!!");
      clicks++;
      break;
    case 9:
      alert("That's it, I'm going to ignore you now, but I tell you what: since you worked so hard to annoy... I mean find me, I'll give you 10% off your next order if you mention \"Easter Egg\" when you place it! (But, keep in mind... this is a one-time deal and can't be combined with any other offers.)");
      d.getElementById('question').style.visibility = 'hidden';
      clicks++;
      break;
    default:
      break;
  }

}

/** END EASTER EGG **/


/** BEGIN **/

function start(lock) {

  resetlinks();

  var gotoHASH = window.location.hash.replace(/#/, ''); // alert(gotoHASH);
  var gotoPAGE = 'intro';

/*
  var sURL = unescape(window.location);

  if (lock && (sURL != 'http://www.national-spe.com/')) {
    location.replace('http://www.national-spe.com/'+sHASH);
  }
*/

  var sURL  = window.location.href;
  var sHREF = window.location.href;
  var sHOST = window.location.hostname;
  var sHASH = window.location.hash;
  if (!(sHASH == '')) {
    sURL = sHREF.substring(0, sHREF.indexOf('#'));
  }
  // alert('HREF: '+sHREF+'\n\nHASH: '+sHASH+'\n\nURL: '+sURL);

  if (lock) {
    var badURL = true;
    switch(sURL) {
      case 'http://www.national-spe.com/?referrer=RunnersImage':
        gotoHASH = 'banners';
      case 'http://www.national-spe.com/':
      case 'http://localhost/':
        badURL = false;
        break;
    }
    if (badURL) {
      var goodHOST = 'www.national-spe.com';
      switch(sHOST) {
        case 'www.national-spe.com':
        case 'localhost':
          goodHOST = sHOST;
          break;
      }
      location.replace('http://'+goodHOST+'/'+sHASH);
    }
  }

  if (!(gotoHASH == '')) { gotoPAGE = gotoHASH; }

  goto(gotoPAGE);

/*
  ip = new ImagePreloader(image_url, onPreload);
  window.status = '';
*/

}

/** END **/

