// index sayfasında çalışacak javascript
// uygulamaları 


/* spot alanı için gerekli değişkenler */
var navigation  = true;
var index 		= 0;
var t_count		= 0;
var time 		= 0;
var slide_delay = 1;
var slide_index = 0;

$(document).ready(function(){
	
	/*
	// IE6 Box Hover Caption Style
	if($.browser.version < 7)
	{
		$(".box-caption").hover(
			function(){
				$(this).addClass("iec");
			},
			function(){
				$(this).removeClass("iec");
			}
		)
	}
	*/
	
	// speed 500
	// easing backin
	
	/* röportaj yazısizisi kutusu tabları */
	//$("#r_box > ol").tabs({ event: 'mouseover' });
	// if(!$.browser.msie)
	// {
	
	
		
	var perde_cycle = $('.perde ul').cycle({ 
		fx:      'fade', 
		speed:    100, 
		timeout:  4000,
		cleartype:true,
		pause:1,
		before:function(){ $(".perde ol li.selected").removeClass("selected"); },
		after:function(isNext, index, opts){ $(".perde ol li:nth-child("+(opts.currSlide+1)+")").addClass("selected");}
		
	});

	$(".perde ol li").each(function(i){

		$(this).hover(
		function(){ perde_cycle.cycle("pause"); perde_cycle.cycle(i); $(".perde ol li.selected").removeClass("selected"); $(".perde ol li:nth-child("+(i+1)+")").addClass("selected");},
		function(){ perde_cycle.cycle("resume");}
		)
	})


	
	
	var image_cycle = $(".s-shape span").cycle({ 
	    fx		: 'scrollVert', 
	    speed	: 350, 
	    timeout	: 0,
		easein	: "backin",
		//easeOut	: "backin",
		
		
		//next:"#s-next",
		//prev:"#s-back",
		//prevNextClick:function(isNext, index, element){ change_slide(isNext, index); },
		before:function(){ navigation=false; },
		after:function(isNext, index, opts){ navigation=true; /*$("#slide_pager li.active").removeClass("active"); $("._"+(opts.currSlide+1)).addClass("active") ; slide_index = opts.currSlide+1; index=slide_index;*/   }
	});				

	
	var title_cycle = $(".sum_case").cycle({ 
	    fx		: 'scrollVert', 
	    speed	: 350, 
	    timeout	: 0,
		//next:"#s-next",
		//prev:"#s-back",
		//prevNextClick:function(isNext, index, element){ change_slide(isNext, index); },
		before:function(){ navigation=false; },
		after:function(){ navigation=true; }
		
	});			

	
	var info_cycle = $(".s-info").cycle({ 
	    fx		: 'fade', 
	    speed	: 350, 
	    timeout	: 0,
		before:function(){ navigation=false; },
		after:function(){ navigation=true; }
		
	});			
	
	/* sonraki */
	
	$("#s-next").click(function(){
	
		if(navigation)
		{

			if(index==9) return false; 

			if(index==8)
			$("#s-next").addClass("disabled-next");
			else
			$("#s-next").removeClass("disabled-next");
			
			index += 1;
			
			image_cycle.cycle(index);
			title_cycle.cycle(index);
			info_cycle.cycle(index);
			
			$("#slide_pager li.active").removeClass("active");		
			$("#slide_pager li:nth-child("+(index+1)+")").addClass("active");		
			
			if($("#slide_pager li:nth-child("+(index+1)+")").children("a").hasClass("hot"))
			{
				$("#last-minute-sign").css("display","block");				
			}else{
				$("#last-minute-sign").css("display","none");
			}
			
			$("#s-back").removeClass("disabled-back");
			
		
		}else{
			return false;
		}
	})	
	
	/* önceki */
	
	$("#s-back").click(function(){
	
		if(navigation)
		{
			if(index==0) return false; 

			if(index==1)
			$("#s-back").addClass("disabled-back");
			else
			$("#s-back").removeClass("disabled-back");

			index -= 1;
			
			image_cycle.cycle(index);
			title_cycle.cycle(index);
			info_cycle.cycle(index);
			
			$("#slide_pager li.active").removeClass("active");		
			$("#slide_pager li:nth-child("+(index+1)+")").addClass("active");		

			if($("#slide_pager li:nth-child("+(index+1)+")").children("a").hasClass("hot"))
			{
				$("#last-minute-sign").css("display","block");				
			}else{
				$("#last-minute-sign").css("display","none");
			}
		
			
			$("#s-next").removeClass("disabled-next");
		
		}else{
			return false;
		}
	})
	
	$("#slide_pager li").each(function(i){
		$(this).hover(
			function(){
				slide_index = i;
				time = 0;
				t_count = true;
				
			},
			function(){
				t_count = false;
				time = 0;
				navigation= true;
			}
		)
	})
	
	$(document).everyTime(750, function(){ 
		
		if(t_count) time = time + 750; 
		
		if(time>slide_delay){

			//if(index==0) return false; 
			index = slide_index;
			
			if(index==0)
			{
				$("#s-back").addClass("disabled-back");
				$("#s-next").removeClass("disabled-next");
			}else if(index==9){
				$("#s-back").removeClass("disabled-back");
				$("#s-next").addClass("disabled-next");
			}else{
				$("#s-back").removeClass("disabled-back");
				$("#s-next").removeClass("disabled-next");
			}
			
			image_cycle.cycle(index);
			title_cycle.cycle(index);
			info_cycle.cycle(index);
			
			$("#slide_pager li.active").removeClass("active");		
			$("#slide_pager li:nth-child("+(index+1)+")").addClass("active");		
			
			/* Son dakika haberinin üzerine gelindiğinde 
			 * spot fotoğrafı üzerinde son dakika ibaresi 
			 * görüntülenekece */
			
			if($("#slide_pager li:nth-child("+(index+1)+")").children("a").hasClass("hot"))
			{
				$("#last-minute-sign").css("display","block");				
			}else{
				$("#last-minute-sign").css("display","none");
			}

			
			
			/*
			$(".spot_item").hover(
					function()
					{
						if($(this).hasClass("hot"))
						{
	
						}else{
							
						}
					},
					function()
					{
							// $("#last-minute-sign").css("display","none");
					}
			)	*/		
		
			//$(".target").text(index);
		}else{ }
		//$(".target").text(time);
	})	
	
	

	
	
	
	
	
	//spot_area();
	
	/*
	var authors_index = 0;  
	
	$("#a-next").click(function(){
		if(authors_index >= $("#a_count").val())
			authors_index = 0;
		else{
			
			authors_index = authors_index + 4;
			
			if(authors_index>$("#a_count").val())
				authors_index = 0;
			
		}
	})
	
	
	$("#a-prev").click(function(){
		
		if(authors_index == 0)
		{
		
			var a_count = $("#a_count").val();
			var f = (a_count%4)
			
			authors_index = a_count - f; //$("#a_count").val();
			
			//authors_index = 0;
		}else
			authors_index = authors_index - 4;
	})
	*/
	
	$("#author-bar ul").hide();
	
	
	$("#author-bar").cycle({
		fx:"scrollHorz",
		speed:200,
		timeout:0,
		prev:"#a-prev",
		next:"#a-next",
		before:function(curr, next, opts){
			
			
			/*
			if(isNaN(authors_index)){
				authors_index = 0;
			}
			
			//if(authors_index>=0)
			$(next).load("/yazar/liste/"+authors_index);
			//authors_index  = authors_index + 4;
			*/
		}
	})	
	
	$.post("/yazar/front_box", function(html){
		$("#author-bar").html(html);
		
		$("#author-bar").cycle({
				fx:"scrollHorz",
				speed:200,
				timeout:0,
				prev:"#a-prev",
				next:"#a-next",
				before:function(curr, next, opts){
					
					
					/*
					if(isNaN(authors_index)){
						authors_index = 0;
					}
					
					//if(authors_index>=0)
					$(next).load("/yazar/liste/"+authors_index);
					//authors_index  = authors_index + 4;
					*/
				}
			})		
	})
	
	
	
	
	
	

	
	 // $('.w-list').cycle({fx:'scrollRight', timeout:6000, easing:'slideVer',delay:-2000,pause:1,speed:1600});
	 $('.w-list').cycle({fx:'scrollRight', timeout:6000, easing:'easeinout', delay:-2000, pause:1,speed:600});
	
	/*
	if(!$.browser.msie)
	{
	
		$(".left").sortable({
			connectWith:[".left",".right",".sidebar"],
			revert:true,
			placeholder:"shade",
			tolerance:"tolerance",
			distance:2,
			cursor:"move",
			handle:".box-caption",
			zindex:300,
			opacity:0.95,
			items:".move",
			start:function(e, ui){
				$(".clear").css("overflow","visible");
				$(".left").css("overflow","visible");			
				$(".large").css("overflow","hidden");			
				$(".AD").css("overflow","hidden").css("clear","both");			
				//$(".new-other").css("overflow","visible");
				shade(ui);
			},
			sort:function(e, ui){
				shade(ui);
			},
			stop:function(e, ui)
			{
				$(".clear").css("overflow","hidden");
				$(".left").css("overflow", "hidden");
				$(".large").css("overflow","visible");		
				$(".AD").css("overflow","visible");			
				$(".sidebar div.small").removeClass("small").addClass("medium");
				
				sort_stop("#C1");
				sort_stop("#C2");
				//weather_stop(ui);
				personal_box_save();
			}
		});	
		 
	
		// içerik alanının sağ tarafında bulunan kutular
		
		$(".right").sortable({
			connectWith:[".right",".left",".sidebar"],
			revert:true,
			tolerance:"tolerance",
			distance:2,
			placeholder:"shade",
			cursor:"move",
			handle:".box-caption",
			opacity:0.95,
			items:".move",
			//	tolerance:"pointer",
			//zindex:300,
			start:function(e, ui){
				$(".clear").css("overflow","visible");
				$(".right").css("overflow","visible");			
				$(".large").css("overflow","hidden");	
				$(".sidebar div.small").removeClass("medium").addClass("small");	
				$(".AD").css("overflow","hidden").css("clear","both");			
				shade(ui);			
			},
			sort:function(e, ui){
				shade(ui);
			},		
			stop:function(e, ui)
			{
				$(".clear").css("overflow","hidden");
				$(".right").css("overflow", "hidden");
				$(".large").css("overflow","visible");	
				$(".AD").css("overflow","visible");			
				$(".sidebar div.small").removeClass("small").addClass("medium");	
				
				sort_stop("#C1");
				sort_stop("#C2");
				personal_box_save();
			}		
		});
	
		$(".sidebar").sortable({
			connectWith:[".left",".right"],
			revert:true,
			placeholder:"shade",
			cursor:"move",
			handle:".box-caption",
			tolerance:"tolerance",
			distance:2,
			zindex:300,
			opacity:0.95,
			items:".move",
			//tolerance:"pointer",
			start:function(e, ui){
				$(".left").css("overflow","visible");			
				$(".large").css("overflow","hidden");	
				shade(ui);			
			},
			sort:function(e, ui){
				shade(ui);
			},		
			stop:function(e, ui)
			{
				$(".left").css("overflow", "hidden");
				$(".large").css("overflow","visible");		
				$(".container div.medium").removeClass("medium").addClass("small");	
				personal_box_save();
			}		
		});	
	
	
	
		$(".gv").hover(
			function(){
				$(this).attr("src","http://77.92.133.72/images/layout/gvh.gif");
			},
			function(){
				$(this).attr("src","http://77.92.133.72/images/layout/gv.gif");
			}
		);	
		
		$(".ga").hover(
			function(){
				$(this).attr("src","http://77.92.133.72/images/layout/gah.gif");
			},
			function(){
				$(this).attr("src","http://77.92.133.72/images/layout/ga.gif");
			}
		);	

		
		//	$(".sum_case").cycle({ fx:     'scrollVert', speed:  'fast', timeout: 0, pager:'#slide_pager',pagerEvent: 'mouseover',pagerAnchorBuilder: function(idx, slide) { return '<li><a href="#">asd</a></li>'; }		});
				
	
	
		// menu altındaki haber geçişleri
		
	
	}
	*/

	
	// hot_news();
	
	// başlangıçta da left ve right eşit olsun 
	
	sort_stop("#C1");
	sort_stop("#C2");	
	
	
	
	$("#e-graphic").click(function(){
		
		$(this).parent().addClass("active");
		
		$("#e-text").parent().removeClass("active");
		
		$("#e-graphic-div").css("display","block");
		$("#e-text-div").css("display","none").parent().removeClass("active");
		
	})

	$("#e-text").click(function(){
		$(this).parent().addClass("active");
		$("#e-graphic").parent().removeClass("active");
		$("#e-text-div").css("display","block");
		$("#e-graphic-div").css("display","none");
	})

	
	
	/* röportaj akordiyon */
	$("#r_box a.t1").click(function(){
		$("#alan-1, #alan-2, #alan-3").css("display","none");
		
		
		$("#r_box li.active").removeClass("active");
		$(this).parent().addClass("active");
		
		$("#alan-1").css("display","block");
	})
	/* röportaj akordiyon */
	$("#r_box a.t2").click(function(){
		$("#alan-1, #alan-2, #alan-3").css("display","none");
		
		$("#r_box li.active").removeClass("active");
		$(this).parent().addClass("active");
		
		$("#alan-2").css("display","block");
	})
	/* röportaj akordiyon */
	$("#r_box a.t3").click(function(){
		$("#alan-1, #alan-2, #alan-3").css("display","none");
		
		$("#r_box li.active").removeClass("active");
		$(this).parent().addClass("active");
		
		$("#alan-3").css("display","block");
	})

	// personal_box_load();
	
	sort_stop("#C1");
	sort_stop("#C2");	
})


function todays_authors()
{
	
	$(".a-tab li.active").removeClass("active");
	$(".a-tab li:nth-child(1)").addClass("active");
	
	$("#author-list").css("display","block");
	$("#my-authors").css("display","none");
}

function my_authors()
{
	$(".a-tab li.active").removeClass("active");
	$(".a-tab li:nth-child(2)").addClass("active");
	$("#author-list").css("display","none");
	$("#my-authors").css("display","block");
}



function authors_list_jump_menu(element){

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


/* Röportaj yazı dizisi ve özel dosyaların olduğu kutu */
function reportage_box()
{

	
}


// alico bunlar sadece ana sayfada commondan cıkardim ...

/* Taşınan kutuların altına shade divi atıyor */


function shade(ui)
{
	var width = $(ui.placeholder).parent();
	
	if($(ui.item).hasClass("mini")){
		
		$(ui.placeholder).html("<b><b><b></b></b></b>");
	}else{
		var h = $(ui.item).height();
		var c = ' style="height:'+h+'px"';
		$(ui.placeholder).html("<b><b><b"+c+">&nbsp;</b></b></b>");
	}
}


/* taşıma işlemi bitiyor */

function sort_stop(element)
{
	
	
	
	// sol ve sağ alanın yüksekliğini hesapla 
	$(element+" .left").css("min-height","1px");
	$(element+" .right").css("min-height","1px");
	
	var lh = $(element+" .left").height();
	var rh = $(element+" .right").height();

	if(lh>rh) 
		var ch = lh;
	else
		var ch = rh;
	
	$(element+" .left").css("min-height",ch+"px");
	$(element+" .right").css("min-height",ch+"px");

	$(".move .box-caption").hover(
		function(){
			var cl = $(this).parent().parent().hasClass("small");
			
			if(cl)
				$(this).parent().parent().addClass("small-hover");
			else
				$(this).parent().parent().addClass("medium-hover");
			
		},
		function(){
		
			var cl = $(this).parent().parent().hasClass("small");
			
			if(cl)
				$(this).parent().parent().removeClass("small-hover");
			else
				$(this).parent().parent().removeClass("medium-hover");
		}
	)
}



/* spottaki hover olayı */
function change_spot(nth){

	/*	
	$(".post_summary").css("display", "none");
	$("#post_"+id).css("display", "block");
	*/
	$(".sum_case div").css("display","none");
	$(".sum_case div:nth-child("+nth+")").css("display","block");

	$(".l div").css("display","none");
	$(".l div:nth-child("+nth+")").css("display","block");
}


/* haber kutusunda daha fazla haber göster */
function more_news(element)
{
	
	var ul 		= $(element).parent().parent().parent().next("ul");
	var open 	= 0; 
	var close 	= 0; 
	
	$(ul).children("li").each(function(){
		if($(this).css("display")!="none")
		{
			open = open + 1;
		}else{
			close = close + 1;
		}
	})

	if(close<12){
		open = open + 1;
		$(ul).children("li:nth-child("+open+")").show(fx_speed);
	}
}


/* daha az haber göster */
function less_news(element)
{	
	var ul 		= $(element).parent().parent().parent().next("ul");
	var open 	= 0; 
	var close 	= 0; 
	
	$(ul).children("li").each(function(){
		if($(this).css("display")!="none")
		{
			open = open + 1;
		}
	})

	if(open>1)
	$(ul).children("li:nth-child("+open+")").hide(fx_speed);
}

/* spot alanı */
function spot_area()
{
	$(".spot_1").css("display","block").addClass("active_spot");

	$(".spot_item").hover(
			function(){
				
				
				var cl = $(this).parent().attr("class");
				
				$(".active_spot").css("display","none").removeClass("active_spot");
				$(".spot"+cl).css("display","block").addClass("active_spot");
				
			},
			function()
			{
				
			}
				
	)
	
	
	
}


