﻿var isBusy = false;

$(document).ready(function () {
    LoadScrolls();

    $("li.facebook a").click(function () {
        fbShare();
    });

    $("li.twitter a").click(function () {
        twShare();
    });

    RepositionContainer();
    $(window).resize(function () {
        RepositionContainer();
    });

    $('#facebookSlideBtn').click(function () {
        if (isBusy) {
            return;
        }

        isBusy = true;

        $("#divPopupContainer").animate({
            top: "0px"
        }, 1200, function () { isBusy = false; });
    });

    $('#slideClose').click(function () {
        if (isBusy) {
            return;
        }

        isBusy = true;

        $("#divPopupContainer").animate({
            top: "-610px"
        }, 1200, function () { isBusy = false; });
    });

    $(".nextMilk").mouseover(function () {
        $(".nextMilk a").css("visibility", "visible");
    });
    $(".nextMilk").mouseout(function () {
        $(".nextMilk a").css("visibility", "hidden");
    });

    $(".stepMilk").mouseover(function () {
        $(".stepMilk a").css("visibility", "visible");
    });
    $(".stepMilk").mouseout(function () {
        $(".stepMilk a").css("visibility", "hidden");
    });

    $(".honeyMilk").mouseover(function () {
        $(".honeyMilk a").css("visibility", "visible");
    });
    $(".honeyMilk").mouseout(function () {
        $(".honeyMilk a").css("visibility", "hidden");
    });

});

function RepositionContainer() {
    var control = $(".mainContent").get(0)

    if (control == undefined || control == null) {
        return;
    }

    var top = (($(window).height() / 2) - ($(control).outerHeight() / 2));
    var left = (($(window).width() / 2) - ($(control).outerWidth() / 2));

    if (top < 0) top = 0;
    if (left < 0) left = 0;
    var pos = 'absolute';

    if ($.browser.msie && parseInt($.browser.version) <= 6) {
        top = top + $(window).scrollTop()
        pos = 'absolute';
    }

    $(control).css({
        position: pos,
        top: top + 'px',
        left: left + 'px'
    });

    RepositionPopupContainer();
}

function RepositionPopupContainer(centerX, centerY) {
    var control = $("#divPopupContainer");

    var centerY = ($(window).height() / 2);
    var centerX = ($(window).width() / 2);

    var top = $(control).attr("top");
    var left = centerX + 100;

    var pos = 'absolute';

    if ($.browser.msie && parseInt($.browser.version) <= 6) {
        top = top + $(window).scrollTop()
        pos = 'absolute';
    }

    $(control).css({
        position: pos,
        top: top + 'px',
        left: left + 'px'
    });
}

function LoadScrolls() {
    if (document.getElementById('scroll-mask') &&
            document.getElementById('scroll-content')) 
    {
        new Dragdealer('scroll-bar',
	    {
	        horizontal: false,
	        vertical: true,
	        yPrecision: document.getElementById('scroll-content').offsetHeight,
	        animationCallback: function (x, y) {
	            var margin = y * (document.getElementById('scroll-content').offsetHeight - document.getElementById('scroll-mask').offsetHeight);
	            document.getElementById('scroll-content').style.marginTop = String(-margin) + 'px';
	        }
	    });
    }


    // Vertical2
	if (document.getElementById('scroll-mask2') &&
            document.getElementById('scroll-content2')) {
	    new Dragdealer('scroll-bar2',
	    {
	        horizontal: false,
	        vertical: true,
	        yPrecision: document.getElementById('scroll-content2').offsetHeight,
	        animationCallback: function (x, y) {
	            var margin = y * (document.getElementById('scroll-content2').offsetHeight - document.getElementById('scroll-mask2').offsetHeight);
	            document.getElementById('scroll-content2').style.marginTop = String(-margin) + 'px';
	        }
	    });
	}

	$("#divPopupContainer").css("z-index", "11").css("top", "-610px");
}

function fbShare() {
    var url = "http://pinarcocuksutu.afflications.com/";
    window.open("http://www.facebook.com/sharer/sharer.php?u=" + encodeURI(url));
}

function twShare() {
    var text = encodeURI("Pınar Çocuk Sütü ile artık çocuklar süt içmeye bayılıyor!");
    window.open("https://twitter.com/share?text=" + text);
}

function GetWidth() {
    var x = 0;
    if (self.innerHeight) {
        x = self.innerWidth;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
        x = document.documentElement.clientWidth;
    }
    else if (document.body) {
        x = document.body.clientWidth;
    }
    return x;
}

function GetHeight() {
    var y = 0;
    if (self.innerHeight) {
        y = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) {
        y = document.documentElement.clientHeight;
    }
    else if (document.body) {
        y = document.body.clientHeight;
    }
    return y;
}

function openPopup() {
    if (isBusy) {
        return;
    }

    isBusy = true;

    $("#divPopupContainer").animate({
        top: "0px"
    }, 1200, function () { isBusy = false; });
}
