function tabs5(tab_clicked,sender){
	var isInactive = false;
	
	if (typeof sender != "undefined"){
		if(sender.className != "active")
			isInactive = true;
	}
	else
		isInactive = true;
		
	if(isInactive){
		var search_tabs_bg_y_offset = "0 0";
		var tab_clicked_id = "";
		
		switch(tab_clicked)
		{
			/*
				Depending on which tab was clicked, switch the result area, pagination area, and search tabs, make ajax call, refresh ads, and erase cookies as appropriate.
				
				Note- We may not need code to toggle pagination since QuickandSimple has a very nice div structure. 
			*/
			case "searchv2_textbut":
			pagination(0);
			$("#articleLoading .searchv2_loading").show();
			$(".search #ajax_results").hide(); //Hide the borders from the ajax results
			$("#searchv2_textsearch").show(); //Show/Hide result area
			$("#searchv2_imagesearch,#searchv2_videosearch,#searchv2_blogsearch,#searchv2_recipesearch").hide();
			search_tabs_bg_y_offset = "0 0";
			eraseCookie('searchreferurl'); //erase cookies when user clicks text button only
			eraseCookie('searchterm');
			tab_clicked_id = "searchv2_textbut";
			break;
			
			
			case "searchv2_imagesearch": //case trick to act as an or, this is what the cookie uses to communicate
			case "searchv2_imagesbut":
			paginationImgs(0);
			$("#imagesLoading .searchv2_loading").show();
			$(".search #ajax_results").show(); //Show the borders from the ajax results
			$("#searchv2_imagesearch").show(); //Show/Hide result area
			$("#searchv2_textsearch,#searchv2_videosearch,#searchv2_blogsearch,#searchv2_recipesearch").hide();
			search_tabs_bg_y_offset = "0 -45px";
			tab_clicked_id = "searchv2_imagesbut";
			break;
			
			case "searchv2_videosearch": //case trick to act as an or, this is what the cookie uses to communicate
			case "searchv2_videosbut":
			paginationVids(0);
			$("#videosLoading .searchv2_loading").show();
			$(".search #ajax_results").show(); //Show the borders from the ajax results
			$("#searchv2_videosearch").show(); //Show/Hide result area
			$("#searchv2_textsearch,#searchv2_imagesearch,#searchv2_blogsearch,#searchv2_recipesearch").hide();
			search_tabs_bg_y_offset = "0 -90px";
			tab_clicked_id = "searchv2_videosbut";
			break;
			
			
			case "searchv2_blogsearch": //case trick to act as an or, this is what the cookie uses to communicate
			case "searchv2_blogsbut":
			paginationBlogs(0);
			$("#blogsLoading .searchv2_loading").show();
			$(".search #ajax_results").show(); //Show the borders from the ajax results
			$("#searchv2_blogsearch").show(); //Show/Hide result area
			$("#searchv2_textsearch,#searchv2_imagesearch,#searchv2_videosearch,#searchv2_recipesearch").hide();
			search_tabs_bg_y_offset = "0 -135px";
			tab_clicked_id = "searchv2_blogsbut";
			break;
			
			
			case "searchv2_recipesearch": //case trick to act as an or, this is what the cookie uses to communicate
			case "searchv2_recipesbut":
			paginationRecipes(0);
			$("#recipesLoading .searchv2_loading").show();
			$(".search #ajax_results").show(); //Show the borders from the ajax results
			$("#searchv2_recipesearch").show(); //Show/Hide result area
			$("#searchv2_textsearch,#searchv2_imagesearch,#searchv2_videosearch,#searchv2_blogsearch").hide();
			search_tabs_bg_y_offset = "0 -180px";
			tab_clicked_id = "searchv2_recipesbut";
		}
		
		$("#searchv2_tabs").css("background-position",search_tabs_bg_y_offset); //Change tabs
		$("#searchv2_tabs a").removeClass("active");
		$("#" + tab_clicked_id).addClass("active");
		refreshAds();	//Refresh ads after the user changes tabs
	}
}

/*
We can't use input type=button because of google ads, so this
script will cycle through each form, add an ID, and attach the correct
javascript submit code.
*/
$(document).ready(function(){
	// unescape all input value
    var search_term = unescape(getQueryVariable('q').replace(/\+/g,'%20'));
    search_term = search_term.replace(/&lt;/g,'<').replace(/&gt;/g,'>');
    $("input[name='q']").val(search_term); 

	
	$(".search_form").each(function(i){
		var new_search_id = 'search_form_' + i;
		$(this).attr('id',new_search_id);
		
		var new_search_js = 'javascript:document.getElementById("'+ new_search_id +'").submit();'
		
		$(this).find('a:first').attr('href',new_search_js);
		
	})
	
	$.get("/ramp/jsearch?q=" + searchTerm + "&mediatype=image&num=20",function(data){
		data = $.parseJSON(((data.charAt(0) ==="(") && (data.charAt(data.length-1) ===")"))? data.substring(1,data.length-1):data = $.parseJSON(data))
		$.each(data.items, function(i,item){
			var imgHtml = '<a href="'+ item.link +'"><img src="'+ item.media.m +'" class="searchv2_itout_image" /></a>';
			$(imgHtml).appendTo("#image_block");
			imagesModQNS.init();
		});
	});
	
	addclass_last_image();
	   
	if($("#articles").find("#searchv2_noresults").length != 0)
	{
		$("#resultlist").addClass("no_result");
	}

	//VIDEOS MODULE
	$.get("/ramp/jsearch?q=" + searchTerm + "&mediatype=video&num=20", //     /cm/veranda/_etc/rampsearch-json.html
    function (data) {
		data = $.parseJSON(((data.charAt(0) === "(") && (data.charAt(data.length - 1) === ")")) ? data.substring(1, data.length - 1) : data = $.parseJSON(data));
		$.each(data.items, function (i, item) {
			var vidHtml = '<div class="searchv2_vtout_video"><a href="' + item.link + '"><img src="' + item.media.m + '" class="searchv2_vtout_image" /></a><div class="searchv2_vtout_text"><a href="' + item.link + '">' + item.title + '</a></div></div>';
			$(vidHtml).appendTo("#video_block");
			videosModQNS.init();
		});
	});
});

var imagesModQNS = {
 	 totalImgs:0,
 	 maxMove:1,
	 init : function(){
	  	if ($("#image_block").find(".searchv2_itout_image").length >= 1) {
			$("#searchv2_image_tout").show();
		}
		if ($("#image_block").find(".searchv2_itout_image").length >= 4) {
			$("#morebutton").show();
		}
	  this.totalImgs = $("#image_block").find(".searchv2_itout_image").length; 
	  this.maxMove = 1;
	 },
	 next : function(){
	  if ((this.maxMove*4) <= this.totalImgs) {
	   $("#image_block").animate({"left": "-=352px"}, "slow");
	   $("#lessbutton").show();
	  } 
	   this.maxMove++;
	  if ((this.maxMove*4) > this.totalImgs) {
	  	$("#morebutton").hide();
	  }
	 },
	 prev : function() {
	  if ((this.maxMove*4) >= 5) {
		 $("#image_block").animate({"left": "+=352px"}, "slow");
		 $("#morebutton").show();
	  } 
	   this.maxMove--;
	   if ((this.maxMove*4) < 5) {
	  	$("#lessbutton").hide();
	  }
	 }
}


var videosModQNS = {
 	 totalVids:0,
 	 maxMoveVid:1,
	 init : function(){
	  	if ($("#video_block").find(".searchv2_vtout_video").length >= 1) {
			$("#searchv2_video_tout").show();
		}
		if ($("#video_block").find(".searchv2_vtout_video").length >= 3) {
			$("#morebuttonVid").show();
		}
	  this.totalVids = $("#video_block").find(".searchv2_vtout_video").length; 
	  this.maxMoveVid = 1;
	 },
	 next : function(){
	  if ((this.maxMoveVid*4) <= this.totalVids) {
	   $("#video_block").animate({"left": "-=352px"}, "slow");
	   $("#lessbuttonVid").show();
	  } 
	   this.maxMoveVid++;
	  if ((this.maxMoveVid*4) > this.totalVids) {
	  	$("#morebuttonVid").hide();
	  }
	 },
	 prev : function() {
	  if ((this.maxMoveVid*4) >= 5) {
		 $("#video_block").animate({"left": "+=352px"}, "slow");
		 $("#morebuttonVid").show();
	  } 
	   this.maxMoveVid--;
	   if ((this.maxMoveVid*4) < 5) {
	  	$("#lessbuttonVid").hide();
	  }
	 }
}

if(typeof String.prototype.trim !== 'function') {
  String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, ''); 
  }
}

function addClassForNextPreButtons()
{

	$('.pagination div').each(function(){
		if($(this).text().trim() == "Previous")
		{
			$(this).addClass('previous').removeClass('next');
		}
	});
}

function addclass_last_image(){
$("#searchv2_imagesearch").find(".searchv2_image_wrapper").length
		$('.searchv2_image_wrapper').each(function(index) {
		if(((index+1)%3)==0){
			$(this).addClass("searchv2_last_image");
		}
		});
}

$(document).ajaxComplete(function() {
	addclass_last_image();
	addClassForNextPreButtons();
	$("#block_tabs").hide();
});

$(document).ajaxStart(function() {
	$("#block_tabs").show();
});
