/*
*	@JavaScript Dosyası
*	@Tayfun Erbilen
*/

$(function(){

	$("#kategoriler ul li").hover(function(){
		$(this).animate({backgroundColor: "#f1f1f1"}, "fast");
	}, function(){
		$(this).animate({backgroundColor: "#fff"}, "fast");
	});
	
	$("#etiketler a").hover(function(){
		$(this).animate({backgroundColor: "#f3f6e8"}, "fast");
	}, function(){
		$(this).animate({backgroundColor: "#fff"}, "fast");
	});
	
	$(".copyright a").hover(function(){
		$(this).animate({backgroundColor: "#000", color: "#fff"}, "fast").css("text-shadow","none");
	}, function(){
		$(this).animate({backgroundColor: "#f1f1f1", color: "#656565"}, "fast");
	});
	
	$(".solVideoListe li a").hover(function(){
		$("span.vlSure", this).animate({marginRight : "-40px"}, 230);
		$("span.vlPlay", this).fadeIn(230);
	}, function(){
		$("span.vlSure", this).animate({marginRight : "0"}, 230);
		$("span.vlPlay", this).fadeOut(230);
	});
	
	$("#KanaLsolVideoListe li a").hover(function(){
		$("span.vlSure", this).animate({marginRight : "-70px"}, 230);
		$("span.vlPlay", this).fadeIn(200);
	}, function(){
		$("span.vlSure", this).animate({marginRight : "0"}, 230);
		$("span.vlPlay", this).fadeOut(230);
	});
	
	$("#girisYap").click(function(){
		var ekranYukseklik = $(window).height()/4;
		$("body").prepend('<div id="karart"></div>');
		$("#girisForm").animate({top: ekranYukseklik+"px"}, 500);
	});
	
	$("#karart").live("click", function(){
		$(this).fadeOut();
		$("#girisForm").animate({top: "-400px"}, 300);
	});
	
	/* Tipsy */
	$("[rel=_senizle]").tipsy({gravity: 's'});
	
	var videoDeger = 0;
	$("#genislet").click(function(){
		if (videoDeger == 0){
			$("#sag").animate({marginTop : "506px"});
			$("#player").delay(100).animate({width : "950px", height: "450px"});
			$(".videoBlok h2").delay(100).animate({width : "950px"});
				$(".videoBlok h2 span").text("Videoyu Küçült");
			videoDeger++;
		}else {
			$("#player").animate({width: "690px", height: "300px"});
			$(".videoBlok h2").animate({width : "690px"});
				$(".videoBlok h2 span").text("Videoyu Genişlet");
			$("#sag").delay(130).animate({marginTop : "0"});
			videoDeger = 0;
		}
	});
	
	$("#yorumYap textarea").click(function(){
		$(this).animate({height: "60px"}, 350);
		$("#yGonder").fadeIn();
		$("#yYapan").fadeIn();
	});
	
	$("#yGonder span").click(function(){
		$("#yorumYap textarea").animate({height: "15px"}, 350);
		$("#yGonder").hide();
		$("#yYapan").hide();
	});
	
	$(".yorum").hover(function(){
		$(".cevapla", this).show();
	}, function(){
		$(".cevapla", this).hide();
	});
	
	$(".cevapla").click(function(){
		var kim = $(this).next("strong").text();
		$(this).parent().next(".yorumaYorumYap").slideDown();
		$(this).parent().next(".yorumaYorumYap").find("textarea").val(kim + ", ");
	});
	
	$(".yyyGizli span").click(function(){
		$(this).parent().parent().slideUp();
	});
	
	$(".alt_yorum:even").css("background-color","#f1f1f1");
	
	$("#formKapat").click(function(){
		$("#karart").fadeOut();
		$("#girisForm").animate({top: "-400px"}, 300);
	});

});


/*
	* Progress Bar 
	* Astald
*/
$(document).ready(function(){
    jQuery.fn.anim_progressbar = function (aOptions) {
        // def values
        var Sure = 1500;
        var iCms = 1000;
        var iMms = 60 * Sure;
        var iHms = 3600 * Sure;
        var iDms = 24 * 3600 * Sure;

        // def options
        var aDefOpts = {
            start: new Date(), // now
            finish: new Date().setTime(new Date().getTime() + 60 * Sure), // now + 60 sec
            interval: 100
        }
        var aOpts = jQuery.extend(aDefOpts, aOptions);
        var vPb = this;

        // each progress bar
        return this.each(
            function() {
                var iDuration = aOpts.finish - aOpts.start;

                // calling original progressbar
                $(vPb).children('.pbar').progressbar();

                // looping process
                var vInterval = setInterval(
                    function(){
                        var iLeftMs = aOpts.finish - new Date(); // left time in MS
                        var iElapsedMs = new Date() - aOpts.start, // elapsed time in MS
                            iDays = parseInt(iLeftMs / iDms), // elapsed days
                            iHours = parseInt((iLeftMs - (iDays * iDms)) / iHms), // elapsed hours
                            iMin = parseInt((iLeftMs - (iDays * iDms) - (iHours * iHms)) / iMms), // elapsed minutes
                            iSec = parseInt((iLeftMs - (iDays * iDms) - (iMin * iMms) - (iHours * iHms)) / Sure), // elapsed seconds
                            iPerc = (iElapsedMs > 0) ? iElapsedMs / iDuration * 100 : 0; // percentages

                        // display current positions and progress
                        $(vPb).children('.percent').html('Durum: <b>'+iPerc.toFixed(1)+'%</b>');
                        $(vPb).children('.elapsed').html('Tahmini Süre:  <b>'+iSec+' Saniye kaldı</b>'); /* iDays+' days '+iHours+'h:'+iMin+'m:' */
                        $(vPb).children('.pbar').children('.ui-progressbar-value').css('width', iPerc+'%');

                        // in case of Finish
                        if (iPerc >= 100) {
                            clearInterval(vInterval);
                            $(vPb).children('.percent').html('<b>100% Tamamlandı</b>');
                            $(vPb).children('.elapsed').html('<br/>'); //.html('<b>Bitti</b>');//
                        }
                    } ,aOpts.interval
                );
            }
        );
    }

    // default mode
    $('#progress1').anim_progressbar();

    // from second #5 till 15
    var iNow = new Date().setTime(new Date().getTime() + 5 * 1000); // now plus 5 secs
    var iEnd = new Date().setTime(new Date().getTime() + 15 * 1000); // now plus 15 secs
    $('#progress2').anim_progressbar({start: iNow, finish: iEnd, interval: 100});

    // we will just set interval of updating to 1 sec
    $('#progress3').anim_progressbar({interval: 1000});
});
