  var active_color = '#323232'; // Colour of user provided text
  var inactive_color = '#323232'; // Colour of default text
  var pagename='';
   $(function(){
    $.preLoadImages("/images/product_top_nav/home.png","/images/product_top_nav/freedom.png","/images/product_top_nav/sportsband.png","/images/product_top_nav/blutrax.png","/images/product_top_nav/tiger_eyes.png","/images/product_top_nav/endorphin.png","/images/product_top_nav/chat.png","/images/product_top_nav/phone.png","/images/product_top_nav/help.png","/images/product_top_nav/account.png","/images/product_top_nav/features.png","/images/product_top_nav/gallery.png","/images/product_top_nav/reviews.png","/images/product_top_nav/specs.png","/images/product_top_nav/works_with.png","/images/product_top_nav/where_to_buy.png","/images/product_top_nav/buy_now.png","/images/tooltip/buy_now.png","/images/tooltip/login.png","/images/tooltip/more.png","/images/tooltip/tip_aptx.png","/images/tooltip/tip_bb4notify.png","/images/tooltip/tip_bluetrax.png","/images/tooltip/tip_isportusport.png","/images/tooltip/tip_jb200.png","/images/tooltip/tip_sb2.png","/images/tooltip/usat.png","/images/tooltip/wired.png","/images/bg_homepop.png");
    $("input.default-value").css("color", inactive_color);
    var default_values = new Array();
    $("input.default-value").focus(function() {
      if (!default_values[this.id]) {
        default_values[this.id] = this.value;
      }
      if (this.value == default_values[this.id]) {
        this.value = '';
        this.style.color = active_color;
      }
      $(this).blur(function() {
        if (this.value == '') {
          this.style.color = inactive_color;
          this.value = default_values[this.id];
        }
      });
    });
    $('.moreinfo').click(function () {
      if (!$.support.opacity) {
       $('#MOREINFO_CONTENT').show(); 
      } else {
       $('#MOREINFO_CONTENT').fadeIn(); 
      }
    });
    $("div.scrollable").scrollable();
    $('#CLOSE a').click(function () {
      if (!$.support.opacity) {
       $('#MOREINFO_CONTENT').hide(); 
      } else {
       $('#MOREINFO_CONTENT').fadeOut(); 
      }
    });
    $('.accessory_button').click(function () {
      $('.ajaxSubmit').hide();
      if (!$.support.opacity) {
        $("#EMAIL_SIGNUP").show(); 
        $("#EMAIL_JOIN_FORM").show(); 
      } else {
        $("#EMAIL_SIGNUP").fadeIn(); 
        $("#EMAIL_JOIN_FORM").fadeIn(); 
      }
      $('#EMAIL_JOIN_FORM').css({opacity: '100'});
    });
    $("#EMAIL_SIGNUP").bind("mouseenter",function(){ }).bind("mouseleave",function(){
      if (!$.support.opacity) 
        $('#EMAIL_SIGNUP').hide();
      else
        $('#EMAIL_SIGNUP').fadeOut(); 
    });
    $('img.hover').hover(function () {
      var src = $(this).attr("src").replace("off", "on");
      $(this).attr("src", src);
    }, function () {
      var src = $(this).attr("src").replace("on", "off");
      $(this).attr("src", src);
    });
    $("#EMAIL_JOIN_FORM").validationEngine({
      inlineValidation: false,
      ajaxSubmit: true,
      ajaxSubmitFile: "/includes/email_join.php",
      ajaxSubmitMessage: false,
      success: function() { callSuccessFunction() },
      failure: function() {}
    });
    if ($.support.opacity) {
      $('#FOOTER').css({height: 0}).animate({ height: '30' }, 'slow');
      $("#HEADER_NAV").animate({ 
        marginTop: "0px"
      }, 500 );
    } else {
      $('#FOOTER').css({height: '30'}).show();
      $('#FOOTER').css({marginTop: '0'}).show();
      $('#HEADER_NAV').css({marginTop: '0'}).show();
    }
    $('#KEY').click(function () {
      $("#NAV_MENU").animate({ 
        marginTop: "0px"
      }, 500 );
    });
    $('#NAV_MENU_BUTTON_IMG').click(function () {
      $("#NAV_MENU").animate({ 
        marginTop: "0px"
      }, 500 );
    });
    $("#NAV_MENU").bind("mouseenter",function(){ }).bind("mouseleave",function(){
      $("#NAV_MENU").animate({ 
        marginTop: "-154px"
      }, 500 );
    });
    $('.top_section li a').each(function (i){
      if ($(this).attr("class").toString().search( new RegExp( /selected/i )) != -1) {
        $(this).css("background-position",'0 -49px');
      } else {
        $(this).hover(
          function() {
            $(this).css("background-position",'0 -49px');
          },
          function() {
            $(this).css("background-position",'0 0');
          }            
        );
      }
    });
    $('.bottom_section li a').each(function (i){
      if ($(this).attr("class").toString().search( new RegExp( /selected/i )) != -1) {
        $(this).css("background-position",'0 -33px');
      } else {
        $(this).hover(
          function() {
            $(this).css("background-position",'0 -33px');
          },
          function() {
            $(this).css("background-position",'0 0');
          }            
        );
      }
    });
    $("#NAV_KEY").animate({ 
      marginTop: "0px"
    }, 500 );
    $("#NAV_MENU_BUTTON").animate({ 
      marginTop: "0px"
    }, 500 );
    $("#COMMENTSFRM").validationEngine({
      inlineValidation: false,
      ajaxSubmit: true,
      ajaxSubmitFile: "/includes/support_email.php",
      ajaxSubmitMessage: false,
      success: function() { 
        $('#COMMENTSFRM').hide();
        if (!$.support.opacity)
          $('#COMMENTSFRM_CONFIRM').show();
        else
          $('#COMMENTSFRM_CONFIRM').fadeIn('slow');
        $('html, body').animate({scrollTop: '10000px'}, 'fast');
        $('#name').val('');
        $('#email').val('');
        $('#comments').val('');
        setTimeout("$('#COMMENTSFRM_CONFIRM').hide();$('#COMMENTSFRM').show();$('#COMMENTSFRM').css({opacity: '100'});", 5000);
      },
      failure: function() {}
    });
 
    $("#FAQ_FRM").validationEngine({
      inlineValidation: false,
      ajaxSubmit: true,
      ajaxSubmitFile: "/includes/support_email.php",
      ajaxSubmitMessage: false,
      success: function() { 
        $('#COMMENTSFRM').hide();
        if (!$.support.opacity)
          $('#COMMENTSFRM_CONFIRM').show();
        else
          $('#COMMENTSFRM_CONFIRM').fadeIn('slow');
        $('html, body').animate({scrollTop: '10000px'}, 'fast');
        $('#name').val('');
        $('#email').val('');
        $('#comments').val('');
        setTimeout("$('#COMMENTSFRM_CONFIRM').hide();$('#COMMENTSFRM').show();$('#COMMENTSFRM').css({opacity: '100'});", 5000);
      },
      failure: function() {}
    });
    
    $("#COMMENTSFRM_JUDD").validationEngine({
      inlineValidation: false,
      ajaxSubmit: true,
      ajaxSubmitFile: "/includes/judd_email.php",
      ajaxSubmitMessage: false,
      success: function() { 
        $('#COMMENTSFRM').hide();
        if (!$.support.opacity)
          $('#COMMENTSFRM_CONFIRM').show();
        else
          $('#COMMENTSFRM_CONFIRM').fadeIn('slow');
        $('#name').val('');
        $('#email').val('');
        $('#comments').val('');
        setTimeout("$('#COMMENTSFRM_CONFIRM').hide();$('#COMMENTSFRM').show();$('#COMMENTSFRM').css({opacity: '100'});", 5000);
      },
      failure: function() {}
    });

    $("#NOTIFY_ME_FRM").validationEngine({
      inlineValidation: false,
      ajaxSubmit: true,
      ajaxSubmitFile: "/includes/notify_list.php",
      ajaxSubmitMessage: false,
      success: function() { 
        $('#NOTIFY_ME_FRM').hide();
        if (!$.support.opacity)
          $('#NOTIFY_ME_FRM_THANKS').show();
        else
          $('#NOTIFY_ME_FRM_THANKS').fadeIn('slow');
        $('#email').val('');
        setTimeout("$('#NOTIFY_ME_FRM_THANKS').hide();$('#NOTIFY_ME_FRM').show();$('#NOTIFY_ME_FRM').css({opacity: '100'});", 5000);
      },
      failure: function() {}
    });

    $("#USAT_FORM").validationEngine({
      inlineValidation: false,
      ajaxSubmit: true,
      ajaxSubmitFile: "/includes/usat-login.php",
      ajaxSubmitMessage: false,
      success: function() {
        document.location.href = '/usat/welcome.html'; 
      },
      failure: function() {}
    });
    
    $("#PRESS_FRM").validationEngine({
      inlineValidation: false,
      ajaxSubmit: true,
      ajaxSubmitFile: "/includes/press_email.php",
      ajaxSubmitMessage: false,
      success: function() { 
        $('#PRESS_FRM').hide();
        if (!$.support.opacity)
          $('#PRESS_FRM_THANKS').show();
        else
          $('#PRESS_FRM_THANKS').fadeIn('slow');
        $('#email').val('');
        setTimeout("$('#PRESS_FRM_THANKS').hide();$('#PRESS_FRM').show();$('#PRESS_FRM').css({opacity: '100'});", 5000);
      },
      failure: function() {}
    });
    
    $("#RESELLERS_FRM").validationEngine({
      inlineValidation: false,
      ajaxSubmit: true,
      ajaxSubmitFile: "/includes/resellers_email.php",
      ajaxSubmitMessage: false,
      success: function() { 
        $('#RESELLERS_FRM').hide();
        if (!$.support.opacity)
          $('#RESELLERS_FRM_THANKS').show();
        else
          $('#RESELLERS_FRM_THANKS').fadeIn('slow');
        $('#email').val('');
        setTimeout("$('#RESELLERS_FRM_THANKS').hide();$('#RESELLERS_FRM').show();$('#RESELLERS_FRM').css({opacity: '100'});", 5000);
      },
      failure: function() {}
    });

    $("#searchFrm .search").click(function() {
      var search_word = $("#searchTxt").val();
      var dataString = 'searchTxt='+ search_word;

      if(search_word!='') { 
        $.ajax({
          type: "GET",
          url: "/includes/search.php",
          data: dataString,
          cache: false,
          success: function(html){
            $(".results").html(html);
            $("#FAQ_QUESTION_FRM").show();
          }

        });
      }
      return false;      
    });


  });
  function callSuccessFunction() {
    $('#EMAIL_SIGNUP').hide();
    if (!$.support.opacity)
      $('#EMAIL_SIGNUP_THANKYOU').show();
    else
      $('#EMAIL_SIGNUP_THANKYOU').fadeIn('slow');
    setTimeout("$('#EMAIL_SIGNUP_THANKYOU').hide();", 5000);
  }

  function jumpSlide(num) {
    var api = $(".scrollable").data("scrollable");
      api.seekTo(num, 'fast');
  }

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

/* create a timeOut function in jQuery */
jQuery.fn.idle = function(time){
  return this.each(function(){
    var i = $(this);
    i.queue(function(){
      setTimeout(function(){
        i.dequeue();
      }, time);
    });
  });
};

