﻿function clientHeight() {
    var y = 0;
    if (self.pageYOffset) {
        y = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) {

        y = document.documentElement.scrollTop;
    }

    if (y == getWindowHeight())
    { return 0; }
    else
    { return y; }
}
function getWindowHeight() {
    var windowHeight;
    if (window.innerHeight && window.scrollMaxY) {
        windowHeight = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) {
        windowHeight = document.body.scrollHeight;
    } else {
        windowHeight = document.body.offsetHeight;
    }
    return windowHeight;
}
//Main function , assigns behaiviors to different elements , when document is ready
$(document).ready(function () {

    $('#basket').mouseenter(function (e) { $(this).css("cursor", "pointer"); }).mouseleave(function (e) { $(this).css("cursor", "normal"); }).click(function (e) { location.replace("ShoppingCart.aspx"); });
    $('.enlargeImage,.aSendToFriend,.aInformMe,.aWashManual, #shippingHelp, .aInformCVV').click(function (e) {
        $('body').append('<div id="mask"></div>')
        $('.popup').appendTo('body');
        $('.popup').append('<a class="close">סגור</a>');
        //if popup's x button clicked
        $('.close').bind('click',function (e) {
            //Cancel the link behavior
            e.preventDefault();
            $('#mask').remove();
            $('.popup').hide();
            $('#informFrame').remove();
        });
        //Cancel the link behavior
        e.preventDefault();
        var popupId = $(this).attr('href');
        if ($(this).hasClass('aInformMe') == true) {
            $('#informFromPopup').append('<iframe id="informFrame" allowtransparency="true" width="317" height="297" frameborder="0" marginheight="0" scrolling="no" style="overflow:hidden;padding:0px;" marginwidth="0" src="InformStock.aspx' + $(this).attr('name') + '"  ></iframe>');
        }
        $('#mask').css({ backgroundColor: '#339fdc', opacity: '0.6', position: 'absolute', top: '0px', left: '0px' });

        $('#mask').live('click', function (e) {
            $(this).remove();
            $(popupId).hide();
            $('#informFrame').remove();
        });

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        //transition effect	
        $('#mask').fadeIn(500);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(popupId).css('top', (clientHeight() + 100));
        $(popupId).css('right', winW / 2 - $(popupId).width() / 2);
        //transition effect     
        $(popupId).fadeIn(500);

    });


    //if mask is clicked
    $('.popup img').click(function () {
        $('#mask').remove();
        $('.popup').hide();
        $('#informFrame').remove();
    });

});



