﻿$(document).ready(function () {
    /*
    ############################################################################
    NAVIGATION FUNCTIONS: BEGIN
    ############################################################################
    */
    var timeout = 300;
    var closetimer = 0;
    var ddmenuitem = 0;

    function nav_open() {
        //cancel close timer...
        nav_canceltimer();

        //close old layer...
        nav_close();

        //get new layer and show it...
        ddmenuitem = $(this).find('div').css('visibility', 'visible');
        $(this).find('a').css('background-position', '0 -45px');
    }

    function nav_close() {
        if (ddmenuitem) {
            $(ddmenuitem).siblings('a').css('background-position', '0 0');
            $(ddmenuitem).css('visibility', 'hidden');
        }
    }

    function nav_timer() {
        closetimer = window.setTimeout(nav_close, timeout);
    }

    function nav_canceltimer() {
        if (closetimer) {
            window.clearTimeout(closetimer);
            closetimer = null;
        }
    }

    $('.n_sub').bind('mouseover', nav_open);
    $('.n_sub').bind('mouseout', nav_timer);
    $('.n_home,.n_contactus').bind('mouseover', nav_close);
    /*
    ############################################################################
    NAVIGATION FUNCTIONS: END
    ############################################################################
    */

    /* prevent sharing on images through meebo */
    $(":image").attr("meebo:notsharable", "true");
    $("a").attr("meebo:notsharable", "true");

    //setup homepage slideshow
    $('#photos').galleryView({
        panel_width: 610,
        panel_height: 165,
        frame_width: 50,
        frame_height: 50,
        pause_on_hover: true,
        nav_theme: 'light'
    });
});

//////////////////////////////////////////////////////////////////////////////////////
//Launch a modal popup...
//////////////////////////////////////////////////////////////////////////////////////
var popupStatus = 0;

function launchModal(modw, modh, url) {
    if (popupStatus == 0) {
        $("div#modalPopupBackground").css({
            'opacity': '0.7'
        });

        $("div#modalPopupBackground").css({
            'height': $(document).height(),
            'width': $(document).width()
        }).fadeIn("slow");
        $("div#modalPopup").css({
            'height': modh,
            'width': modw
        }).fadeIn("slow");

        $("div#modalPopup").center();

        $("iframe#modalIframe")
            .css({
                'width': '100%',
                'height': '100%'
            })
            .attr({
                'src': url
            });

        popupStatus = 1;
    }
}

//////////////////////////////////////////////////////////////////////////////////////
//Close a modal popup...
//////////////////////////////////////////////////////////////////////////////////////
function closeModal() {
    if (popupStatus == 1) {
        $("div#modalPopup").fadeOut('slow');
        $("div#modalPopupBackground").fadeOut('slow');
        $("iframe#modalIframe")
            .attr({
                'src': ''
            });
        popupStatus = 0;
    }
}