﻿var $elem
var root = '/'
$(document).ready(function () {

    initScroll();

    var $sidebar = $("#sideBar"), $window = $(window), offset = $sidebar.offset(), topPadding = 5;

    $window.scroll(function () { if ($sidebar && offset && $window.scrollTop() > offset.top) { $sidebar.stop().animate({ marginTop: $window.scrollTop() - offset.top + topPadding }); } else { $sidebar.stop().animate({ marginTop: 0 }); } });

    $(".SIGLogin").click(function (e) {
        showLogin();
        e.preventDefault();

    });

    $(".closeDialog").click(function () {
        $('#dialog-overlay').hide();
        $('#loginContainer').fadeOut();

    });
    $('#homeLnk').click(
           function () {
               this.style.behavior = 'url(#default#homepage)';
               this.setHomePage(location.href);
           });

    $('#printLnk').click(
           function () {
               window.print();
           });

    $('#bookmarkLnk').click(
           function () {
               if (window.external)
                   window.external.AddFavorite(location.href, document.title)
               else if (window.sidebar) window.sidebar.addPanel(document.title, location.href, "");
               else alert("Your browser doesn't support this function.");
           });



    $('#emailLnk').click(
         function () {
             $("#emailPage").slideToggle();
         });


    $("#btnSendFriend").click(
    function () {
        var yourName = $("input#yourName").val();
        var yourEmail = $("input#yourEmail").val();
        var friendName = $("input#friendName").val();
        var friendEmail = $("input#friendEmail").val();

        if (yourName == '') { alert("Please complete all fields"); return false }

        var dataString = 'yName=' + yourName + '&yEmail=' + yourEmail + '&fName=' + friendName + '&fEmail=' + friendEmail + '&title=' + document.title + '&href=' + location.href;
        //alert (dataString);return false;
        $.ajax({
            type: "POST",
            url: root + "sendfriend.ashx",
            data: dataString,
            success: function () {
                $('#emailPage').append("<div id='message'></div>");
                $('#message').html("<img id='checkmark' src='/img/check.png' /> <strong>email sent to " + friendName + "</strong>")
                $("input#friendName").val('');
                $("input#friendEmail").val('');
            }
        });

        return false;

    })

});

function showLogin() {
	$("#dialog-overlay").css({ "opacity": "0.7" }).fadeIn("fast");
        $('#loginContainer').center().fadeIn();
}

(function ($) { $.fn.extend({ center: function () { return this.each(function () { var top = ($(window).height() - $(this).outerHeight()) / 2; var left = ($(window).width() - $(this).outerWidth()) / 2; $(this).css({ position: 'fixed', margin: 0, top: (top > 0 ? top : 0) + 'px', left: (left > 0 ? left : 0) + 'px' }); }); } }); })(jQuery);

    function initScroll() {


        $(".scroll").click(function (event) {
            //prevent the default action for the click event
            event.preventDefault();

            //get the full url - like mysitecom/index.htm#home
            var full_url = this.href;
            if (full_url != '') {
                //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
                var parts = full_url.split("#");
                var trgt = parts[1];

                //get the top offset of the target anchor
                var target_offset = $("#" + trgt).offset();
                var target_top = target_offset.top - 9;

                //goto that anchor by setting the body scroll top to anchor top
                $('html, body').animate({ scrollTop: target_top }, 500);
            }
        });

}


