

$(document).ready(function(){
	$.extend($.expr[':'], {
		"contains-ic": "$.fn.text.apply([a]).toLowerCase().indexOf(m[3].toLowerCase())>=0"
	});

	$("#textcontainer").show();
	
	$("#container").children().each(function(){
		$(this).click(function(){
			$("#textcontainer").children().each(function(){
				$(this).fadeOut();
			});
			var itemId = $(this).attr("int")
			$("#container").children().each(function(){
				if($(this).attr("int")!=itemId){
					$(this).fadeOut(400);
				}
			});
			pauseZoom(itemId);
			return false;
		});
	});

	///////////// Extra event handlers

	//Search button click
	$("#searchBtn").click(function(){
		var searchStrn = $("#searchTxt").val();
		var searchRealm = $("input[@name=searchRadio]:checked").val();
		if(searchRealm =="page"){
			searchPage(searchStrn);
		}else{
			$(".leftcontainer").fadeOut("slow");
			searchStrn = urlencode(searchStrn);
			$(".leftcontainer").load("/search/"+searchStrn);
			$(".leftcontainer").fadeIn("slow");
		}
		
	});

	//Hide content button
	$("#hideContent").click(function(){
		$("#content").children().hide();
		$("#contentframe").animate({height:"0px", width:"0px", opacity:0}, "slow","", function(){$("#contentframe").hide()});
	});


	$("#resetSearch").click(function(){
		$(".leftcontainer span").css({"background":""});
		$("#searchTxt").val("");
		return false;
	});

	$(".tet").click(function(){
		
	});

	/////////////// End event handlers

});

function pauseZoom(itemId){
	$("#logo").fadeTo(500,1,function(){zoomImage(itemId);});
}

function zoomImage(itemId){
	$("#container").children().each(function(){
		if($(this).attr("int")==itemId){
			var url = $(this).children(0).attr("href");
			if (itemId == 2){
				$("#leftB").animate({"width":"0px"}, 700,"linear", function(){fadeContent(url);});
				$("#rightB").animate({"width":"0px"}, 700,"linear");
				//$("#"+divtext[itemId]).css({top:"0px",left:"0px"});
				//$("#logo").fadeTo(500,1,function(){$("#"+divtext[itemId]).fadeIn("slow");});
			} else {
				$(this).animate(animateDiv[0], 700, "linear",function(){fadeContent(url);})
				//$("#"+divtext[itemId]).css({top:"0px",left:"0px"});
				//$("#logo").fadeTo(500,1,function(){$("#"+divtext[itemId]).fadeIn("slow");});
			}
		}
	});
}
function fadeContent(url){
	//$("#logo").fadeTo(400,1,function(){$("#contentframe").fadeIn(500);});
	$("#logo").fadeTo(1000,1,function(){$("#container").fadeTo(500,0);});
	$("#logo").fadeTo(1000,1,function(){window.location = url});
}



function searchPage(searchStrn){
	if(searchStrn ==""){
		//blinkBox("#searchTxt");
		return false;
	}
	var searchStrnSplit = searchStrn.split(" ");
	var instanceCount = 0;
	if(searchFnCalled == true){
		$(".leftcontainer span").css({"background":""});
	}else{
		searchFnCalled = true;
		$(".leftcontainer p").contents().not("[nodeType=1]").wrap("<span></span>")
		$(".leftcontainer p").children().each(function(){
			var newTxt = $(this).html().split(" ").join(" </span> <span> ");
			newTxt = "<span> "+newTxt+" </span> ";
			if($(this).html() !=""){
				$(this).html(newTxt);
			}


		});

	}
	for(i=1;i<=searchStrnSplit.length;i++){
		$(".leftcontainer p").children().each(function(){
			var searchItem = $(this).find(":contains-ic('"+searchStrnSplit[i-1]+"')");
			if(searchItem.text() != ""){
				searchItem.css({"background":"#FFFF00"});
				if($(this).parent().parent().css("display")=="none"){
					$(this).parent().parent().fadeIn("slow");
				}
				var splitStr  = searchItem.text().split(searchStrnSplit[i-1]);
				instanceCount += splitStr.length - 1
				
			}
		});
	}

	//alert(instanceCount);
}

function blinkBox(field){
	$("#logo").fadeTo(300, "1",function(){$(field).css({"background":"#FED480"})});
	$("#logo").fadeTo(300, "1",function(){$(field).css({"background":"white"})});
	$("#logo").fadeTo(300, "1",function(){$(field).css({"background":"#FED480"})});
	$("#logo").fadeTo(300, "1",function(){$(field).css({"background":"white"})});
}

function clearBox(field, originalString){
	if($(field).val() == originalString) $(field).val("");
}

function urlencode(str) {
return escape(str).replace('+', '%2B').replace('%20', '+').replace('*', '%2A').replace('/', '%2F').replace('@', '%40');
}

function urldecode(str) {
return unescape(str.replace('+', ' '));
}

function showHideFAQ(id){
	if($("#faqInfo"+id).css("display")=="none"){
		$("#faqInfo"+id).slideDown("slow");
	}else{
		$("#faqInfo"+id).slideUp("slow");
	}
}
