﻿/***
helper to get platform
***/
var currentPlatform = function() {
    return location.href.split('/')[3];
}

$(document).ready(function() {
    $('.socialMediaScroll').jScrollPane({showArrows:true});
    $('#scrollcontainer').jScrollPane({showArrows:true});

    // topNav 
    $("li#memberAction").hoverIntent({
        sensitivity: 3,
        interval: 200,
        over: mpOver,
        timeout: 500,
        out: mpOut
    });
    $("li#supportAction").hoverIntent({
        sensitivity: 3,
        interval: 200,
        over: mpOver,
        timeout: 500,
        out: mpOut
    });
    $("li#wclientAction").hoverIntent({
        sensitivity: 3,
        interval: 200,
        over: mpOver,
        timeout: 500,
        out: mpOut
    });
    $("li#subNavTv").hoverIntent({
        sensitivity: 3,
        interval: 10,
        over: mpOver,
        timeout: 500,
        out: mpOut
    });

    // custom select
    $("select").uniform();

    $("#sharepop a.main").mouseenter(function(){
	    $("#sharepop .subdiv").fadeIn("fast");
	    $(this).addClass("hover");
	});

    $("#sharepop").mouseleave(function(){
	    $("#sharepop .subdiv").fadeOut("fast");
	    $("#sharepop a.main").removeClass("hover");
	});	
	    
//    $("textarea.oneclick").click(function(){
//	    $(this).html("");
//	    $(this).removeClass("oneclick");
//	});			
			   					   
    /*$('.ss-item .numbered').click(function(){
        if ($(this).parent().find('img:visible').length > 0)
            $(this).parent().find('img').slideUp('fast');
        else{
            $(".ss-item img").slideUp('fast');
            $(this).parent().find('img').slideDown('fast');
        }
    });*/

	//videoThumbAction
    $(".videoThumbAction li, .videoListView li").mouseover(function() {
		$(this).addClass("selected");
    }).mouseout(function() {
		$(this).removeClass("selected");
	});
	
/* RENEW ************************************************************/	
// footer action
var miLink = $("#footer .mainItems a")

miLink.mouseover(function() {
    var miRel = $(this).attr("rel");
    miLink.parent().removeClass("selected");
    $(this).parent().addClass("selected");
    $("#footer .footerSection").hide();

    switch(miRel)
    {
        case '1':
          $("#footer #fsWeb").show();
        break;
        case '2':
          $("#footer #fsEv").show();
        break;
        case '3':
          $("#footer #fsCep").show();
        break;
    }    

});
	
// landing page feature slider

    var i=0;
    for (i=1;i<=13;i++)
    {
        var bgPos = (i * -150);
        if (i == 8 || i == 10 || i == 11 || i == 12 || i == 13) {
            $("#featureSlider").append("<li rel=\""+i+"\"><a href=\"/ev/ozellikler\" style=\"background-position:"+bgPos+"px 0;\">Tivibu özelliklerini Keşfedin</a><span class=\"fIcoEv\"></span></li>");
        } else {
            $("#featureSlider").append("<li  rel=\""+i+"\"><a href=\"/web/ozellikler\" style=\"background-position:"+bgPos+"px 0;\">Tivibu özelliklerini Keşfedin</a></li>");
        }
    }

    var btnNext = $("#lfSlider a.next");
    var btnPrev = $("#lfSlider a.prev");
    
    var slideNum = 0;
    featureNavCtrl(slideNum);
    
    btnNext.click(function() {
//       var divPos = $("#featureSlider").css("margin-left");
       var divPos = $("#featureSlider").css("left");
       
       if ( slideNum < '2')  {

//        $("#featureSlider").animate({"margin-left": "-=644px"}, "fast");
        $("#featureSlider").animate({"left": "-=644px"}, "fast");

        slideNum = slideNum + 1;
        featureNavCtrl(slideNum);
      }
    });
    btnPrev.click(function() {
//       var divPos = $("#featureSlider").css("margin-left");
       var divPos = $("#featureSlider").css("left");
       if ( slideNum > '0') {
//          $("#featureSlider").animate({"margin-left": "+=644px"}, "fast");
          $("#featureSlider").animate({"left": "+=644px"}, "fast");
          slideNum = slideNum - 1;
        featureNavCtrl(slideNum);
          
       }
    });
    
    $("#featureSlider li").mouseover(function() {
		$(this).addClass("selected");
    }).mouseout(function() {
		$(this).removeClass("selected");
	});
});

function featureNavCtrl(slidePos) {
    if (slidePos == '0') { $("#lfSlider a.prev").addClass("prevOff")}
    if (slidePos == '2') { $("#lfSlider a.next").addClass("nextOff")}
    if (slidePos > '0') { $("#lfSlider a.prev").removeClass("prevOff")}
    if (slidePos < '2') { $("#lfSlider a.next").removeClass("nextOff")}
}

// topNav Function
function mpOver(){ $(this).addClass("selected");$(this).find("ul").show();}
function mpOut() { $(this).removeClass("selected"); $(this).find("ul").hide(); }

//anasayfa.js
$(document).ready(function() {
    // fbFeed
    /*$.get("/home/fbfeed.aspx", {}, function(response) {

        $("#social_facebook").html(response);
        $('#socialMediaScrollFb').jScrollPane({ showArrows: false });
    }, "html");*/
    $('#socialMediaScrollFb').jScrollPane({ showArrows: false });
    
    //overlay
    $("a[rel='#overlay']").overlay({
        mask: 'black',
        effect: 'apple',
        onBeforeLoad: function() {
            // grab wrapper element inside content
            var wrap = this.getOverlay().find(".contentWrap");
            // load the page specified in the trigger
            wrap.load(this.getTrigger().attr("href"));
        },
        onClose: function(){
            $("#overlay .contentBox").html("");
        }
    });
    
    //download
    $(".dl").click(function(){
        dcsMultiTrack('DCS.dcsuri','/wt.gif','DCSext.parametre','DownloadEvent_Player');
    });
    
    // feature tabs
    $(".featureNav a").click(function(){
        var relValue = $(this).attr("rel");
        $(".featureNav li").removeClass("selected");
        $(".featureNav .line").removeClass("line1").removeClass("line2").removeClass("line3");
        $(".featureInfo .featureContent").hide();
        
        $(this).parent().addClass("selected");
        $(".featureNav .line").addClass('line'+relValue);
        $('#featureContent'+relValue).show();
    });    
    
    // 
    $(".faqTabs a").click(function(){
         var relValue = $(this).attr("rel");
        $(".faqTabs li").removeClass("selected");
        $('.faqContainer').hide();

        $(this).parent().addClass("selected");
        $('#faqContainer'+relValue).show();
    });
    
    // smBox
    $("#smBoxNav .lnkTwitter").click(function(){
        $("#smBoxNav li").removeClass("selected");
        $(this).parent().addClass("selected");
        $("#postTwitter").css({"top":"34px", "left":"0"});
        $("#postFacebook").css({"top":"-999px", "left":"-999px"});
    });    
    $("#smBoxNav .lnkFacebook").click(function(){
        $("#smBoxNav li").removeClass("selected");
        $(this).parent().addClass("selected");
        $("#postTwitter").css({"top":"-999px", "left":"-999px"});
        $("#postFacebook").css({"top":"34px", "left":"0"});
    });
});

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

var OpenLinkInOverlay = function(url, width){
    $("<a href=\""+ url +"\" rel=\"#overlay\"></a>").overlay({
        mask: 'black',
        effect: 'apple',
        onBeforeLoad: function() {
            var wrap = $("#overlay .contentWrap");
            if (width != null)
                $("#overlay").css("width", width);
            wrap.load(url);
        },
        onClose: function(){
            $("#overlay .contentBox").html("");
            $("#overlay").css("width", "");
        },
        closeOnClick: false,
        load: true
    });
};

/*******
tivibu ev fotoalbüm application
********/
var openPhotoAlbumApp = function () {
	window.open('/fotoalbum', "PopTivibuEvFotoAlbumApp", "width=816,height=616,menubar=0,location=no,left=0,top=0,scrollbars=yes,status=yes,resizable=yes");
};

/****
remember homepage
*****/
/*var openRememberModal = function () {
	$("#overlay").overlay({
		mask: 'black',
		effect: 'apple',
		onBeforeLoad: function () {
			// grab wrapper element inside content
			var wrap = this.getOverlay().find(".contentWrap");
			// load the page specified in the trigger
			wrap.load("/beni-hatirla");
		},
		onLoad: function () {
			this.getOverlay().find("input[value='" + currentPlatform() + "']").parent().addClass("selected");
		},
		onClose: function () {
			//$("#overlay .contentWrap").html("");
			//$("#overlay").attr("style", "");

		},
		load: true
	});
};

$(function() {
    var c = $.cookie("homepage");
    if (c != null && c == "" && (typeof(landingPage) == "undefined" || landingPage == null || landingPage != 1)) {
        openRememberModal();
    }
});

var closeOverlay = function () {
	$('#overlay').data('overlay').close();
};

var postponeHomepage = function () {
	$.cookie("homepage", "postpone", { expires: 1 });
	$('#overlay').data('overlay').close();
};

var saveHomepage = function () {
	var val = $(".siteChoice:checked").val();
	if (val == "landing" || val == "web" || val == "ev" || val == "cep") {
		$.cookie("homepage", val, { expires: 30 });
		closeOverlay();
	}
};*/


/****
videobox
*****/
/*var openRememberModal = function () {
    $("#overlay").overlay({
        mask: 'black',
        effect: 'apple',
        onBeforeLoad: function () {
            // grab wrapper element inside content
            var wrap = this.getOverlay().find(".contentWrap");
            // load the page specified in the trigger
            //wrap.load("/video-box");
            wrap.show();
        },
        onLoad: function () {
            
            //this.getOverlay().find("input[value='" + currentPlatform() + "']").parent().addClass("selected");
        },
        onClose: function () {
            $.cookie("videobox", "postpone", { expires: 1 });
            //$("#overlay .contentWrap").html("");
            //$("#overlay").attr("style", "");

        },
        load: true
    });
};

$(function () {
    var c = $.cookie("videobox");
    if (c == null || c == "")
            openRememberModal();
});

var closeOverlay = function () {
    $('#overlay').data('overlay').close();
};*/

//var postponeHomepage = function () {
//    $.cookie("videobox", "postpone", { expires: 1 });
//    $('#overlay').data('overlay').close();
//};

//var saveHomepage = function () {
//    var val = $(".siteChoice:checked").val();
//    if (val == "landing" || val == "web" || val == "ev" || val == "cep") {
//        $.cookie("homepage", val, { expires: 30 });
//        closeOverlay();
//    }
//};



/****
likebox
*****/
/*var openRememberModal = function () {
    $("#overlay").overlay({
        mask: 'black',
        effect: 'apple',
        onBeforeLoad: function () {
            // grab wrapper element inside content
            var wrap = this.getOverlay().find("#playercontainerbox");
            // load the page specified in the trigger
            //wrap.load("/video-box");
            wrap.show();
        },
        onLoad: function () {
            //this.getOverlay().find("input[value='" + currentPlatform() + "']").parent().addClass("selected");
        },
        onClose: function () {
            $.cookie("likebox", "postpone", { expires: 1 });
            //$("#overlay .contentWrap").html("");
            //$("#overlay").attr("style", "");

        },
        load: true
    });
};

$(function () {
    var c = $.cookie("likebox");
    if (c == null || c == "")
        openRememberModal();
});*/

function openLikeBoxModal(){
    $("#likeboxmodal").show();
}

$(function () {
    var c = $.cookie("likebox");
    if (c == null || c == "")
        openLikeBoxModal();
});

var closeOverlay = function () {
    $('#overlay').data('overlay').close();
};

$(document).ready(function(){
    $("#showlike-close").click(function(){
        $("#like-overlay").hide();
        $("#show-like-container").hide();
        $.cookie("likebox", "postpone", { expires: 365 });
    });
});
