﻿/*var loaded = 0;
var popupStatus = 0;
*/
$(document).ready(function () {
    var config = {
        sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
        interval: 0, // number = milliseconds for onMouseOver polling interval    
        over: expandMenu, // function = onMouseOver callback (REQUIRED)    
        timeout: 300, // number = milliseconds delay before onMouseOut    
        out: collapseMenu // function = onMouseOut callback (REQUIRED)    
    };

    $(".nav ul li").hoverIntent(config);
    $('body').append('<div class="olay">');
});

function expandMenu() {
    jQuery(this).find("> ul").show();
}

function collapseMenu() {
    jQuery(this).find("> ul").hide();
}

$.fn.loadPopup = function (parent) {
    if ($(this).length > 0) {
        $(".olay").css({
            "opacity": "0.75"
        });
        $(".olay").fadeIn("slow");
        $(this).fadeIn("slow");
        var e = $(this);
        $('.olay').click(function () {
            if (parent != null) {
                $(e).disablePopup(parent);
            } else {
                $(e).disablePopup();
            }
        });
        $(window).resize(function () {
            $(e).center();
        });
    }
};

$.fn.disablePopup = function (parent) {
    if ($(this).length > 0 && $(this).css('position') == "fixed") {
        $(".olay").fadeOut("slow");
        $(this).fadeOut("slow", function () {
            if ($(this).get(0).tagName == "IFRAME") {
                $(parent).append($(this));
                var html = $(this).outerHTML();
                $(this).replaceWith(html);
            }
        });
    }
};

$.fn.center = function () {
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var thisHeight = $(this).height();
    var thisWidth = $(this).width();

    $(this).css({
        "position": "fixed", //absolute
        "top": windowHeight / 2 - thisHeight / 2/* + $(window).scrollTop()*/,
        "left": windowWidth / 2 - thisWidth / 2
    });

    $(".olay").css({
        "height": windowHeight
    });
};

$.fn.outerHTML = function (s) {
    return (s)
			? this.before(s).remove()
			: $('<p>').append(this.eq(0).clone()).html();
};

/*function createPlayer(id, vfile, vimage) {
    if (id == null)
        id = "ply";
    if (vfile == null)
        vfile = "http://www.longtailvideo.com/jw/upload/bunny.flv";
    if (vimage == null)
        vimage = "http://www.longtailvideo.com/jw/upload/bunny.jpg";
    jwplayer(id).destroy();
    jwplayer(id).setup({
        flashplayer: "/App_Support/ClientSwf/player.swf",
        file: vfile,
        image: vimage,
        height: 360,
        skin: "/App_Support/ClientScript/glow.zip",
        width: 640
    });
}



function loadVideo(array, id) {
    if (id == null)
        id = "ply";
    jwplayer(id).load(array);
}

function loadPopup(popup) {

    if (popupStatus == 0) {
        $(".olay").css({
            "opacity": "0.45"
        });
        $(".olay").fadeIn("slow");
        $(popup).fadeIn("slow");
        popupStatus = 1;
    }
}

function disablePopup() {

    if (popupStatus == 1) {
        $(".olay").fadeOut("slow");
        $('.popup').fadeOut("slow");
        popupStatus = 0;
    }
}

function centerPopup(popup) {
        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
        var popupHeight = $(popup).height();
        var popupWidth = $(popup).width();

        $(popup).css({
            "position": "absolute",
            "top": windowHeight / 2 - popupHeight / 2,
            "left": windowWidth / 2 - popupWidth / 2
        });

        $(".olay").css({
            "height": windowHeight
        });
}*/
