$(document).ready(function(){
	var anasayfa_url = $("#anasayfa_url").html();
	var anasayfa_domain = $("#anasayfa_domain").html();
	$(".popClose,.popCloseWhite").click(function(){
		//$(this).parent().parent().parent().fadeOut();
		$(".popup").not("#popup_kayit").fadeOut();
	});
	$(document).keyup(function(e) {
		if (e.keyCode == 27) { $(".popClose").click(); }
	});
	$(".iletisim_link").live({click: function(){
		$(".popup").fadeOut();
		$("#popup_iletisim").center_vertical().fadeIn();
	}});
	$("#iletisim_gonder").live("click",function(){
		var mesaj_ = $("#iletisim_mesaj").val();
		if(mesaj_=="")
			$("#iletisim_rapor").html("Lütfen görüşlerinizi yazın.").css('color','red');
		else{
			var isim_ = $("#iletisim_isim").val();
			if(isim_=="")
				$("#iletisim_rapor").html("Lütfen isminizi yazın.").css('color','red');
			else{
				var eposta_ = $("#iletisim_eposta").val();				
				if(eposta_=="")
					$("#iletisim_rapor").html("Lütfen e-posta adresinizi yazın.").css('color','red');
				else{
					$("#iletisim_gonder").attr('disabled', 'disabled');
					$("#iletisim_rapor").html("<img src=\""+anasayfa_url+"img/loading.min.gif\" />  Gönderiliyor...").css('color','black');
					$.post(
						"http://"+anasayfa_domain+"/sorgu/iletisim_gonder.php",
						{
							isim: $('#iletisim_isim').val(),
							eposta: $('#iletisim_eposta').val(),
							mesaj: $("#iletisim_mesaj").val()
						},
						function(data){
							if(data=='1'){
								$("#iletisim_rapor").html("İletiniz tarafımıza ulaştı. En kısa zamanda değerlendirilecek<br />ve geri dönüş yapılacaktır. Teşekkür ederiz.").css('color','green');
								$("#iletisim_gonder").removeAttr('disabled');
								$("#iletisim_gonder").val("Gönder");
								$("#iletisim_mesaj").html("");
								$("#popup_iletisim").delay(8000).fadeOut();
							}else if(data=='2'){
								$("#iletisim_rapor").html("Lütfen geçerli bir eposta adresi girin.").css('color','red');
								$("#iletisim_gonder").removeAttr('disabled');
								$("#iletisim_gonder").val("Gönder");
							}else{
								$("#iletisim_rapor").html("Bir hata oluştu. Lütfen tekrar deneyin. ("+data+")").css('color','red');
								$("#iletisim_gonder").removeAttr('disabled');
								$("#iletisim_gonder").val("Gönder");
							}
						}
					);
				}
			}
		}
	});
	$('.sozlesme').click(function(){
		$(".popup").not("#popup_kayit").fadeOut();
		$.get('http://'+anasayfa_domain+'/sozlesme.html', function(data){
		  $('#sozlesme_metin').html(data);
		});
		$("#popup_sozlesme").centerit().fadeIn();
	});
	$('.gizlilik').click(function(){
		$(".popup").fadeOut();
		$.get('http://'+anasayfa_domain+'/gizlilik.html', function(data){
		  $('#gizlilik_metin').html(data);
		});
		$("#popup_gizlilik").centerit().fadeIn();
	});
	$('.hakkinda').click(function(){
		$.get('http://'+anasayfa_domain+'/hakkinda.html', function(data){
		  $('#hakkinda_metin').html(data);
		});
		$(".popup").fadeOut();
		$("#popup_hakkinda").centerit().fadeIn();
	});
	jQuery.fn.center_vertical = function(){
		var inner = this.attr("id").substring(6);
		//this.css("position","absolute");
		this.find("#popInner_"+inner).css("top", (($(window).height() - this.find("#popInner_"+inner).outerHeight()) / 2) + $(window).scrollTop() + "px");
		//this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
		return this;
	}
	jQuery.fn.centerit = function(){
		var inner = this.attr("id").substring(6);
		this.find(".popup_foto").css("max-height", (($(window).height() - 60)) + "px");
		this.find(".popup_foto").css("max-width", (this.find(".popup_ara").innerWidth() - 60) + "px");
		this.find("#popInner_"+inner).css("top", (($(window).height() - this.find("#popInner_"+inner).outerHeight()) / 2) + $(window).scrollTop() + "px");
		this.find("#popInner_"+inner).css("left", ((this.find(".popup_ara").innerWidth() - this.find("#popInner_"+inner).outerWidth()) / 2) + $(window).scrollLeft() + "px");
		return this;
	}
});
