//SLI Search Form Replacement
function sliSearchFormReplacement(){
	//Swap FCP Search for SLI Search
	var
	sli_search_form = $('<form action="http://search.cyclesurgery.com/search" onsubmit="return ajaxsearchsubmit(this)" id="header_search_form" method="get" name="searchform" />'),
	sli_fieldset = $('<fieldset />'),
	sli_hidden_input = $('<input name="asug" type="hidden" />'),
	sli_text_input = $('<input autocomplete="off" class="text clear_value" id="keywords" name="w" type="text" value="Site search" />'),
	sli_button = $('<button class="submit img" type="submit">Submit</button>');
	sli_fieldset.append(sli_hidden_input).append(sli_text_input).append(sli_button);
	sli_search_form.append(sli_fieldset);

	$("#header_search_form").replaceWith(sli_search_form);

	//Re-enable the clear input value function for this new form text field
	$(".clear_value").focus(function(){
		if(this.value == this.defaultValue){
			this.value = "";
		}
	}).blur(function(){
		if(!this.value.length){
			this.value = this.defaultValue;
		}
	});
}

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

$(document).ready(function(){
						   
	sliSearchFormReplacement();

	// CYCLE-493
	$('#header_search_form').submit(function() {return ajaxsearchsubmit(this)});

	$('a[rel*="external"]').click(function(){
		this.target = "_blank";
	});

	//display product video
	$("#open-video").click(function(){
		$("#prod-video").show();
	});
	
	//hide product video
	$(".close").click(function() {
		$("#prod-video").hide();
	});
	
	$(".wc_specialized_all h1.landingpage-content").replaceWith('<h1 class="landingpage-content"><img src="/pws/client/images/specialized/sbc-logo-large.jpg" alt="Specialized" /></h1>');
	$(".wc_oakley_all h1.landingpage-content").replaceWith('<h1 class="landingpage-content"><img src="/pws/client/images/oakley/oak-logo-large.jpg" alt="Oakley" /></h1>');
	$(".wc_endura_all h1.landingpage-content").replaceWith('<h1 class="landingpage-content"><img src="/pws/client/images/endura/end-logo-large.jpg" alt="Endura" /></h1>');
  
	//load the cycle plugin 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: 5000
		});
	});	
});
