(function($)
{
	$(document).ready( function() { 
		
		// Define what happens when the textbox comes under focus
    // Remove the watermark class and clear the box
		$("#txtAnahtar").focus(function() {

			$(this).filter(function() {

				// We only want this to apply if there's not 
				// something actually entered
				return $(this).val() == "" || $(this).val() == "Search by keywords"

			}).removeClass("watermarkOn").val("");

		});

		// Define what happens when the textbox loses focus
		// Add the watermark class and default text
		$("#txtAnahtar").blur(function() {

			$(this).filter(function() {

				// We only want this to apply if there's not
				// something actually entered
				return $(this).val() == ""

			}).addClass("watermarkOn").val("Search by keywords");

		});
			
		
		$('A[rel="external"]').click( function() {
			key = $(this).attr('id').substring(1);
			AnahtarDetay(key, '');
			return false;
		});
		
		var key = $.jqURL.get("key");
		if(key && key.length>0){
			var Akey = "A" + String(key);
			if($('#'+ Akey)) $('#'+ Akey).click();
		}
		
	
	});
})(jQuery);



function AnahtarDetay(key, keyword){
	var DivAdi = "divDetay" + key;
	var objeDiv = document.getElementById(DivAdi);
	if(!objeDiv) return;
	var objImg = document.getElementById("imgDetay" + key);
	var bDurum = false;
	var strImgSrc = "/images/DetayAc.gif";
	if(objeDiv.style.display == '') bDurum = true;
	HepsiniKapat();
	if(bDurum){
		objeDiv.style.display = 'none';
	}
	else
	{
		objeDiv.style.display = '';
		strImgSrc = "/images/DetayKapat.gif";
	}
	if(objImg) objImg.src = strImgSrc;
	if(objeDiv.innerHTML.length>0) return;
	var adres = "/ajx.aspx?i=anahtarbul&key="+key+"&keyword=" + keyword;
	objeDiv.innerHTML = "<img src=/images/yukleniyor.gif> loading...";
	
	(function($)
	{
	$.ajax({
		type: "GET",
		url: "/ajx.aspx",
		data: "i=anahtarbul&key="+key+"&keyword=" + keyword,
		success: function(msg){
			objeDiv.innerHTML = msg;
			var Akey = "A" + String(key);
			if($('#'+ Akey))
				$.scrollTo('#'+ Akey, 800, {margin:true} );
		}
	});})(jQuery);
}

function HepsiniKapat(){
	var spanlblBody = document.getElementById('lblBody');
	if(!spanlblBody) return;
	var elem = spanlblBody.getElementsByTagName('div');
	var objImg;
	var objeDiv;
	for(i=0;i<elem.length;i++)
	{	
		objeDiv = elem[i];
		if(objeDiv.id.length>0 && objeDiv.id.indexOf('divDetay')>=0){
			objeDiv.style.display = 'none';
			objImg = document.getElementById(objeDiv.id.replace("divDetay","imgDetay"));
			if(objImg) objImg.src = "/images/DetayAc.gif"
		}
	}
}


function kisaAra()
{
	var bul = document.getElementById("txtAnahtar");
	if (bul)
	{
		if (bul.value.length==0) return alert("Please enter a keyword to be searched.");
		var basharf = bul.value.substring(0,1).toUpperCase();
		if(window.location.href.indexOf("/" + basharf + ".aspx")>0)
			alert('')
		else
			window.location.href = basharf + ".aspx?keyword=" + bul.value;
			
	}
}
