﻿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 () {

    $('.pageSide').css({ height: $('.page').height() - 15 });
    $('.pageMain').css({ height: $('.page').height() - 15 });
    $(".regular").mouseover(function (e) {
        $(this).css("color", "#FEF200");
    }).mouseout(function (e) { $(this).css("color", "#FFFFFF"); });

    var tempValue;
    $('.subscribeinput').focusin(function (e) {
        tempValue = $(this).val();
        $(this).val("");
    }).focusout(function (e) {
        if ($(this).val() == '' || $(this).val() == tempValue || $(this).val() == 'שם' || $(this).val() == 'דואר אלקטרוני') { $(this).val(tempValue) }
    });

    $('#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();
        });
        //Cancel the link behavior
        e.preventDefault();
        var popupId = $(this).attr('href');
        $('#mask').css({ backgroundColor: '#339fdc', opacity: '0.6', position: 'absolute', top: '0px', left: '0px' });

        $('#mask').live('click', function (e) {
            $(this).remove();
            $(popupId).hide();
        });

        //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();
    });

});

