var menuImages = new Array();
var initialKeyword = "Enter Keyword";

function init() {

  createMenu( "nav_register", "nav_how_it_works", "nav_faqs", "nav_your_details", "nav_for_advertisers", "nav_contact_us" );

  initialiseKeywordWipe();

}

function createMenu() {
  if (!document.images[0].getAttribute) return;
  if ( createMenu.arguments.length > 0 ) {
    var target, img;
    for (var x=0; x<createMenu.arguments.length; x++) {
      target = createMenu.arguments[x];
      if ( ! document.images[target] ) break;
      img = document.images[target];
      menuImages.length++;
      menuImages[target] = new Array(1);
      menuImages[target]['off'] = new Image(); menuImages[target]['off'].src = img.src;
      if (img.getAttribute( "over" )) {
        menuImages[target].length++;
        menuImages[target]['over'] = new Image(); menuImages[target]['over'].src = img.getAttribute( "over" );
        img.onmouseover = function () { this.src = menuImages[this.name]['over'].src; }
        img.onmouseout = function () { this.src = menuImages[this.name]['off'].src; }
      }
      if (img.getAttribute( "down" )) {
        menuImages[target].length++;
        menuImages[target]['down'] = new Image(); menuImages[target]['down'].src = img.getAttribute( "down" );
        img.onmousedown = function () { this.src = menuImages[this.name]['down'].src; }
        img.onmouseup = function () { this.src = (menuImages[this.name]['over']) ? menuImages[this.name]['over'].src : menuImages[this.name]['off'].src; }
      }
    }
  } else return;
}

function initialiseKeywordWipe() {

    document.forms['find_an_offer']['keyword'].value = initialKeyword;

    document.forms['find_an_offer']['keyword'].onfocus = function () {
        if ( this.value == initialKeyword ) {
            this.value = "";
        }
    }

    document.forms['find_an_offer']['keyword'].onblur = function () {
        if ( this.value == "" ) {
            this.value = initialKeyword;
        }
    }

}


function findOffer() {
    
    var kw = document.forms['find_an_offer']['keyword'].value;

    if ( kw == initialKeyword ) {
        alert( "Please enter a keyword to search for an offer." );
        return;
    }

    if ( kw.indexOf( " " ) > 0 ) {
        alert( "Please search for one keyword at a time." );
    } else {
        location.href = '/offer/index.html?keyword='+kw;
    }

}
