// JavaScript Document

var CURRENT_PAGE_NUMBER = 1;
function getTvPage(pagenumber)
{
	$.ajax({
		type:"POST",
		url:"/p/GetTvRecords.asp",
		data:{"page_size":"4","page_index":pagenumber},
		beforeSend:function(){
			$(".tv-inner").append("<div class='load'><img src='i/Assets/images/loader.gif' /><p>Yükleniyor</p></div>");
		},
		success:function(msg){ 
			$(".load").remove();
			$(".tv-inner").append(msg);
			$(".pagertv").append("<ul></ul>");
			var pagecount = $(".pagertv").attr("rel");
			var pagenumber = Math.ceil(pagecount / 4);
			var pageread = pagenumber / pagenumber;
			var activeClassStr = ""
			for (pageread;pageread<=pagenumber;pageread++)
			{
				 
				activeClassStr = CURRENT_PAGE_NUMBER == pageread ? "class='active'":"";
				
				$(".pagertv ul").append('<li><a rel='+ pageread +' '+activeClassStr+' href="#">'+ pageread +'</a></li>');
			}
		}
	});
}


$(document).ready(function(){
 URLEncode($("div.bottom-share li.share-twitter a, div.organization-share li.share-twitter a"));

	$(".organization .box a[rel^='prettyPhoto']").each(function(i) {
		$(this).prettyPhoto({deeplinking: false,theme:'facebook'});
   	});
	$(".news-item-container a[rel^='prettyPhoto']").each(function(i){
		$(this).prettyPhoto({deeplinking: false, theme:'facebook' });	
	});
	$(".logo-box a[rel^='prettyPhoto']").each(function(i){
		$(this).prettyPhoto({theme:'facebook'});
	});
	$("a [rel^='prettyPhoto']").each(function(i){
		$(this).prettyPhoto({deeplinking: false, theme:'facebook'});
	});
	
	$("a.watch").live("click",function(){      
			$("a.watch[rel^='prettyPhoto']").prettyPhoto({deeplinking: false, theme:'facebook'});
		return false;
	});
	getTvPage(1);
	
	$(".pagertv ul li a").live("click",function(){
			var pageup = $(this).attr("rel");
			CURRENT_PAGE_NUMBER = pageup;
			$(".tv-inner").html("");
			getTvPage(pageup);
			return false;
	});
						   
	//$(".bottom-share ul li.share-facebook a").attr("href","http://www.facebook.com/share.php?v=4&src=bm&u=" + window.location.href);
	//$(".bottom-share ul li.share-facebook a").attr("onclick","window.open(this.href,'sharer','toolbar=0,status=0,width=626,height=436'); return false;");
	//$(".bottom-share ul li.share-twitter a").attr("href","http://www.twitter.com/?status=" + $(".press-top-head h2").text() + "" + window.location.href);
	$(".bottom-share ul li.share-facebook a").attr({
			"href":	"http://www.facebook.com/share.php?v=4&src=bm&u=" + window.location.href,
			"onClick":"window.open(this.href,'sharer','toolbar=0,status=0,width=626,height=436'); return false;"
	});	
	
	
	$("div.element ul li a").click(function(){
		if($(this).parents("li:eq(0)").hasClass("active"))
		{
			$("div.element ul li.active").children(".ac-all").slideToggle(300);
			$("div.element ul li.active").removeClass("active");
		}
		else
		{
			$("div.element ul li.active").children(".ac-all").slideToggle(300);
			$("div.element ul li.active").removeClass("active");
			$(this).parents("li:eq(0)").addClass("active");
			$(this).parents("li:eq(0)").children(".ac-all").slideToggle(300);
		}
		return false;
	});
	$(".togglebottom").live("click",function(){
		$("div.element ul li.active").children(".ac-all").slideToggle(300);
		$("div.element ul li.active").removeClass("active");
	});
	
	$("div.phone-element ul li a.phn-toggle").click(function(){
		if($(this).parents("li:eq(0)").hasClass("active"))
		{
			$("div.phone-element ul li.active").children(".phn-acc").slideToggle(300);
			$("div.phone-element ul li.active").removeClass("active");
		}
		else
		{
			$("div.phone-element ul li.active").children(".phn-acc").slideToggle(300);
			$("div.phone-element ul li.active").removeClass("active");
			$(this).parents("li:eq(0)").addClass("active");
			$(this).parents("li:eq(0)").children(".phn-acc").slideToggle(300);
		}
		return false;
	});
	
	$(".phn-togglebottom").live("click",function(){
		$("div.phone-element ul li.active").children(".phn-acc").slideToggle(300);
		$("div.phone-element ul li.active").removeClass("active");
	});
	
	$("#tab-ac ul li a").click(function(){
		var index = $(".tab-cards ul li a").index($(this));
		$(".tab-cards ul li a.active").removeClass("active");
		$(".tab-cards ul li a").eq(index).addClass("active");
		$(".tab-nav div.tab-text").css("display","none");
		$(".tab-nav div.tab-text").eq(index).css("display","block");
	})
	
	/*
	$(".cards-list a").live("click",function(){
		var index = $(this).attr("rel");
		$(".cards-list a.active").removeClass();
		$(this).addClass("active").addClass(index);
		Cufon.refresh();
		$(".cards div.card-text").css("display","none");
		$("div.card-text[title='" + index + "']").css("display","block");
		return false;
	});
	*/
	
	$(".cards-list a").hover(function(){
		var index = $(this).attr("rel");
		$(".cards-list a.active").removeClass();
		$(this).addClass("active").addClass(index);
		Cufon.refresh();
		$(".cards div.card-text").css("display","none");
		$("div.card-text[title='" + index + "']").css("display","block");
		return false;						  
	},function(){
		
	})
	
	/*setTimeout('$(".tabs-text").height($(".spec-tab[open=open]").height())', 500);*/
	/*
	$("div#breadcrumb ul li.li_start a").css({
		background: 'none',
		padding: 0,
		paddingRight: 10
	});
	*/
	var slider4 = $("#news-slider").Slider({
		duration:700,
		width: 270,
		Mask: '.news-slider-mask',
		ItemContainer: '.news-item-container',
		Item: '.cnt',
		LeftArrow: '.cnt-left',
		RightArrow: '.cnt-right',
		AutoSlide: 'on',
		AutoSlideTime: 5000
	});	

	$("#search, #search-inner").focus(function () {
        if ($(this).val() == "ara") {
            $(this).val("");
        }
    });
    $("#search, #search-inner").blur(function () {
        if ($(this).val() == "") {
            $(this).val("ara");
        }
    });	

	$("#en #search, #en #search-inner").focus(function () {
        if ($(this).val() == "search") {
            $(this).val("");
        }
    });
    $("#en #search, #en #search-inner").blur(function () {
        if ($(this).val() == "") {
            $(this).val("search");
        }
    });	
	
	$(".print-media a[rel=''], .ac-inner img[rel='']").hide();

/* main menu */
    $('#content .nav-menu ul li').hover(
        function () {
            //show its submenu
            $('ul', this).fadeIn("slow");
        },
        function () {
            //hide its submenu
            $('ul', this).fadeOut("slow");        
        }
    );
	
	$('.contact-main').wrapInner('<div class="mainInner" />');
	$('.contact-main:odd').css("margin-left",9);
	$('.contact-main:nth-child(2n)').after("<br class=\"clear\" />");

});

function URLEncode(object){
var url = encodeURIComponent(document.title+" - "+window.location.href);
$(object).attr("href","http://twitter.com/home?status="+url);
return false;
};
