﻿$(document).ready(function() {

    if (window.location.pathname.indexOf('Video-Tributes.aspx') > 0) {
        $("#bannerTribute").show();
    } else {
        initSwapSlider();
    }
    $("input:text[title!='']").each(function() {
        var input = $(this);
        input.watermark(input.attr('title'));
    });
    $(".centerTop li a").hover(function() {
        var el = $(this);
        slideUpMenuItem(el);
    },
    function() {
        var el = $(this);
        if (!el.is(".active")) {
            slideDownMenuItem(el);
        }
    });
    $(".printLink").hover(function() {
        $(".printPageLink").html('Print this Page');
        return false;
    },
    function() {
        $(".printPageLink").html('');
        return false;
    });
    $(".emailLink").hover(function() {
        $(".printPageLink").html('Email this Page');
        return false;
    },
    function() {
        $(".printPageLink").html('');
        return false;
    });
    $(".openLink").hover(function() {
        $(".printPageLink").html('Add to Favorites');
        return false;
    },
    function() {
        $(".printPageLink").html('');
        return false;
    });
    //$("#liveadmin img").attr("src", "images/startchat.png").show();
    setTimeout(function() { $("#liveadmin img").attr("src", "images/startchat.png").show() }, 1000);
});
function initSwapSlider(){
    $("#banners").swapSlider({
        continuous: true,
        speed: 1200,
        pause: 6400, 
        width: 778,
        height: 303,
        onSwapping: function(oldEl, newEl) {
            var link = $("a:first", newEl);
            if (link.length) {
                var href = link.attr('href');
                $(".centerTop li a").each(function() {
                    var fl = $(this);
                    var flhref = fl.attr('href');
                    if (flhref.toLowerCase() == href.toLowerCase()) {
                        fl.addClass("active");
                        slideUpMenuItem(fl);
                    }
                    else if (fl.is(".active")) {
                        fl.removeClass("active");
                        slideDownMenuItem(fl);
                    }
                });
            }
        }
    });
}
function slideUpMenuItem(el) {
    $(".slide", el).animate({ height: "80px" }, { queue: false, duration: 500 });
    el.animate({ marginTop: "-80px" }, { queue: false, duration: 500 });
    $(".icon", el).fadeIn(500);
}
function slideDownMenuItem(el) {
    el.animate({ marginTop: "-10px" }, { queue: false, duration: 500 });
    $(".slide", el).animate({ height: "10px" }, { queue: false, duration: 500 });
    $(".icon", el).hide();
}

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!");
            }
        });
    }
});