var p=navigator.userAgent.toLowerCase(),
	u,
	wf=true,
	h,
	o=false,
	j=0;
$(document).ready(function(){ 
	if(p.match(/(iphone|ipod|ipad)/)) {
		u='ios';
	}
	else if(p.match(/webkit/)) {
		u="webkit";
	}
	else if(p.match(/opera/)) {
		u="opera";
	}
	else if(p.match(/firefox/)) {
		u="firefox";
	}
	else if(p.match(/msie 8/)) {
		u="msie8";
		o=true;
	}	
	else if(p.match(/msie 9/)) {
		u="msie9";
	}		
	else if(p.match(/msie 10/)) {
		u="msie10";
	}	
	else if(p.match(/msie/)) {
		u="msie";
		wf=false;
		o=true;
	}
	if(wf==true) {
		$.getScript("js/gwf.js?");
	}
	if(o==true) {
		$('<div class="dikkat"><p>Web sitemizi sorunsuz bir şekilde görüntüleyebilmeniz için tarayıcınızı güncel sürümüne yükseltmeniz gerekmektedir.</p><p> Uyumlu tarayıcılar: MS Internet Explorer 9 ve üzeri, Webkit/Safari 3.1 ve üzeri, Mozilla Firefox 3.5 ve üzeri, Google Chrome 4.0 ve üzeri, Opera 10 ve üzeri.</p></div>').appendTo(".uyari");
	}
	$('.nav ul > li > a').hover(function(){$(this).animate({color:"#3986a6"},300);},function(){$(this).animate({color:"#555555"},700);});
	$.getScript('js/'+u+'.js');
	$('#lms-launcher').live('click',function(){
		window.open($("#lla").attr('href'),'_blank');
	});		
	if(window.location.hash){
		b(window.location.hash);
	} else {
		b("#!anasayfa");
	}
	$('a').live('click',function() {
		b(this.hash);	
	});	
	$('.flyer > .bt-kapat').click(function(){
		$(this).parent().fadeOut()
	});	
	$.getJSON('data/spect.txt',function(jd) {
		$.each(jd,function(i,d) {			
			$('<img />').attr({'src':d.url,'id':'spect'+i}).load(function(){
        		$('.spect > .ci').append($(this));
				if(i>=jd.length-1) P(i);
        	});
		});
	})
});

function P(j,p){
	if(typeof p=='undefined') {for(var i=0;i<=j+1;i++) $('#spect'+i).fadeOut(0); return P(j,0)}
	$('#spect'+p).fadeIn(1000);
	setTimeout(function(){$('#spect'+p).fadeOut(1000);if(p<j) p++; else p=0;P(j,p);},9000);	
}

function b(f) {
	if(!f.match(/#!/)) return;
	if(f.match(/#!duyurular#/)) {h=f.slice(12); f="#!duyurular"};
	$("#inner").fadeOut(100,function(){
		f=f.slice(1).replace('!', '');
		$.ajax({
		  url: 'content/'+f+'.html?'+m(),
		  cache: false,
		  success: function(d){
			$("#inner").html(d);			
			switch(f) {
				case "anasayfa":
					$.ajax({
						url:'/data/guncelManset.xml?'+m(),
						type:'GET',
						dataType:'xml',
						timeout:0,
						success:function(x) {
							var s="";
							$(x).find("tabloManset").each(function() {
								s+='<div id="'+$(this).find("id").text()+'" class="item"><h3>'+t($(this).find("ilanTarihi").text())+'</h3><div class="article">'+$(this).find("duyuru").text()+'</div></div>'
							});  
							$('.duyurular').html(s);
						},
						error: function(){$('#debug').append("Duyuru xml hatası")}
					});
					$('.duyurular.liste > .item').live('click',function(){
						document.location='#!duyurular#'+$(this).attr("id");
						b('#!duyurular#'+$(this).attr("id"));
					});					
					$.getJSON('data/lmslink.txt',function(jd) {
						$('#lms-launcher').css({'background-image':'url('+jd[$.random(3)].url+')'});
					})					
					r();
				break;
				case "sss":
					/*$('.stdicerik.sss > .item').each(function(i) {
						$(this).attr("aheight",$(this).height());
						$(this).height($(this).children("h3").height());
						$(this).children("p").fadeOut();
						
						$(this).click(function(){
							if($(this).attr("acik")=="acik") {
								$(this).animate({height:$(this).children("h3").height()});
								$(this).children("p").fadeOut();
								$(this).attr("acik","kapali");
							} else {
								$(this).animate({height:$(this).attr("aheight")});
								$(this).children("p").fadeIn();
								$(this).attr("acik","acik");
							}
						});
					});*/
					r();
				break;
				case "duyurular":
					$.ajax({
						url:'/data/tumDuyurular.xml?'+m(),
						type:'GET',
						dataType:'xml',
						timeout:0,
						success:function(x) {
							var s='',z='';
							$(x).find("tablo").each(function() {
								var q='<div id="'+$(this).find("id").text()+'" class="item"><div class="tarih"><h3>'+t($(this).find("ilanTarihi").text())+'</h3></div><div class="article">'+$(this).find("duyuru").text()+'</div><br clear="all" /></div>';
								if(h==$(this).find("id").text()){z=q;} else {s+=q;}
							});							
							$('.stdicerik.duyurular').html(z+s).text();
							$('html, body').stop().animate({scrollTop:$('.content').offset().top},750);
							if(h) $("#"+h).css({"background":"#f3f3f3"}).children(".tarih").children("h3").css({"color":"#39F"});
							r();
						},
						error: function(){$('#debug').append("Duyuru xml hatası")}
					});	
				break;
				default: r();
			}
		  }
		})
	});
}

function r() {
	$(".content").animate({height:$("#inner").height()+20},100);
	c($(".content"),$("#inner"));
	setTimeout(function(){$("#inner").fadeIn(100);},100);
}

function c(b,a){
	if(b.height()!=a.height()+20) b.animate({height:a.height()+20},100);
	setTimeout(function(){c(b,a)},1000);
}

function m() {
	var tx="",p="abcdefghijklmnopqrstuvwxyz0123456789";
	for(var i=0;i<24;i++) tx+=p.charAt(Math.floor(Math.random()*p.length));
	return tx;
}

function t(d) {
	var b=d.split('/');
	return b[1]+'/'+b[0]+'/'+b[2];
}
