var initTMR;

$(document).ready(function(){
	start();
});

function start(){
	correctPNG();
	
	$("*").css("font-family", "tahoma").ajaxComplete(function(event,request, settings){
		if(initTMR){
			clearTimeout(initTMR);
		}
		initTMR = setTimeout("init();", 800);
	});
	
	$('#tabs').tabs();
	$('#tabs').tabs('option', 'fx', {
		opacity: 'toggle'
	});
	
	$("*","#oylamaDIV").tipsy("n");
	
	init();
}

function init(){
	$('.tipsy').remove();
	$('[title][g=n]').tipsy({
		gravity: 'n'
	});
	$('[title][g=w]').tipsy({
		gravity: 'w'
	});
	$('[title][g=s]').tipsy({
		gravity: 's'
	});
	$('[title][g=e]').tipsy({
		gravity: 'e'
	});
	$('[title][g!=n][g!=w][g!=s][g!=e]').tipsy({
		gravity: 's'
	});
	
	$("[tarih=1]").mask("99.99.9999");
	
	$("[numeric=1]").numeric("0123456789");
	$("[numeric=2]").numeric(".");
	
	$(".ajaxForm").unbind("submit").submit(function(){
		return ajaxForm(this);
	});
	
	$("[opacity]").each(function(){
		$(this).css("opacity", $(this).attr("opacity"));
	});
	
	galeriYap("a[rel=lightbox]");
}

$(function(){
	$("[numeric=1]").numeric('1234567890');
	$("[numeric=2]").numeric('.');
	
});

function sayfaDegis(adres){
	window.location.href = adres;
}

function galeriYap(str){
	$(str).lightBox({
		overlayBgColor: '#000',
		overlayOpacity: 0.7,
		imageLoading: 'JS/jQuery/lightbox/images/lightbox-ico-loading.gif',
		imageBtnClose: 'JS/jQuery/lightbox/images/lightbox-btn-close.gif',
		imageBtnPrev: 'JS/jQuery/lightbox/images/lightbox-btn-prev.gif',
		imageBtnNext: 'JS/jQuery/lightbox/images/lightbox-btn-next.gif',
		containerResizeSpeed: 350 ,
		txtImage: 'Resim',
		txtOf: '/'
	});
}

function secAll(me){
	var val = $(me).attr("checked");
	var grup = $(me).attr("grup");
	$("input[grup="+ grup +"]").attr("checked", val);
}

function ajaxDiyalog(adres, options, ajaxOptions){
	$('.dialog-content').css("overflow-x", null).css("overflow-y", null);
	$.weeboxs.open('Lütfen Bekleyiniz...',{
		title: 'Lütfen Bekleyiniz...'
	});
	
	if(ajaxOptions){
		if(ajaxOptions.method == "post"){
			$.post(adres, ajaxOptions, function(data){
				$.weeboxs.close();
				$.weeboxs.open(data, options);
			});
		}else{
			$.get(adres, ajaxOptions, function(data){
				$.weeboxs.close();
				$.weeboxs.open(data, options);
			});
		}
	}else{
		$.get(adres, function(data){
			$.weeboxs.close();
			$.weeboxs.open(data, options);
		});
	}
}

function frameDiyalog(baslik, adres, w, h){
	if(w == "undefined" || w == null){
		w = 600;
	}
	
	if(h == "undefined" || h == null){
		h = 500;
	}
	
	$.weeboxs.open('<iframe width="'+ w +'" height="'+ h +'" style="border:0; margin:0px 0px 0px 0px; padding:0px 0px 0px 0px;" scrolling="auto" src="'+ adres +'">',{
		title: baslik,
		width: (w + 6)
	});
	$('.dialog-content').css("overflow-x", "hidden").css("overflow-y", "hidden");
}

function mailListEkle(me){
	$('[rel=sonuc]', me).html("Lütfen bekleyiniz.");
	
	var mail = $('[name=mail]', me).val();
	$.post("mail-list-ekle.php", {'mail':mail}, function(data){
		$('[rel=sonuc]', me).html(data);
	});
}

function correctPNG() {
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	if ((version >= 5.5) && (document.body.filters)) 
	{
	  for(var i=0; i<document.images.length; i++)
	  {
		 var img = document.images[i]
		 var imgName = img.src.toUpperCase()
		 if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		 {
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
			var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			var imgStyle = "display:inline-block;" + img.style.cssText 
			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			img.outerHTML = strNewHTML
			i = i-1
		 }
	  }
	}
}

function videoAc(me){
		var adres = $(me).attr("href");
		var isim = $(me).attr("isim");
				
		var w = '550';
		var h = '350';
		var skin = 'FLVPlayer/SkinUnderPlayStopSeekMuteVol.swf';
		
		var str = '<object id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="player" width="'+535+'" height="'+h+'">\
		<param name="movie" value="JWplayer/player.swf" />\
		<param name="allowfullscreen" value="true" />\
		<param name="allowscriptaccess" value="always" />\
		<param name="flashvars" value="file='+adres+'" />\
		<embed\
			type="application/x-shockwave-flash"\
			id="JWplayer"\
			name="JWplayer"\
			src="JWplayer/player.swf"\
			width="'+535+'" \
			height="'+h+'"\
			allowscriptaccess="always" \
			allowfullscreen="true"\
			flashvars="file='+adres+'"\
		/>\
	</object>';
		
		$.weeboxs.open(str,{
					   title:isim,
					   width:parseInt(w)
					   });
	}