﻿/// <reference name="MicrosoftAjax.js" />
/// <reference path="~/scripts/jquery-1.3.2-vsdoc2.js" />
Type.registerNamespace("SearsPhotos.Common");



//*************************************
// SearsPhotos.Common.SessionExtender
//*************************************
SearsPhotos.Common.SessionExtender = function() {

    this._idleTimeBeforeIssueMessage = 0;
    this._modalBehaviorId = null;
    this._timeoutID = null;
    this._timerCallBack = null;
}


SearsPhotos.Common.SessionExtender.prototype = {

    start: SearsPhotos$Common$SessionExtender$start,
    restartTimer: SearsPhotos$Common$SessionExtender$restartTimer,
    silentExtend: SearsPhotos$Common$SessionExtender$silentExtend,
    onExtendSessionOKClicked: SearsPhotos$Common$SessionExtender$onExtendSessionOKClicked,
    _setTimerForExtendSessionPopup: SearsPhotos$Common$SessionExtender$_setTimerForExtendSessionPopup,
    _showModalPopup: SearsPhotos$Common$SessionExtender$_showModalPopup,
    _onTouchSessionSuccess: SearsPhotos$Common$SessionExtender$_onTouchSessionSuccess,
    _onTouchSessionFail: SearsPhotos$Common$SessionExtender$_onTouchSessionFail

}

function SearsPhotos$Common$SessionExtender$start(idleTimeBeforeIssueMessage, modalBehaviorId) {
    this._idleTimeBeforeIssueMessage = idleTimeBeforeIssueMessage;
    this._modalBehaviorId = modalBehaviorId;
    this._setTimerForExtendSessionPopup();
}

function SearsPhotos$Common$SessionExtender$silentExtend() {
    SearsPhotos.CommonService.TouchSession(this._onTouchSessionSuccess, this._onTouchSessionFail, false);
}

function SearsPhotos$Common$SessionExtender$onExtendSessionOKClicked() {

    var mpeBehaviorhandle = $find(SearsPhotos.Common.SessionExtender._staticInstance._modalBehaviorId);
    mpeBehaviorhandle.hide();

    $("#ProdConfig").css("visibility", "visible");
    
    var successDelegate = Function.createDelegate(this, this._onTouchSessionSuccess);
    var failDelegate = Function.createDelegate(this, this._onTouchSessionFail);

    SearsPhotos.CommonService.TouchSession(successDelegate, failDelegate);
}

function SearsPhotos$Common$SessionExtender$_setTimerForExtendSessionPopup() {

    this._timerCallBack = Function.createDelegate(this, this._showModalPopup);
    this._timeoutID = window.setTimeout(this._timerCallBack, this._idleTimeBeforeIssueMessage);
}

function SearsPhotos$Common$SessionExtender$_showModalPopup() {
    var mpeBehaviorhandle = $find(SearsPhotos.Common.SessionExtender._staticInstance._modalBehaviorId);
    mpeBehaviorhandle.show();

    $("#ProdConfig").css("visibility", "hidden");

    window.focus();
}



function SearsPhotos$Common$SessionExtender$restartTimer() {

    window.clearTimeout(this._timeoutID);
    this._setTimerForExtendSessionPopup();
}

function SearsPhotos$Common$SessionExtender$_onTouchSessionSuccess(res) {

    try {
        if (res.IsAuthenticated == false) {
            window.location = window.location;
        }
        else {
            this._setTimerForExtendSessionPopup();
        }
    } catch (e) {
       
        
    }
}

function SearsPhotos$Common$SessionExtender$_onTouchSessionFail(res) {

}


SearsPhotos.Common.SessionExtender._staticInstance = new SearsPhotos.Common.SessionExtender();

SearsPhotos.Common.SessionExtender.start = function(idleTimeBeforeIssueMessage, modalBehaviorId) {
    SearsPhotos.Common.SessionExtender._staticInstance.start(idleTimeBeforeIssueMessage, modalBehaviorId);
}

SearsPhotos.Common.SessionExtender.silentExtend = function() {
    SearsPhotos.Common.SessionExtender._staticInstance.silentExtend();
}

SearsPhotos.Common.SessionExtender.onExtendSessionOKClicked = function() {
    SearsPhotos.Common.SessionExtender._staticInstance.onExtendSessionOKClicked();
}

SearsPhotos.Common.SessionExtender.restartTimer = function() {
    SearsPhotos.Common.SessionExtender._staticInstance.restartTimer();
}

function updateCartTotal() {
    $.ajax({
        type: "POST",
        url: "UpdateCartTotal.asmx/Update",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            $("#cartTotal").text(msg.d);
        }
    });
}

SearsPhotos.Common.SessionExtender.registerClass("SearsPhotos.Common.SessionExtender");

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

 /***************************/
    //@Author: Adrian "yEnS" Mato Gondelle
    //@website: www.yensdesign.com
    //@email: yensamg@gmail.com
    //@license: Feel free to use it, but keep this credits please!					
    /***************************/

    //SETTING UP OUR POPUP
    //0 means disabled; 1 means enabled;
    var popupStatus = 0;

    //loading popup with jQuery magic!
    function loadPopup() {
        //loads popup only if it is disabled
        if (popupStatus == 0) {
            $("#backgroundPopup").css({
                "opacity": "0.7"
            });
            $("#backgroundPopup").fadeIn("slow");
            $("#popupContact").fadeIn("slow");
            popupStatus = 1;
        }
    }

    //disabling popup with jQuery magic!
    function disablePopup() {
        //disables popup only if it is enabled
        if (popupStatus == 1) {
            $("#backgroundPopup").fadeOut("slow");
            $("#popupContact").fadeOut("slow");
            popupStatus = 0;
        }
    }

    //centering popup
    function centerPopup() {
        //request data for centering
        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
        var popupHeight = $("#popupContact").height();
        var popupWidth = $("#popupContact").width();
        //centering
        $("#popupContact").css({
            "position": "absolute",
            "top": windowHeight / 2 - popupHeight / 2,
            "left": windowWidth / 2 - popupWidth / 2
        });
        //only need force for IE6

        $("#backgroundPopup").css({
            "height": windowHeight
        });

    }

    $(document).ready(function() {
    $(".moreinfoLink").click(function() {

            centerPopup();
            loadPopup();

        });

        $("#popupContactClose").click(function() {
            disablePopup();
        });


        $("#backgroundPopup").click(function() {
            disablePopup();
        });

        $("#popupContact").click(function() {
            disablePopup();
        });

        $(document).keypress(function(e) {
            if (e.keyCode == 27 && popupStatus == 1) {
                disablePopup();
            }
        });

    });

    //FAQ code
    jQuery(document).ready(function() {


        $(".category").next("div").slideDown("slow");


        $(".category").click(function() {

            $(this).next("div").toggle("slow");

        });


        $(".question").click(function() {

            $(this).next("div").toggle("fast");

        });


        $(".category").hover(function() {

            $(this).removeClass("categorynohover");
            $(this).addClass("categoryhover");

        }, function() {

            $(this).removeClass("categoryhover");
            $(this).addClass("categorynohover");

        }
             );


        $(".question").hover(function() {

            $(this).addClass("categorynohover");

        }, function() {

            $(this).removeClass("categorynohover");

        }
             );


        $("#expandLink").click(function() {

            $("div [id*='ToggeableDiv_']").slideDown("slow");
            $("#collapseLink").css("display", "");
            $(this).css("display", "none");

        });

        $("#collapseLink").click(function() {

            $("div [id*='ToggeableDiv_']").slideUp("slow");
            $("#expandLink").css("display", "");
            $(this).css("display", "none");

        });


    });