﻿var loading = '<center><img src="/img/loading.gif" id="loading" alt="Loading" /></center>';
$(document).ready(function()
{
	//arama seysi
	$(".search-box li").live('click', function(){
		$(".search-box li.selected").removeClass("selected");
		$(this).addClass("selected");
		$("form #search").val($(".search-box li.selected").text());
		document.location.href = $(".search-box li.selected a").attr("href");
		$(".search-box").remove();
	});
	$("form #search").bind('keydown', function (evt){
		if (evt == null) { keycode = event.keyCode; } else { keycode = evt.which; }
		if (keycode == 13) {
			if($(".search-box li").hasClass("selected")){
				$("form #search").val($(".search-box li.selected").text());
				document.location.href = $(".search-box li.selected a").attr("href");
				$(".search-box").remove();
				return false;
			};
		};
	});
	$("form #search").bind('keyup', function (evt){
		if (evt == null) { keycode = event.keyCode; } else { keycode = evt.which; }
		switch (keycode){
			case 27:
				$(".search-box").remove();
				return false;
			case 38:
				if($(".search-box li:first-child").hasClass("selected")){
					$(".search-box li.selected").removeClass("selected");
					$(".search-box li:last-child").addClass("selected");
				}
				else{
					$('.search-box li.selected').removeClass("selected").prev(".search-box li").addClass("selected");
				}
				return false;
			case 40:
				if($(".search-box li:last-child").hasClass("selected")){
					$(".search-box li.selected").removeClass("selected");
					$(".search-box li:first-child").addClass("selected");
				}
				else{
					$('.search-box li.selected').removeClass("selected").next(".search-box li").addClass("selected");
				}
				return false;
		};
		if($(this).val().length >= 4 && $(this).val().length<7  && keycode != 40 && keycode != 38 && keycode != 13){
			$.ajax({
				url: '/search.php?m=ajax',
				cache: false,
				dataType: 'json',
				type: 'POST',
				data: 's='+$("form #search").val(),
				beforeSend: function()
				{
					$(".search-box").remove();
					yaz = '<ul class="search-box" style="border: 1px solid rgb(116, 111, 94); z-index: 950; visibility: visible; opacity: 0.9; left: 5px; top: 60px; width: 195px; overflow-y: hidden;">';
					yaz += '<li style="height: 18px;">'+loading+' Yükleniyor<\/li>';
					yaz += '<\/ul>';
					$("#search").after(yaz);
				},
				success: function(JSON)
				{
					var veri = JSON;
					yaz = '<ul class="search-box" style="border: 1px solid rgb(116, 111, 94); z-index: 950; visibility: visible; opacity: 0.9; left: 5px; top: 60px; width: 195px; overflow-y: hidden;">';
					$.each(JSON, function(j, k){
						yaz += '<li style="height: 12px;"'+ (j == 0 ? 'class="selected"' : '' )+ '><a href="/sector.php?id='+k.i+'">' + k.n + '</a><\/li>';
					});
					$(".search-box").remove();
					$("form #search").after(yaz);
				}
			});
		};
	});
	//tab seysi
	$(".tabs a").live("click", function(){
			$("#tabs>div").hide();
			$($(this).attr("href")+"_").show(); 
		});	
	$("#tabs>div>.page a").live("click", function(){
		var id = $(this).parent().parent().attr('id');
		$(".con",$(this).parent().parent()).empty();
		$.ajax({
			url: $(this).attr("href") ,
			cache: false,
			beforeSend: function()
			{
				$('#'+id+' .con').empty();
				$('#'+id+' .con').append(loading);
			},
			success: function(html)
			{
				$('#'+id+' .con').empty();
				$('#'+id+' .con').append(html+'+');
			}
		});
		return false;
	});
	//arama tab seysi
	$(".searchtabs ul li a").live("click", function(){
		$(".searchtabs ul li").removeClass();
		$(this).parent().addClass('selected');
		$(".searchtabs form input[name='m']").attr("value" , $(this).attr("href").replace('#',''));
		$(".searchtabs form").attr("action" , $(this).attr("href").replace('#','/search.php#'));
		$(".searchtabs form legend").empty().append($(this).html());
	});
	$(".searchtabs ul li a:first").click();
	$.feeder({ url: '/xml.php?m=tobb', divid : '#left-banner-1' , item : '"<a href=" + item.link + " target=_blank>" + item.title + "</a><br /><br /><img src=" + item.resim + " /><br /><br />"' , view: 0});

	$('a[rel*=facebox]').facebox();

	$("#tabs-blue ul li a").live("click", function(){
		$("#tabs-blue ul li").removeClass();
		$(this).parent().addClass('selected');
		$("#tabs-blue>div").hide();
		$("#tabs-blue>div").empty();
		$.feeder({ url: $(this).attr("href").replace('#','xml.php?m=') , divid : $(this).attr("href") , item : '"<span> <a href=" + item.link + " target=_blank>" + item.title + "</a></span>"' , view: 1});
		$($(this).attr("href")).show(); 
		return false;
	});	
	$("#tabs-blue ul a:first").click();
	//lastuserlist pagi seysi
	$(".box-small-center div.page a").live("click", function(){
		$(".box-small-center fieldset div").hide();
		$("#"+ $(this).attr("href").replace('#','') ).show();
		return false;
	});
	$("#sectorlist div:first").show();
	$("#sectorlist div.page a").click( function(){
		$("#sectorlist div.sectorss").hide();
		$("#sectorlist div#row" + $(this).attr("href").replace('#ss','') ).show();
		return false;
	});
	if (document.location.hash!='') { $("a[href='"+document.location.hash+"']").trigger("click"); }

	var s0 = new SWFObject('/img/kobiarabul.swf', 'mpl', '570', '82', '9');
		s0.addParam('allowscriptaccess','always');
		s0.addParam('allowfullscreen','true');
		s0.addParam('wmode','transparent');
		s0.write('bannertop');
	var	s2 = new SWFObject('/img/akdenizhaberler.swf', 'mpl', '190', '220', '9');
		s2.addParam('allowscriptaccess','always');
		s2.addParam('allowfullscreen','true');
		s2.addParam('wmode','transparent');
		s2.write('left-banner-4');
	$("input[type='text']").attr("autocomplete", "off");
	$("a.accordion:not(.accdown)").live("click", function()
	{
		$("div.accordion:visible").hide("show");
		$("a.accordion").removeClass("accdown");
		$(this).next().show("show").end().addClass("accdown");
		return false;
	});
});
