/**
 * Nette Technologies | www.nette.com.tr
 * 03-2011
 */

// sayfa açılınca üst menü altında bu hrefe sahip olan current yapılacaktır.
var _umAltSeciliHref = "";

Cufon.replace
	(
		[
            ".cufonPrp",
            ".othersBoxArea span"
		],
		{
			hover: true,
            fontFamily: "PF Reminder Pro"
		}
	);

/* Common */
var msie6 = $.browser.msie && $.browser.version<7 ? true : false;
var usrckie='';
$().ready(function(){
    
    $(".header_quicklinks .main")
		.dropdownize({menuEl: ".hqMenu"})
		.click(function (){ return false; });
            
    if (_umAltSeciliHref != "") {
        $(".categoriMenuBottom a[href='"+_umAltSeciliHref+"']").addClass("current");
    }
    
    var headID = document.getElementsByTagName("head")[0];         
    var cssNode = document.createElement('link');
    cssNode.type = 'text/css';
    cssNode.rel = 'stylesheet';
    cssNode.href = _staticPath+'css/style-nonvalid.css';
    cssNode.media = 'screen';
    headID.appendChild(cssNode);

    usrckie = getCookie('usrckie');if(usrckie==''||usrckie==undefined){usrckie=randomString(45);setCookie('usrckie',usrckie,365);}
    if(msie6){ $('body').addClass('msie6'); }
    
    /**
     * VideoPlay
     */
    var playimg = '<span class="playimg">Play</span>';
    var lis = $('a.vp');
    var img = null;
    var liPos = null;
    var imgPos = null;
    for (i=0;i<lis.length;i++) {
        img = $(lis[i]).find('img');
        h = img.height();
        l = Math.round((img.width()  - 30) / 2) + parseInt(img.css('paddingLeft'), 10) + parseInt(img.css('borderLeftWidth'), 10);
        t = Math.round((img.height() - 30) / 2) + parseInt(img.css('paddingTop'), 10) +  parseInt(img.css('borderTopWidth'), 10);
        $(lis[i]).css('position','relative').append(playimg);
        $(lis[i]).find('span.playimg').css({'top':t,'left':l});
    }

    $('span.playimg').fadeTo('fast',0.65);
    $('a.vp').hover(function(){ $(this).find('span.playimg').fadeTo('fast',1); },function(){ $(this).find('span.playimg').fadeTo('fast',0.65); });

    /**
     * Rotators
     */
    var RotaPlays=[],RotaPlay=true;
    var rotors = $("div.rotor");
    for (i=0;i<rotors.length;i++){
        $(rotors[i]).addClass('rotors'+i);
        var visible = Number($('.rotors'+i+' .rotormain ul').attr('class'));
        var elCount = $('.rotors'+i+' .rotormain li').size();
        if (!isNaN(visible) && elCount > visible) {
            var scroll = 1;
            var speed = 500;
            var auto = true;
            var timeout = 4e3;
            if ($(rotors[i]).find(".vizyonBoxCarusel").size() > 0) {
                timeout = 3e3;
            }
            var mouseWheel = false;
            if ($(rotors[i]).hasClass("rotorMwheel")) {
                mouseWheel = true;
            }
            $('.rotors'+i+' .rotormain').jCarouselLite({
                 btnNext:".rotors"+i+" a.next"
                ,btnPrev:".rotors"+i+" a.prev"
                ,speed:speed
                ,mouseWheel:mouseWheel
                ,vertical:false
                ,visible:visible
                ,auto:auto
                ,timeout:timeout
                ,circular:true
                ,scroll:scroll
            });
            if( $('.rotors'+i+' .rotormain ul').attr('title')=='otoplay' ){
                RotaPlays.push(".rotors"+i+" a.next");
            }
            $('.rotors'+i+' .rotormain ul').removeAttr('class').removeAttr('title');
        }
    }

    $(".tabs").children("ul").find("a").addClass("noSmoothScroll");
    $(".cokokunanTab li a, .galeriTab li a").addClass("noSmoothScroll");
    enable_smooth_scroll(".noSmoothScroll");
    
    $(".tabs").tabs({ fx: { opacity: 'toggle', duration: "fast" } });
    
    $(".toTheTopBtn").click(function(){
        $('html, body').animate({ scrollTop: 0 }, "fast");
        return false;
    });
    
    /* Paylaşımlar */
    $(".d-share a").click(function(e){e.preventDefault(); window.open($(this).attr('href'), "CtrlWindow", "width=600,height=500,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");});
    
    //$(".loginLnk.login,a.UserLogin,").colorbox({href:"uye_girisi_ufak.php", opacity: 0.7});
    $(".loginLnk.login,a.UserLogin,").colorbox({
        inline:true
        ,href:"#uyelikFormuUfak"
        ,opacity: 0.7
        ,returnFocus: false
        ,onOpen: function (){
            $("#uyelikFormuUfak").show();
            _cbPr = pagerefresh;
            pagerefresh = false;
        }
        ,onComplete: function (){
            $('#uyelikFormuUfak input[name="eposta"]').focus();
        }
        ,onClosed: function (){
            $("#uyelikFormuUfak").hide();
            pagerefresh = _cbPr;
        }
    });
    
    $("a[rel='facebox'], a[rel='colorbox']").each(function (){
        var opts = {"rel": "nofollow"};
        if (/^#/.test($(this).attr("href"))) {
            opts.html = $($(this).attr("href")).html(); 
        }
        $(this).colorbox(opts);
    });
    $("input.kopyala").click(function (){
        $(this).select();
    });
    
    //hayranol
    $(".btn_hayranOl").click(function() {
        var params = $(this).attr("id").split("_");
        var postveri = 'bolumID='+params[1]+'&konuID='+params[2]+'&durumID='+params[3];
        var $this = $(this);
    	$.ajax({
    		type: "POST",
    		url: "uyeolkontrol.php",
    		data: postveri,
    		success: function(msg){
    			if(msg=="ok"){ 
                    $this.fadeTo(200, 0.3, function (){ $(this).fadeTo(200, 1); });
                    if (params[3] == 2) {
                        var favPar = $this.parents(".profilim_fav_item:first");
                        if (favPar.size() > 0) {
                            favPar.fadeOut();
                        } else {
                            $this.removeClass("quitFan");
                        }
                    } else {
                        $this.addClass("quitFan");
                    }
                    $this.attr("id", "hayranol_" + params[1] + "_" + params[2] + "_" + (params[3] == 2 ? 1 : 2));		 
    				//alert("OK");
    				//location.reload();
    			}else{
                    cBoxErr('Üye Girişi Yapmadınız!');
    			}
    		}
    	});
        return false;
    });
    
    $(".favCont .pagination a").live("click", function (){
        var par = $(this).parents(".favCont:first");
        par.html("&nbsp;").addClass("loading");
        var qPart = $(this).attr("href").split("?")[1];
        $.ajax({
    		type: "get",
    		url: "ajax_fonksiyonlar.php?"+qPart,
    		success: function(ret){
    			par.removeClass("loading").html(ret);
    		}
    	});
        return false;
    });
     
    $(".astroIcons a").mouseenter(function (){
        $(this).parents(".astroIcons").find("li").removeClass("current");
        $(this).parents("li:first").addClass("current");
        $(this).parents(".astro").find(".burcSpot").stop(true, true).hide();
        $(this).parents(".astro").find(".burcSpot_" + $(this).attr("class")).fadeIn();
    });      
});

/* Scroll To */
var RefreshUrl,RefreshTime,pagerefresh=true,RefreshControl = function(url,time){
    RefreshUrl=url;RefreshTime=time;
    thispagerefresh=window.setTimeout(function(){if(pagerefresh){ setCookie('ScrollTo',$(window).scrollTop(),1);window.location.href=RefreshUrl; }},RefreshTime);
}
$().ready(function(){
    var ScrollToPos=getCookie('ScrollTo');
    if(ScrollToPos!='' && Number(ScrollToPos)>0){
        setCookie('ScrollTo',0,1);
        $('html, body').animate({scrollTop:Number(ScrollToPos)},1000,function(){});
    }
});

/**
 * Header Menu
 */
var crslPluses='';
$(function(){
    var last3 = $('#navigation li.last3');
    for (i=0;i<last3.length;i++)
    {
        //$(last3[0]).find('div').css('left',-22-($(last3[0]).find('a').width())).find('div').css({'left':-103-($(last3[0]).find('a').width())});
        //$('#navigation li.last3:eq('+i+')').find('div').css('left',-22-($('#navigation li.last3:eq('+i+') a').width())).find('div').css({'left':-103-($('#navigation li.last3:eq('+i+') a').width())});
        $(last3[i]).find('div:first').css('left', -200+($(last3[i]).find('a').width()) ).find('div').css({'left':-200});
    }
    //$('#navigation li.last3').find('div').css('left',-22-($('#navigation li.last3 a').width())).find('div').css({'left':-103-($('#navigation li.last3 a').width())});
    
    var topmnulis='#navigation li.first,#navigation li.middle,#navigation li.last';
    $(topmnulis).hover(function(){
        $(topmnulis).removeClass('current');
        $(this).addClass('current').find('div:first').show();
    },function(){
        $(this).removeClass('current');
        $(this).find('div').hide();
    });
    $('#navigation li li').hover(function(){
        $(this).addClass('current').find('div').show();
    },function(){
        $(this).removeClass('current').find('div').hide();
    });
});


/**
 * Datay Yazı Boyutu 
 */
$(function(){
    $('.textsize a').click(function(){
        var doPx=13;
        var ndx = $(this).parent().index();
        switch (ndx){
            case 0: doPx = 13; break;
            case 1: doPx = 16; break;
            case 2: doPx = 20; break;
            case 3: doPx = 24; break;
            default : doPx = 24; break;
        }
        $(this).parents(".textsize").css({backgroundPosition: "left " + (-ndx * 16) + "px"});
        $('.detail-text').css('font',doPx+'px/'+(doPx+6)+'px Tahoma');
        return false;        
    });	
});

/**
 * Rating 
 */
function rating(table,id,userid,ratingpuan,cookieKey) {
	var postveri = 'table='+table+'&id='+id+'&userid='+userid+'&ratingpuan='+ratingpuan;
	$.ajax({
		type: "POST",
		url: "uyeolkontrol.php",
		data: postveri,
		success: function(msg){
			if(msg=="ok"){
				setCookie(cookieKey,ratingpuan,365);
				$('#RatingF_' + cookieKey + ' > input').rating('disable');
			}else{
			     //$('<div class="msg-err">Teknik bir problem olustu.<br />Lütfen Daha sonra tekrar deneyin.</div>').colorbox();
                 alert(msg);
			}
		}
	});
}

$().ready(function() {
	var a = $('.arkadasOlButon');
	for (var i = 0; i < a.length; i++) {
		$(a[i]).click(function (event) { 
			event.preventDefault();
			prcl=this.id.split("_");
			var ok=true;
			if( prcl[3]==4 ){
				ok = confirm('Emin misiniz?');
			}
			if(ok){
				arkadasolayril(prcl[1],prcl[2],prcl[3],this);
			}
		});
	}
});

function arkadasolayril(a,b,c,d) {
	$(d).html('Bekleyin');
	$.ajax({
		type: "POST",url: "uyeolkontrol.php",data: 'a='+a+'&b='+b+'&c='+c,
		success: function(msg){
			if(msg=="ok"){
				location.reload();
			}else{
                $('<div class="msg-err">' + msg + '</div>').colorbox();
			}
		}
	});	
}

/* Mesaj At Win */
function mesajGonder(from,to){
	//jQuery.fn.modalBox({ directCallURI: 'add_quiz.html' });
	konu = $('#subj').val();
    msg = $('#M textarea').val();
	if(konu==''){$('#subj').focus(); return;}
	if(msg==''){$('#M textarea').focus(); return;}
    $.ajax({
		type	: 'POST',
		url		: 'uyeolkontrol.php',
		data	: 'konu='+konu+'&msg='+msg+'&from='+from+'&to='+to+'&ac=msgSend',
		success: function(msg) {
			$('#cevabi').html(msg);
			$('.mesajKutusu').hide();
			$('#cevapKutusu').show("medium");
			//$('#answer-box .button').focus();
		}
	});	
}

function cBoxAlert(html){
    $.colorbox({html:html, transition: "none"});
}

function cBoxErr(html){
    cBoxAlert('<div class="msg-err">'+html+'</div>');
}

/**
 * Hava Durumu Yüklemesi 
 */
var hdData     = '';
var hdSehirler = '';
$(function(){
    //hdYukle();
    $('#top-weather').hover(function(){
        $('#top-weather .hdSehir, #top-weather .derece').hide();
        $('#top-weather a.degistir').show();
    },function(){
        $('#top-weather .hdSehir, #top-weather .derece').show();
        $('#top-weather a.degistir').hide();
    });
    $("#hd-sehir-sec").blur(function (){
        $('.hd-data').hide();
        $('#top-weather').show();
    });
});

function hdYukle($sehirAnahtar) {
    if($sehirAnahtar==undefined){
        $sehirAnahtar=getCookie('HD_SehirAnahtar');
    }
    if($sehirAnahtar==''){
        $sehirAnahtar='istanbul';
    }
    $('.hd-data').hide();
    
    
    data=getCookie('HD_Data');

    if(data!='' && data.sehiranahtar!=$sehirAnahtar){
        data='';
    }

    if(data==''){
        //$.ajaxSetup({ timeout: 7000 });         
    	$.getJSON('ajax_fonksiyonlar.php?ac=havadurumuver&sehir='+$sehirAnahtar, function(data) {
    	    hdData = data;
            setCookie('HD_SehirAnahtar',$sehirAnahtar,365);
           // setCookieTime('HD_Data',$.JSON.encode(data),(60*2));
            hdDuznle($sehirAnahtar);
    	});
    }else{
        hdData = $.JSON.decode(data);
        hdDuznle($sehirAnahtar);
    }
}

function hdDuznle() {
    $('#top-weather .hdSehir').html(hdData['sehir']);
    $('#top-weather span.derece').html(hdData.besgun.sicaklik[0]);
    //$('#top-weather span.info').html( hdData['info'] );
    $('#top-weather img').attr('src',_staticPath+'images/hd/mini/'+hdData['imgno']+'.png');
    $('#top-weather img')
        .attr('alt',hdData['info'])
        .attr('title',hdData['info']);
    $('#top-weather').show();
}

function hdSecUst() {
    $('#top-weather').hide();
    $('.hd-data').show();
}

/* Manşet */
var mansetCurrent=0,mansetHover=false;
$().ready(function()
{
    if($('.manset-top li').length>1)
    {
        $('.manset-bottom a:first').addClass('current');
        var mansetChange = function(bu){
            //alert($(bu).attr('index'));
            $('.manset-bottom li a').removeClass('current');
            $(bu).addClass('current');
            mansetCurrent = Number($(bu).attr('index')) ;
            $('.manset-top ul').stop().animate({'left':(mansetCurrent==0 ? 0 : -1*mansetCurrent*450 )},500);
        };
        
        var Lists = $('.manset-bottom li');
        for (i=0;i<Lists.length;i++){
            $(Lists[i]).children('a').attr('index',i);
            $(Lists[i]).children('a').hover( function(){ mansetChange(this)},function(){});
        }
        $.timer(5000,function(mansettimer){
            if(!mansetHover){
                var Lists = $('.manset-bottom li');
                mansetChange($(Lists[mansetCurrent]).children('a'));
                mansetCurrent = mansetCurrent==4 ? 0 : mansetCurrent+1;
            }
        });
    }
});

function salondegistir( $veri ){
    var veri = $($veri).val();
    location.href = veri;
}

