var $j = jQuery.noConflict();

$j(document).ready(function() {

	var clickSearchBg = false;
	var tbxFocus = false;
	
	function clickOpenSearch()
	{
		$j("#search_input").animate({width: "190px"}, 400, "swing");
		$j("#search_input input").focus();
		tbxFocus = true;
		document.getElementById("tbx_search").value = "";
		$j("#product_search a").unbind('click', clickOpenSearch);
		$j("#product_search a").click(clickLaunchSearch);
		$j("#product_search a").css({backgroundImage:"url(assets/images/ps_bg.gif)"});
		$j("#search_input").css({borderLeft:"2px solid #cddde9"});
		return false;
	}
	
	function clickLaunchSearch()
	{
		document.search.submit();
	}

	$j("#product_search a").click(clickOpenSearch);
	
	$j("#product_search").hover(

		function(){
			clickSearchBg = true;
			return false;
		},
		function(){
			clickSearchBg = false;
			hideSearchBar();
			return false;
		}					
	);
	
	$j("#search_input input").blur(function(){
	
		tbxFocus = false;
		hideSearchBar();
		return false;
	});
	
	$j("#search_input input").focus(function(){
	
		tbxFocus = true;
	});
	
	function hideSearchBar()
	{

		if ((tbxFocus == false) && (clickSearchBg == false))
		{
			$j("#search_input").animate({width: "0"}, 300, "swing");
			$j("#product_search a").unbind('click', clickLaunchSearch);
			$j("#product_search a").click(clickOpenSearch);
			$j("#product_search a").css({backgroundImage:"none"});
			$j("#search_input").css({borderLeft:"none"});
		}
		return false;
	}
	
	//function replaceQuotes()
	//{
		var blockquotes = document.getElementsByTagName("blockquote");
		for (j=0; j<blockquotes.length; j++) {
			var thisBlockInfo = blockquotes[j].innerHTML;
			var firstQuote = "<span class=\"quote_lt\">\"</span>";
			var midQuote = "<span class=\"quote_lastword\">";
			var lastQuote = "<img class=\"quote_rt\" src=\"assets/images/bg_quoteright.gif\" width=\"15\" height=\"11\" /></span>";
			//var thisBlockBuilder = "<span class=\"quote_lt\">\"</span>" + thisBlockInfo[0].nodeValue.substring(1, thisBlockInfo[0].nodeValue.length);
			var quoteSplit = thisBlockInfo.split(" ");
			//alert(quoteSplit[0].substring(1, quoteSplit[0].length));
			quoteSplit[0] = firstQuote + quoteSplit[0].substring(1, quoteSplit[0].length);
			quoteSplit[quoteSplit.length-1] = midQuote + quoteSplit[quoteSplit.length-1].substring(0, quoteSplit[quoteSplit.length-1].length-1) + lastQuote;
			
			var thisQuoteJoined = quoteSplit.join(" ");
			blockquotes[j].innerHTML = thisQuoteJoined;
		}
	//}
	
	//replaceQuotes();
	
});	