﻿	var list_district = function(index){
		$.each(c[index].d, function(i, v){$("#town").append('<option value="'+v.i+'">'+(v.i == 0 ? 'Seçiniz' : v.n)+'<\/option>');});
	}
	$(function(){
		$.each(c, function(i, v){$("#city").append('<option value="'+v.i+'">'+(v.i == 0 ? 'Seçiniz' : v.n)+'<\/option>');});
		$("#city").bind(($.browser.msie ? "click" : "change"), function(){
			$("#town").empty();
			list_district($("option", this).index($(":selected", this)));
		});
		list_district(0);
	});
	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: 170px; 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: 170px; 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>" + (item.updated.substr(0,10)) + " <a href=" + item.link + " target=_blank>" + item.title + "</a></span>"' , view: 1});
			$($(this).attr("href")).show(); 
		});	
		$(".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;
		});
		if (document.location.hash!='') { $("a[href='"+document.location.hash+"']").trigger("click"); }
	var flashvars = {};
	var params = {};
	params.wmode = "transparent";
	var attributes = {};
	swfobject.embedSWF("img/kobiarabul.swf", "bannertop", "300", "120", "9.0.0",  false, flashvars, params, attributes);
	swfobject.embedSWF("img/sondakika.swf", "flashsondakika", "176", "14", "9.0.0",  false, flashvars, params, attributes);	});

