/* global değerler */
var fx_speed	= 100;
var headline_in	= 5000; // "yeni" alanındaki haberlerin geçiş süresi
var c_headline	= 1;	// "yeni" alanında giriş anındaki haber


/* hot news alanı için değerler */
var t = 0;	// hot_news için timer
var i = 1;	// hot_news için index
var l = 10;	// hot_news için limit

var hot_hover = false;

/* haber detay değerleri */
var type_size = 13;

/* akordiyon kutusu */
function accordion()
{
	/* akordiyon içindeki he lere basılınca */
	$(".a_title").click(function(){
		
		/* önce açık olanı kapat */
		$(".a_title").parent("li.active").removeClass("active").children("ol, .tab").css("display","none");
		
		/* daha sonra basılanı aç */
		$(this).parent("li").addClass("active").children("ol, .tab, .tab > span").css("display","block");
	})

}

/* tavsiye et */
function popup(page, id)
{
	var w = 540; 
	var h = 525; 
	var l = (screen.width - w ) / 2; 
	var t = (screen.height - h ) / 2;
	
    window.open(page+id,'','top='+t+', left='+l+', height='+h+' , width='+w);
}


// document.ready
$(document).ready(function(){
	

	//$(".header .submit").val="";
	
	$("#h_search .submit").val("");
	
	$(".s_post").click(function(){
		$("a.active").removeClass("active");
		$(this).addClass("active");
		
		$("#h_search").attr("action","/ara");
		$("#h_search input[disabled=disabled]").removeAttr("disabled");
		$("#h_search input[name=tip]").attr("value","-");
		
		
	})

	$(".s_video").click(function(){
		$("a.active").removeClass("active");
		$(this).addClass("active");
		
		
		$("#h_search").attr("action","http://multimedya.milligazete.com.tr/multimedya/ara");
		$("#h_search input[name=nerede]").attr("disabled","disabled");
		$("#h_search input[name=nasil]").attr("disabled","disabled");
		$("#h_search input[name=gorunum]").attr("disabled","disabled");
		$("#h_search input[name=arsiv]").attr("disabled","disabled");
		$("#h_search input[name=tip]").attr("value","video");
	})

	$(".s_image").click(function(){
		$("a.active").removeClass("active");
		$(this).addClass("active");
		
		$("#h_search").attr("action","http://multimedya.milligazete.com.tr/multimedya/ara");
		$("#h_search input[name=nerede]").attr("disabled","disabled");
		$("#h_search input[name=nasil]").attr("disabled","disabled");
		$("#h_search input[name=gorunum]").attr("disabled","disabled");
		$("#h_search input[name=arsiv]").attr("disabled","disabled");
		$("#h_search input[name=tip]").attr("value","fotograf");
		
	})
	
	
	
	$(".nb .back").hover(
		
		function(){
			$(".nb span b").addClass("mb").fadeIn(200);
		},
		function(){
			$(".nb span b").removeClass("mb");
		}
	)
	
	$(".nb .next").hover(
		
		function(){
			$(".nb span b").addClass("mn").fadeIn(200);;
		},
		function(){
			$(".nb span b").removeClass("mn");
		}
	)
	
	accordion();
	
	
	$(".target").hover(
		function(){
			hot_hover = true;	
		},
		function(){
			hot_hover = false;
		}
	);
	
	hot_news();
	
	
	$(".login").load("/account");
	
})



function mesaj(){
	alert('Bu bölüm geliştiriliyor');
}

// Global fonksiyonlar --------------------------------------------------------

/* haber kutularının minimize maximize işlemi */
function box_resize(element)
{
	var box = $(element).parent().parent().parent().parent();
	
	if($(box).hasClass("mini"))
	{
		
		/* kutu açılıyor */
		$.post("/boxservice/box_resize", {move:"open", id:$(box).attr("id")}, function(html){
			
		});
		
		//$(element).css("background-image","url(/images/layout/show_hide.gif)");				
		$(element).removeClass("open");				
		$(element).attr("title","Ac");				
		
		$(box).children().children(".box-body").slideDown(fx_speed, function(){
			sort_stop("#C1");
			sort_stop("#C2");			
		});
		$(box).removeClass("mini");
		
	}else{

		/* kutu açılıyor */
		$.post("/boxservice/box_resize", {move:"close", id:$(box).attr("id")}, function(html){
			
		});
		
		
		//$(element).css("background-image","url(/images/layout/show_hidden.gif)");				
		$(element).addClass("open");				
		$(element).attr("title","Kapa");
		$(box).children().children(".box-body").slideUp(fx_speed, function(){
			sort_stop("#C1");
			sort_stop("#C2");	
		});
		$(box).addClass("mini");
		
		//$(box).parent().css("min-height","0");
	}

}




/* gündemdeki haberleri hızlıca gösteren alan */	
function hot_news()
{
	
	//return false;
	l = $("#hot_count").val();
	
	$("#hot_news_area").everyTime(3000, function(){


		
		// $(this).children("li").css("display","none");
		//$(".target").css("display","none");
		$(".target").css("display","none").removeClass("active");
		$(".hot_"+i).css("display","block").addClass("active");
	  
	  	
	//	$(".hot_1").css("display","block");
		
		
		/* sıralamayı değiştir */
		if(i<l)
			i++;
		else
			i = 1;
		
	});
	
	
	//$(".hot_1").css("display","block");
	
	/*
	
	return false;
	
	if($.browser.msie)
	{
		return false;
		$(".target").everyTime(100, function(){
			if(hot_hover==1) return true;
			if(t>200)
			{
				i++;
				if(i==(l+1))i=1
				t=1;
			}
			var str = hotnews[i][0]; //$(".source li:nth-child("+i+") a").text();
			var url = hotnews[i][1]; //$(".source li:nth-child("+i+") a").attr("href");
			var len = str.length + 1;  
			
			if(t < len)
			{
				var target = str.substring(0, t);
				
				$(this).html("<a href='"+url+"'>"+target+"</a>");
			}else{
				$(this).html("<a href='"+url+"'>"+str+"</a>");
			}
			//alert("asd");
			t++;		
		})		
		
		
		
	}else{
		
		$(".target").everyTime(10, function(){
			if(hot_hover==1) return true;
			if(t>300)
			{
				i++;
				if(i==(l+1))i=1
				t=1;
			}
			var str = hotnews[i][0]; //$(".source li:nth-child("+i+") a").text();
			var url = hotnews[i][1]; //$(".source li:nth-child("+i+") a").attr("href");
			var len = str.length + 1;  
			
			if(t < len)
			{
				var target = str.substring(0, t);
				
				$(this).html("<a href='"+url+"'>"+target+"</a>");
			}else{
				$(this).html("<a href='"+url+"'>"+str+"</a>");
			}
			//alert("asd");
			t++;		
		})		
	}*/
	

}

// önceki haber
function hot_news_back()
{
	t = 0;
	i--;
	if(i<1) i=l;
	$(".target").css("display","none").removeClass("active");
	$(".hot_"+i).css("display","block").addClass("active");
}

// sonraki haber 
function hot_news_next()
{
	t = 0;
	i++;
	if(i>l) i=1;
	$(".target").css("display","none").removeClass("active");
	$(".hot_"+i).css("display","block").addClass("active");
}




/* yazı detayındaki içeriğin puntosunu büyütüyor */
function type_increase(){
	
	var curr_size = "pmedium";
	
	$(".post-up-nav span a").removeClass("disabled");
	
	if($(".text-content").hasClass("pmedium")){ curr_size = "plarge";  $(this).attr("class","disabled"); }
	if($(".text-content").hasClass("psmall")) {	curr_size = "pmedium"; $(".post-up-nav span a.m").attr("class","disabled");}
	if($(".text-content").hasClass("plarge")){ 	curr_size = "plarge"; $(this).attr("class","disabled");}
	
	$(".text-content").attr("class","news-content text-content "+curr_size);
	

	$(".s").removeClass("disabled");
	if(curr_size=="plarge")
	{
		$(".l").addClass("disabled");
	}

	
	/*
	var font_size = parseInt($(".news-content p[class!=sum]").css("font-size"));

	if(font_size>17) return false;  
	
	font_size += 1;
		
	$(".news-content p").css("font-size", font_size+"px");
	$(".news-content p").css("line-height", font_size+5+"px");
	
	$(".news-content p.sum").css("font-size", font_size+1+"px");
	*/
}

/* yazı detayındaki içeriğin puntosunu küçültür */
function type_decrease(){

	var curr_size = "pmedium";
	
	if($(".text-content").hasClass("pmedium"))	curr_size = "psmall";	
	if($(".text-content").hasClass("psmall")) 	curr_size = "psmall";	
	if($(".text-content").hasClass("plarge")) 	curr_size = "pmedium";	
	
	$(".text-content").attr("class","news-content text-content "+curr_size);
	
	$(".l").removeClass("disabled");
	if(curr_size=="psmall")
	{
		$(".s").addClass("disabled");
	}
	
	
	/*
	var font_size = parseInt($(".news-content p[class!=sum]").css("font-size"));
	
	if(font_size<13) return false;  
	
	font_size -= 1;
	
	$(".news-content p").css("font-size", font_size+"px");
	$(".news-content p").css("line-height", font_size+5+"px");
	
	$(".news-content p.sum").css("font-size", font_size+1+"px");
	*/
}


function type_default(){
	$(".text-content").attr("class","news-content text-content pmedium");
	
	$(".s").removeClass("disabled");
	$(".l").removeClass("disabled");
}


/* sayfanın yazılabilir halini yapacak */
function print_page(id){
	window.open("/haber/yazdir/"+id, null,"top=100,left=250,height=600,width=800,scrollbars=yes,status=yes,toolbar=yes,menubar=yes,location=no");
}

/* post caption yükseklik ayarı */

function set_heights()
{
	var news_cap=$(".post-caption h1").height();
	
	if($.browser.msie==false) $(".post-caption h1").css('min-height','40px');	
	
	if(news_cap < 41){
		
		if($.browser.safari==true){
			
			$(".post-caption p span").css('height','44px');
		}
		
		if($.browser.msie==true){
			
			$(".post-caption p span").css('height','auto');
			$(".post-caption p span").css('padding-top','18px');
		}
		
	}
	else{
		
		$(".post-caption h1").css('padding-top','0');
		
		if($.browser.safari==true){
			news_cap=(news_cap-6)
			$(".post-caption p span").css('height',news_cap+'px');
		}
		else
		{
			if($.browser.msie==true){
			
				$(".post-caption p span").css('height','auto');
				news_cap=(news_cap-26)
				$(".post-caption p span").css('padding-top',news_cap+'px');
			}
			else
			{
				$(".post-caption p span").css('height',news_cap+'px');
			}
		}
		
	}

}


function set_heights_dual()
{
	var news_cap=$(".post-caption h1").height();
	
	if($.browser.msie==false) $(".post-caption h1").css('min-height','64px');
	
	if(news_cap > 66){
		
		$(".dual h1").css('padding-top','0');
		$(".dual p span").css('height',(news_cap-12)+'px');
		$(".dual p span").css('padding-top','12px');
	}
	else
	{
		
	}
	
	/*if(news_cap < 64){ // varsayılan h1 yüksekligi 64 kucuk ıse
		
		if($.browser.safari==true){ // browser safari ise
			
			$(".post-caption p span").css('height','44px'); // height 
		}
		
		if($.browser.msie==true){ // ie ise
			
			$(".post-caption p span").css('height','auto');
			$(".post-caption p span").css('padding-top','5px');
		}
		
	}
	else{
		
		$(".post-caption h1").css('padding-top','0');
		
		if($.browser.safari==true){
			news_cap=(news_cap-6)
			$(".post-caption p span").css('height',news_cap+'px');
		}
		else
		{
			if($.browser.msie==true){
			
				$(".post-caption p span").css('height','auto');
				news_cap=(news_cap-26)
				$(".post-caption p span").css('padding-top',news_cap+'px');
			}
			else
			{
				$(".post-caption p span").css('height',news_cap+'px');
			}
		}
		
	}*/

}


function postnavbar(){

	$(".post-up-nav li:last").addClass("last");
}

function authors_list_jump_menu(element){

	window.location = $(element).val();
}

/* çerez oluştur */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/* çerez oku */
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/* çerez sil */
function eraseCookie(name) {
	createCookie(name,"",-1);
}

