$(document).ready(function() {
  //New window links
  $("a._blank").click(function() {
    window.open(this.href);
    return false;
  });
  //--- MENU
  var navTime;
  $(".mainnav").hover(function() {
    
    
    var NavID = $(this).attr("id").split("-")[1];
    $(".subnav").hide();
    $("#subnav" + NavID).show();
  },function() {
    
  });
  $(".subnav").hover(function() {
    
  }, function() {
    
  });
  //--- SEARCH
  $("#qs").focus(function() {
    if ($(this).val() == 'Search Bikes...') {
      $(this).val('');
    } else {
      $(this).keyup();
    }
  }).blur(function() {
    if ($(this).val() == '') {
      $(this).val('Search Bikes...');
    }
  }).keyup(function(e) {
    if (e.keyCode == 27) {
      $(this).blur();
    $("#searchResults").hide();
    if (isIE6()) $('select').show();
      return;
    }
    var val = $(this).val();
    whiteval = val.replace(/^\s*|\s*$/g,'');
    if (val && whiteval != '') {
      $('#searchResults').show();
      if (isIE6()) $('select').hide();
      $("#searchList").load("/qs/",
        {data: val}
      );
    } else {
      $('#searchResults').hide();
      if (isIE6()) $('select').show();
    }
  });
});

//tab effects

var TabbedContent = {
  init: function() {
    $(".tab_item").mouseover(function() {
        $(".tab_item").removeClass("cur");
        $(this).addClass("cur");
      var background = $(this).parent().find(".moving_bg");
      $(background).stop().animate({
        top: $(this).position()['top']
      }, {
        duration: 300
      });
      TabbedContent.slideContent($(this));
    });
  },

  slideContent: function(obj) {
    var margin = $(obj).parent().parent().find(".slide_content").width();
    margin = margin * ($(obj).prevAll().size() - 1);
    margin = margin * -1;
    $(obj).parent().parent().find(".tabslider").stop().animate({
      marginLeft: margin + "px"
    }, {
      duration: 300
    });
  }
}


//For the Bike Archives Dropdown List
function goTo(form) {
	if (form.targets.options[form.targets.selectedIndex].value =='#') {
	} else { 
		popupwindow(form.targets.options[form.targets.selectedIndex].value,'archivebike','width=1024,height=500,scrollbars=yes,resizable=yes,toolbar=no,status=no,location=yes');
	}
}
function popupwindow(theurl,windowname,features) {
	newwindow = window.open(theurl,windowname,features);
	if (window.focus) {newwindow.focus()}
	void 0;
}


//--- FIND A RETAILER
function fad(param, step) {
  $("#" + step).load('/includes/bikes.find-a-dealer.inc.php?where=' + param);
}


function isIE6() {
  if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
   var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
   if (ieversion<7)
    return true;
  }
  return false;
}
