var canliTikli = '0';
var oncekiMSJ = '';
var ilkKontrol = 0;
var sorulan = new Array();
var canliChatBool = true;
var canliTMR;

jQuery(function(){
	jQuery.facebox.settings.opacity = 0.7;
	jQuery.facebox.settings.overlay = true;
	
	setTimeout("jQuery('#durumu').fadeOut(1000);", 5000);
	
	jQuery("#indirimBG").css("opacity", "0.7");
	
	jQuery("#mailList").attr("value", "Mail Adresinizi Girin...").css("color", "#CCCCCC").click(function(){
		if(jQuery("#mailList").attr("value") == "Mail Adresinizi Girin..."){
			jQuery("#mailList").attr("value", "");
		}
	}).blur(function(){
		if(jQuery("#mailList").attr("value") == ""){
			jQuery("#mailList").attr("value", "Mail Adresinizi Girin...");
		}
	});
	jQuery("#mailList, #mailEkleBTN").attr("disabled", "");
	
	jQuery("#trMenu td").each(function(){
		if(jQuery(this).attr("isMenu") == "true"){
			jQuery(this).mouseover(function() {
				jQuery(this).css("background","url(IMG/btn-bg.png) center bottom no-repeat");
			}).mouseout(function() {
				jQuery(this).css("background","");
			});
		}
	});
	
	jQuery("#chatTXT").click(function(){
		if(jQuery("#chatTXT").attr("value") == "Bu kısma yazabilirsiniz..."){
			jQuery("#chatTXT").attr("value", "");
		}
		jQuery("#chatTXT").css("color", "#000000");
	}).blur(function(){
		if(jQuery("#chatTXT").attr("value") == ""){
			jQuery("#chatTXT").attr("value", "Bu kısma yazabilirsiniz...");
		}
		jQuery("#chatTXT").css("color", "#999999")
	});
	
	jQuery("#yeniMSJ").click(function(){
		canliDestek();
	});
	
	jQuery("#nedenSlide").cycle({
		fx: 'scrollUp',
		easing: 'easeInOutElastic',
		timeout: 3000,
		delay: -2000
	}).css("display", "block");
	
	jQuery("#trMenu").parent().parent().removeClass("menuContent-hover").hover(function() {
		jQuery(this).mousemove(function(e){
			var coOrdinate = jQuery(this).offset({relativeTo: "body"});
			var w = 830;
			var isikX = Math.round((e.pageX) - (coOrdinate.left) - (145 / 2));
			var isikBackground = "url(IMG/isik.png) "+ isikX +"px 34px no-repeat";
			if(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) == 6){
				isikBackground = "url(IMG/isik.jpg) "+ isikX +"px 35px no-repeat";
			}
			
			jQuery(this).css("background", isikBackground);
		});
	}, function() {
		jQuery(this).unbind("mousemove").css("background", "none");
	});
	
	canliLoop();
	domainReq();
	
	jQuery("#haberlerTD").css("background", "url("+ jQuery("#haberlerTD").attr("background") +") 215px top no-repeat");
	jQuery("[fixPNG]").pngfix();
});

function domainInfo(name, uzanti){
	jQuery.post("domain-info.php", {dmn:name, tld:uzanti}, function(data){
		jQuery.facebox("<pre>"+ data +"</pre>");
	});
}

function domainReq(){
	jQuery("#domainSor").click(function(){
		listDomains();
	});
	
	jQuery(".chkBX").click(function(){
		listDomains();
	});
	
	jQuery("#domains").blur(function(){
		listDomains();
	});	
}

function listDomains(){
	var HTML = '\
			  <table class="tbl" width="350" border="0" style="border: 1px solid #000000;" align="center" cellspacing="0" cellpadding="0"> \
				<tr bordercolor="#000000"> \
					<td class="tbl-baslik" width="250"><strong>Domain / Alan Adi</strong></td> \
					<td class="tbl-baslik" width="100" align="center"><strong>Durum</strong></td> \
				</tr>';
	
	var domains = jQuery("#domains").attr("value");
	domains = domains.replace(/\n/g, ",");
	domains = domains.replace(/\s+/g, "");
	domains = domains.replace("http://", "");
	domains = domains.replace("www.", "");
	domains = domains.replace(":", "");
	domains = domains.replace(".", "");
	domains = domains.replace("/", "");
	domains = domains.replace(/ç/g, "c");
	domains = domains.replace(/Ç/g, "C");
	domains = domains.replace(/ı/g, "i");
	domains = domains.replace(/İ/g, "İ");
	domains = domains.replace(/ğ/g, "g");
	domains = domains.replace(/Ğ/g, "G");
	domains = domains.replace(/ü/g, "u");
	domains = domains.replace(/Ü/g, "U");
	domains = domains.replace(/ö/g, "o");
	domains = domains.replace(/Ö/g, "O");
	domains = domains.replace(/ş/g, "s");
	domains = domains.replace(/Ş/g, "S");
	
	var domain = domains.split(",");
	var x = 0;
	for(x=0; x<domain.length; x++){
		if(domain[x] != ""){
			jQuery(".chkBX").each(function(){
				if(jQuery(this).attr("checked") == true){
					var full = domain[x] +"."+ jQuery(this).attr("value");
					full = full.toLowerCase();
					
					var domName = domain[x] + jQuery(this).attr("value");
					domName = domName.replace(".", "");
					
					var onceden = sorulan[full];
					
					if(!onceden){
						HTML += '<tr> \
									<td style="padding-left:5px; height:25px; font-size: 13px"><b>'+ domain[x] +'.'+ jQuery(this).attr("value") +'</b></td> \
									<td style="font-size: 13px" align="center" id="snc-'+ domName +'"><img src="IMG/ajax-loader.gif" /></td> \
								</tr>';
						
						jQuery.post("domain-sor.php", {dmn:domain[x], tld:jQuery(this).attr("value")}, function(data){
							jQuery("#snc-"+ domName).html(data);
							sorulan[full] = data;
						});
					}else{
						HTML += '<tr> \
									<td style="padding-left:5px; height:25px; font-size: 13x"><b>'+ domain[x] +'.'+ jQuery(this).attr("value") +'</b></td> \
									<td style="font-size: 13px" align="center" id="snc-'+ domName +'">'+ sorulan[full] +'</td> \
								</tr>';
					}
				}
			});
		}
	}
	
	HTML += '</table>';
	jQuery("#domainSNC").html(HTML);
}

function mailEkle(){
	var eMail = jQuery("#mailList").attr("value");
	jQuery("#mailList").attr("value2", eMail);
	if(eMail.indexOf("@") == -1 || eMail.indexOf(".") == -1){
		jQuery("#mailList, #mailEkleBTN").attr("disabled", "disabled");
		jQuery("#mailList").attr("value", "Hatalı eMail Adresi !").css("color", "#FF0000");
		
		setTimeout('jQuery("#mailList").attr("value", jQuery("#mailList").attr("value2")).css("color", "#CCCCCC"); jQuery("#mailList, #mailEkleBTN").attr("disabled", "");', 2000);
	}else{
		jQuery("#mailList, #mailEkleBTN").attr("disabled", "disabled");
		jQuery("#mailList").attr("value", "Lütfen Bekleyiniz...").css("color", "#FF9900");
		
		jQuery.post("mailList.php", {mail:eMail}, function(data){
			jQuery("#mailList").css("display", "none");
			jQuery("#mailMarquee").css("display", "block").html("&nbsp;&nbsp;&nbsp;"+ data +"&nbsp;&nbsp;&nbsp;");
		});
	}
}

function onlineBekleGizle(){
	jQuery('#onlineBekle').css('display', 'none');
}

function siteHarita(){
	jQuery("#haritaBOX").animate({ 
		opacity: "toggle"
	}, 300 );
}

function canliDestek(){
	if(canliChatBool == true){
		jQuery("#canliBOX").animate({ 
			opacity: "toggle"
		}, 300, function(){
			if(jQuery("#canliBOX").css("display") == "block"){
				canliTikli = '1';
				jQuery("#yeniMSJ").fadeOut(300);
			}else{
				canliTikli = '0';
			}
			
			jQuery.post("ajax.php", {islem:"cDestek", deger:canliTikli});
			if(canliChatBool == true){
				canliGuncelle();
			}
		});
	}
}

function canliGuncelle(){
	if(canliChatBool == true){
		jQuery.get("canliChat.php", function(data){
			if(data == "ping"){
				jQuery.post("canliChat.php", {islem:"ekle", mesaj:"pong"});
			}else{
				if(oncekiMSJ != data){
					oncekiMSJ = data;
					if(ilkKontrol >= 2){
						if(canliTikli == '0'){
							jQuery("#yeniMSJ").fadeIn(300);
						}
					}else{
						ilkKontrol = ilkKontrol + 1;
					}
				}
				jQuery("#canliText").html(data);
				jQuery('#canliText').scrollTop(jQuery('#canliText').height());
			}
		});
	}
}

function canliLoop(){
	if(canliChatBool == true){
		canliGuncelle();
        canliTMR = false;
		//canliTMR = setTimeout("canliLoop()", 1000);
	}
}

function canliGonder(){
	if(canliChatBool == true){
		var yazi = jQuery("#chatTXT").attr("value");
		jQuery("#chatTXT").attr("value", "");
		if(yazi != ""){
			//jQuery("#chatTXT").attr("disabled", "disabled");
			//jQuery("#chatTXT").attr("value", "Lütfen Bekleyiniz, Gönderiliyor...").css("color", "#FF9900");
			jQuery.post("canliChat.php", {islem:"ekle", mesaj:yazi},function(){
				//jQuery("#chatTXT").attr("disabled", "");
				canliGuncelle();
			});
		}
	}
}

function indirimYap(){
	if((jQuery("#iadi").attr("value") != "") && (jQuery("#isoyadi").attr("value") != "") && (jQuery("#itel").attr("value") != "") && (jQuery("#imail").attr("value") != "") && (jQuery("#ikonu").attr("value") != "")){
		var iForm = jQuery("#indirimFORM").serialize();
		iForm = iForm + "&ajax=1&indir=1";
		
		jQuery.post("indirim.php", iForm, function(data){
			jQuery("#indirimBOX").fadeOut(1000, function(){
				jQuery.facebox(data +'<br><br><input type="button" onClick="jQuery.facebox.close(); return false;" name="button" id="button" value="Tamam"  style="color: #FFFFFF; font-family: Tahoma; font-size: 11px; font-weight: bold; border-style: solid; border-width: 0; padding-left: 1; padding-right: 1; padding-top: 2; padding-bottom: 1; background-color: #2C2C2C"/>');
			});
		});
	}else{
		jQuery.facebox('Hiç Bir Kutucuğu Boş Bırakmamalısınız.<br><br><input type="button" onClick="jQuery.facebox.close(); return false;" name="button" id="button" value="Tamam"  style="color: #FFFFFF; font-family: Tahoma; font-size: 11px; font-weight: bold; border-style: solid; border-width: 0; padding-left: 1; padding-right: 1; padding-top: 2; padding-bottom: 1; background-color: #2C2C2C"/>');
	}
}

function indirimVazgec(){
	var str = '<br>İndirimlerimizden faydalanamayacaksınız<br>Eminmisiniz ?<br><br>';
		str += '<input type="button" onClick="indirimVazgec2(); return false;" name="button" id="button" value="Eminim"  style="color: #FFFFFF; font-family: Tahoma; font-size: 11px; font-weight: bold; border-style: solid; border-width: 0; padding-left: 1; padding-right: 1; padding-top: 2; padding-bottom: 1; background-color: #2C2C2C"/>';
		str += '&nbsp;&nbsp;&nbsp;<input type="button" onClick="jQuery.facebox.close(); return false;" name="button" id="button" value="Vazgeçtim"  style="color: #FFFFFF; font-family: Tahoma; font-size: 11px; font-weight: bold; border-style: solid; border-width: 0; padding-left: 1; padding-right: 1; padding-top: 2; padding-bottom: 1; background-color: #2C2C2C"/>';
	jQuery.facebox(str);
}

function indirimVazgec2(){
	jQuery.facebox.close();
	jQuery.post("indirim.php", {ajax:'1', indir:'0'}, function(data){
		jQuery("#indirimBOX").fadeOut(1000, function(){
			jQuery("#indirimBOX").fadeOut(1000);
		});
	});
}

function videoAc(me){
	var jsSO = 'http://www.medyax.com/JS/swfobject.js';
	var player = "http://www.medyax.com/SWF/video.swf";
	var file = jQuery(me).attr("href");
	var skin = "http://www.medyax.com/SWF/SkinUnderPlayStopSeekFullVol.swf";
	var w = 540;
	var h = 480;
	
	var str = '<script type="text/javascript" src="'+ jsSO +'"></script> \
			   <div id="flvDIV" style="width:'+ w +'px; height:'+ h +'px" align="center"></div> \
			   <script type="text/javascript"> \
					var so = new SWFObject("'+ player +'","single","'+ w +'","'+ h +'","0"); \
					so.addParam("allowfullscreen","true"); \
					so.addParam("wmode","transparent"); \
					so.addVariable("file", "'+ file +'"); \
					so.addVariable("skin", "'+ skin +'"); \
					so.write("flvDIV"); \
				</script>';
	jQuery.facebox(str);
}
