﻿$(document).ready(function() {
    $(".popup").fancybox({
        'zoomOpacity': true,
        'overlayShow': false,
        'zoomSpeedIn': 500,
        'zoomSpeedOut': 500,

        'frameWidth': 720,
        'frameHeight': 710,
        'hideOnContentClick': false,
        'centerOnScroll': false,
        callbackOnShow: function() {
            $(".popupSkin").click(function() {
                changeSkin(this);
                return false;
            });
        }
    });

    $(".popupLarge").fancybox({
        'zoomOpacity': true,
        'overlayShow': false,
        'zoomSpeedIn': 500,
        'zoomSpeedOut': 500,

        'frameWidth': 720,
        'frameHeight': 720,
        'hideOnContentClick': false,
        'centerOnScroll': false,
        callbackOnShow: function() {
            $(".popupSkin").click(function() {
                changeSkin(this);
                return false;
            });
        }
    });

    $(".popupWebsiteTemplate").fancybox({
        'zoomOpacity': true,
        'overlayShow': false,
        'zoomSpeedIn': 500,
        'zoomSpeedOut': 500,

        'frameWidth': 820,
        'frameHeight': 620,
        'hideOnContentClick': false,
        'centerOnScroll': false
    });

    $("input:text[title!='']").each(function() {
        var input = $(this);
        input.watermark(input.attr('title'));
    });

    $(".printLinkSolutions").hover(function() {
        $(".printPageLink").html('Print this Page');
        return false;
    },
    function() {
        $(".printPageLink").html('');
        return false;
    });
    $(".emailLinkSolutions").hover(function() {
        $(".printPageLink").html('Email this Page');
        return false;
    },
    function() {
        $(".printPageLink").html('');
        return false;
    });
    $(".openLinkSolutions").hover(function() {
        $(".printPageLink").html('Add to Favorites');
        return false;
    },
    function() {
        $(".printPageLink").html('');
        return false;
    });

    setTimeout(function() { $("#liveadmin img").attr("src", "images/startChatSmall.png").show() }, 3000);

});

function changeSkin(image) {
    var newImage = $(image).attr("src").replace('.png', 'Skin.jpg');
    $("#fancy_wrap .popupMainImage img").attr("src", newImage);
    $("#fancy_wrap .popupImgSmall").removeClass("popupImgSmallSelected");
    $(image).closest('#fancy_wrap .popupImgSmall').addClass("popupImgSmallSelected");
}

function addToFavorites() {
    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(document.title, location.href, "");
    } else if (window.external) { // IE Favorite
        window.external.AddFavorite(location.href, document.title);
    }
    else if (window.opera && window.print) { // Opera Hotlist
        return true;
    }
}
function emailFriend() {
    var width = 600;
    var height = 400;
    var left = parseInt((screen.availWidth / 2) - (width / 2));
    var top = parseInt((screen.availHeight / 2) - (height / 2));
    window.open("Controls/EmailFriend.aspx?link=" + window.location, "EmailFriend", "menubar=0,resizable=0,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top);
}
$("#btnSubmitNewsletter").click(function() {
    $("#btnSubmitNewsletter").addClass("btnLoading");
    $('#txtNewsletterInfo').html("");
    var index = window.location.pathname.lastIndexOf('/');
    var path = window.location.pathname.slice(0, index + 1) + 'Controls/Subscription.aspx';
    if (typeof $.jmsajax == 'function') {
        $.jmsajax({
            url: path,
            method: "btnSubmitNewsletter_Click",
            data: {
                email: $("#txtNewsletter").val()
            },
            success: function(res) {
                $("#btnSubmitNewsletter").removeClass("btnLoading");
                if (res) {
                    $('#txtNewsletterInfo').html("Successfully subscription!");
                } else {
                    $('#txtNewsletterInfo').html("Error when subscribing. Please try again!");
                }
            },
            error: function() {
                $("#btnSubmitNewsletter").removeClass("btnLoading");
                alert("Error when subscribing. Please try again!");
            }
        });
    }
});