$("#header_search_form").remove();


///////////////////////////////////////////////
//SLI Search functions
//function sliSearchFormReplacement(){
  //SNOWROCK-1036
//  $("#sli_search_1").val("I\'m searching for...");
//} 


function ajaxsearchsubmit(form){
  var search = encodeURIComponent(form.w.value);
  var asug = encodeURIComponent(form.asug.value);
  window.location="http://search.snowandrock.com/search#w="+search+"&asug="+asug;
  return false;
}




///////////////////////////////////////////////		
//preload images
$.fn.preload = function(callback) {
  this.each(function(){
    $('<img/>')[0].src = this;
  });
  callback();
}

$(document).ready(function(){


  ////////////////////////////////////////////////
 // Run SLI Functions
 // sliSearchFormReplacement();
  $('#banner_search_form').attr('name','searchform');
  $('#banner_search_form').submit(function() {return ajaxsearchsubmit(this)});

  ////////////////////////////////////////////////	
  //product page descriptions toggle
	
  $(".inStoreDesc").hide();
	
  //toggle showing the descriptions
  $(".inStore").click(function() {
    if($(this).next(".inStoreDesc").is(":hidden")) {
      $(this).css({"clear":"both"});
    } else {
      $(this).css({"clear":"none"});
    }
    $(this).next(".inStoreDesc").slideToggle(500);
    return false;
  });
	
  ///////////////////////////////////////////////	
  //image replacement for brand pages
  $(".wc_brand_FIV h1.brand-name").replaceWith('<h1 class="brand-name"><img src="/pws/client/images/brand-logos/FIV.png" alt="Five Ten" /></h1>');

  ///////////////////////////////////////////////	
  //make external sites load in a new window
  $('a[rel*="external"]').click(function(){
    this.target = "_blank";
  });
	
  ///////////////////////////////////////////////
  //left nav toggle on buying guides pages
  $("ul.top-level>li>a").click(function(){
	
    $(this).next("ul.bottom-level").slideToggle(300);
		
    //prevent the links from working
    return false;
  });	
	
  ///////////////////////////////////////////////	
  //load the cycle pluging and run it on anything with a class jq-cycle
  $.getScript("/pws/client/javascript/jquery.cycle.all.min.js",function() {
    $('.jq-cycle').cycle({ 
      fx:    'fade', 
      speed:  3000 
    });
       
    // On the home page
    if ($('.Home').length) {
    
      //create a pager list
      $('#nav-bar .promotion').after('<ul id="pager"></ul>')
    	      
      //setup the scolling top
      $('.scroll').cycle({
        fx: 'scrollHorz',
        delay: 5000,
        timeout: 5000,
        next: '.next',
        prev: '.prev',
        pager:  '#pager',
        pause: true,

        pagerAnchorBuilder: function(idx, slide) {
          return '<li class="thumbnail"><img src="/pws/client/images/home-page/thumb-' + jQuery(slide).find('h2').attr('title') + '.jpg" alt="' + jQuery(slide).find('h2').attr('title') + '" width="55px"  height="40px" title="' + jQuery(slide).find('h2').attr('title') + '" /></li>';
        }
      });
    }
  });	
   
  // On the home page
  if ($('.Home').length) {
    //pre load the images
    $(['/pws/client/images/home-page/Main-apres.jpg',
    '/pws/client/images/home-page/Main-Half-term.jpg',
    '/pws/client/images/home-page/Main-Ski-winter.jpg',
    '/pws/client/images/home-page/Main-Snowboard.jpg',
    '/pws/client/images/home-page/Main-Outdoor.jpg', 
    '/pws/client/images/home-page/Main-Protest-comp.jpg', 
    '/pws/client/images/home-page/Main-K2.jpg']).preload(function() {
      $('.Home .apres').css("backgroundImage","url('/pws/client/images/home-page/Main-apres.jpg')");
      $('.Home .half-term').css("backgroundImage","url('/pws/client/images/home-page/Main-Half-term.jpg')");
      $('.Home .ski-winter').css("backgroundImage","url('/pws/client/images/home-page/Main-Ski-winter.jpg')");
      $('.Home .snowboard').css("backgroundImage","url('/pws/client/images/home-page/Main-Snowboard.jpg')");
      $('.Home .outdoor').css("backgroundImage","url('/pws/client/images/home-page/Main-Outdoor.jpg')");
      $('.Home .protest-comp').css("background","url('/pws/client/images/home-page/Main-Protest-comp.jpg')");
      $('.Home .k2').css("background","url('/pws/client/images/home-page/Main-K2.jpg')"); 
    });
  }	
});



