﻿/// <reference name="MicrosoftAjax.js" />
/// <reference path="~/scripts/jquery-1.3.2-vsdoc2.js" />
Type.registerNamespace("MyPortraits.Common");



//*************************************
// MyPortraits.Common.SessionExtender
//*************************************
MyPortraits.Common.SessionExtender = function() {

    this._idleTimeBeforeIssueMessage = 0;
    this._modalBehaviorId = null;
    this._timeoutID = null;
    this._timerCallBack = null;
}


MyPortraits.Common.SessionExtender.prototype = {

    start: MyPortraits$Common$SessionExtender$start,
    restartTimer: MyPortraits$Common$SessionExtender$restartTimer,
    silentExtend: MyPortraits$Common$SessionExtender$silentExtend,
    onExtendSessionOKClicked: MyPortraits$Common$SessionExtender$onExtendSessionOKClicked,
    _setTimerForExtendSessionPopup: MyPortraits$Common$SessionExtender$_setTimerForExtendSessionPopup,
    _showModalPopup: MyPortraits$Common$SessionExtender$_showModalPopup,
    _onTouchSessionSuccess: MyPortraits$Common$SessionExtender$_onTouchSessionSuccess,
    _onTouchSessionFail: MyPortraits$Common$SessionExtender$_onTouchSessionFail

}

function MyPortraits$Common$SessionExtender$start(idleTimeBeforeIssueMessage, modalBehaviorId) {
    this._idleTimeBeforeIssueMessage = idleTimeBeforeIssueMessage;
    this._modalBehaviorId = modalBehaviorId;
    this._setTimerForExtendSessionPopup();
}

function MyPortraits$Common$SessionExtender$silentExtend() {
    MyPortraits.CommonService.TouchSession(this._onTouchSessionSuccess, this._onTouchSessionFail, false);
}

function MyPortraits$Common$SessionExtender$onExtendSessionOKClicked() {

    var mpeBehaviorhandle = $find(MyPortraits.Common.SessionExtender._staticInstance._modalBehaviorId);
    mpeBehaviorhandle.hide();

    $("#ProdConfig").css("visibility", "visible");

    var successDelegate = Function.createDelegate(this, this._onTouchSessionSuccess);
    var failDelegate = Function.createDelegate(this, this._onTouchSessionFail);

    MyPortraits.CommonService.TouchSession(successDelegate, failDelegate);
}

function MyPortraits$Common$SessionExtender$_setTimerForExtendSessionPopup() {

    this._timerCallBack = Function.createDelegate(this, this._showModalPopup);
    this._timeoutID = window.setTimeout(this._timerCallBack, this._idleTimeBeforeIssueMessage);
}

function MyPortraits$Common$SessionExtender$_showModalPopup() {
    var mpeBehaviorhandle = $find(MyPortraits.Common.SessionExtender._staticInstance._modalBehaviorId);
    mpeBehaviorhandle.show();

    $("#ProdConfig").css("visibility", "hidden");

    window.focus();
}



function MyPortraits$Common$SessionExtender$restartTimer() {

    window.clearTimeout(this._timeoutID);
    this._setTimerForExtendSessionPopup();
}

function MyPortraits$Common$SessionExtender$_onTouchSessionSuccess(res) {

    try {
        if (res.IsAuthenticated == false) {
            window.location = window.location;
        }
        else {
            this._setTimerForExtendSessionPopup();
        }
    } catch (e) {


    }
}

function MyPortraits$Common$SessionExtender$_onTouchSessionFail(res) {

}


MyPortraits.Common.SessionExtender._staticInstance = new MyPortraits.Common.SessionExtender();

MyPortraits.Common.SessionExtender.start = function(idleTimeBeforeIssueMessage, modalBehaviorId) {
    MyPortraits.Common.SessionExtender._staticInstance.start(idleTimeBeforeIssueMessage, modalBehaviorId);
}

MyPortraits.Common.SessionExtender.silentExtend = function() {
    MyPortraits.Common.SessionExtender._staticInstance.silentExtend();
}

MyPortraits.Common.SessionExtender.onExtendSessionOKClicked = function() {
    MyPortraits.Common.SessionExtender._staticInstance.onExtendSessionOKClicked();
}

MyPortraits.Common.SessionExtender.restartTimer = function() {
    MyPortraits.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);
        }
    });
}

MyPortraits.Common.SessionExtender.registerClass("MyPortraits.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");

    });


});