var d = document;
var site_domain = "harmonyam.com";

/* Prevent flickering images in IE: www.mister-pixel.com */
try {
  document.execCommand('BackgroundImageCache', false, true);
} catch(err) {}

/* MOUSEOVER CREATION AND PRELOAD SCRIPT */

addEvent(window,'load',function() { createMouseovers() },false);

var overExt = "_ON";

function assignImageSrcs(img) {
  if (img.src) {
    var dotAt = img.src.lastIndexOf(".");
    if (dotAt > 0) {
      var imgName = img.src.substr(0, dotAt);
      var imgExt  = img.src.substr(dotAt+1);
      if (imgName.lastIndexOf(overExt) == imgName.length - overExt.length) {
        // image is already in over state
        }
      else {
        // save original image src (as outSrc) and all other generated sources to image
        img.outSrc  = img.src;
        img.overSrc = imgName + overExt + "." + imgExt;
        }
      }
    }
  }

function applyMouseoverEvents(img) {
  eval("img.onmouseover = function () {this.src = this.overSrc};");
  eval("img.onmouseout = function () {this.src = this.outSrc};");
  }

function createMouseovers() {
  var imgs = getElementsByClass("mouseover",document,"IMG")
  for (var i = 0; i < imgs.length; i++) {
    assignImageSrcs(imgs[i]);
    if (imgs[i].outSrc && imgs[i].overSrc) {
      // create mouseover actions & do preloads
      applyMouseoverEvents(imgs[i]);
      preloadImages(imgs[i].onSrc);
      }
    }
  }

// Accept any number of image sources for preloadings (separate with commas)
function preloadImages() {
  if (document.images) {
    if (!document.preloads)
      document.preloads = new Array();
    var i, j, p = document.preloads.length, a = preloadImages.arguments;
    // Check to see if the preload already exists in the array, and if so, exit function
    for (i=0; i<p; i++) {
      for (j=0; j<a.length; j++) {
        if (document.preloads[i].src == a[j])
          return;
        }
      }
    // Add preload to array
    for (j=0; j<a.length; j++) {
      document.preloads[p]       = new Image;
      document.preloads[p++].src = a[j];
      }
    }
  }

/* EMAIL OUTPUT FUNCTIONS */

// Writes out the opening tag for an email link in the form <a href="mailto:me@domain.com">
function writeEmailLinkOpenTag(addressee, domain, subject, linkCodePrepend, linkCodeAppend) {
  if (writeEmailLinkOpenTag.arguments.length < 2 || domain == "" || domain == null)
    domain = site_domain;
  var emailAddress = addressee + "@" + domain;
  if (writeEmailLinkOpenTag.arguments.length < 3 || subject == null)
    subject = "Inquiry from " + site_domain;
  if (writeEmailLinkOpenTag.arguments.length < 4 || linkCodePrepend == null)
    linkCodePrepend = "";
  if (writeEmailLinkOpenTag.arguments.length < 5 || linkCodeAppend == null)
    linkCodeAppend = "";
  document.write("<a" + linkCodePrepend + " href=\"mailto:" + emailAddress.toLowerCase() + "?subject=" + subject + "\"" + linkCodeAppend + ">");
  }

// Writes out the closing tag for an email link in the form </a>
function writeEmailLinkCloseTag() {
  document.write("</a>");
  }

// Writes out an email link in the form <a href="mailto:me@domain.com">some text</a>
function writeEmailTextLink(addressee,domain,subject,linkText,linkCodePrepend,linkCodeAppend) {
  writeEmailLinkOpenTag(addressee,domain,subject,linkCodePrepend,linkCodeAppend);
  document.write(linkText);
  writeEmailLinkCloseTag();
  }
  
// Writes out an email link in the form <a href="mailto:me@domain.com">me@domain.com</a>
function writeEmailAddressLink(addressee,domain,subject,linkCodePrepend,linkCodeAppend) {
  writeEmailLinkOpenTag(addressee,domain,linkCodePrepend,linkCodeAppend);
  writeEmailAddress(addressee,domain);
  writeEmailLinkCloseTag();
  }
  
// Writes out an email address
function writeEmailAddress(addressee,domain) {
  if (writeEmailAddress.arguments.length < 2 || domain == "" || domain == null)
    domain = site_domain;
  var emailAddress = addressee + "@" + domain;
  document.write(emailAddress);
  }

/* MISCELLANEOUS FUNCTIONS */

function getElementsByClass(searchClass,node,tag) {
  var classElements = new Array();
  if (node == null)
    node = document;
  if (tag == null)
    tag = '*';
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp('(^|\\s)'+(searchClass instanceof Array ? searchClass.join('|') : searchClass )+'(\\s|$)');
  for (i = 0, j = 0; i < elsLen; i++) {
    if (pattern.test(els[i].className)) {
      classElements[j] = els[i];
      j++;
      }
    }
  return classElements;
  }

function addEvent(obj, type, fn, useCapture) {
  if (obj == null)
    obj = window;
  if (obj.addEventListener) {
    obj.addEventListener( type, fn, useCapture );
    }
  else if (obj.attachEvent) {
    obj["e"+type+fn] = fn;
    obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
    obj.attachEvent( "on"+type, obj[type+fn] );
    }
  else {
    obj["on"+type] = obj["e"+type+fn];
    }
  }

/* COOKIE FUNCTIONS */

function cookieGet(name) {
  var cookies = document.cookie.split(";");
  for (var i = 0; i < cookies.length; i++) {
    var a = cookies[i].split("=");
    if (a.length == 2 && a[0].trim() == name)
      return unescape(a[1].trim());
    }
  return "";
  }

function cookieSet(name, value, days) {
  var date = new Date();
  date.setTime(date.getTime()+(days*24*60*60*1000));
  document.cookie = name + "=" + escape(value) + "; expires=" + date.toGMTString() + "; path=/"; // expiry = 0 expires at end of session, but doesn't work in IE
  }

function cookieDel(name) {
  document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/";
  }

function rememberMenu(item) {
  document.cookieSet = true;
  cookieSet('menuitem', item, 1);
  }

addEvent(window,'unload',function() { if (!document.cookieSet) { cookieDel("menuitem") } },false);

/* HELPER FUNCTIONS */

String.prototype.trim = function() {
  var s = this.replace(/^\s*/, "");
  return s.replace(/\s*$/, "");
  }
//-->