﻿//document ready
//var showMenu = null;
var defaultSearchText = "Search";

$(document).ready(function() {
    //round corner of image
    //$('.ImageArea img').corner();

    $('#MainNavMenu li:has(ul)').each(function() {
        $(this).mouseover(function(event) {
            $(this).addClass('Hover');
            setTimeout("ShowMenu($('#" + $(this).attr("id") + "'), false)", 500);
            //ShowMenu(this, false);
        });
        $(this).mouseout(function(event) {
            $(this).removeClass('Hover');
            setTimeout("ShowMenu($('#" + $(this).attr("id") + "'), true)", 500);
            //ShowMenu(this, true);
        });
        $(this).click(function(event) {
            var url = $(this).attr('url');

            if (url == null || url == "") {
                return false;
            }

            window.location.href = url;
        });
    });

    $('#txtHeaderSearch').keyup(function(event) {
        if (event.keyCode == 13) {
            Search();
            return false;
        }

        return true;
    });

    $('#txtHeaderSearch').focus(function(event) {
        if ($(this).val().search(new RegExp(defaultSearchText, "i")) == 0) {
            $(this).val("");
        }
    });

    $('#txtHeaderSearch').blur(function(event) {
        if ($(this).val().length == 0) {
            $(this).val(defaultSearchText);
        }
    });

    //Preload Css Images
    $.preloadCssImages();
});

function Search() {
    var search = $('#txtHeaderSearch').val();

    if (search == null ||
        search.lengh == 0) {
        return false;
    }
    
    //construct Url and send user to search page.    
    window.location = ResolveUrl("~/SearchResults.aspx?s=" + search);
}

function ShowMenu(element, close) {
    if (typeof element == 'undefined' || element == null) {
        throw new Error();
        return;
    }

    if (typeof close == 'undefined' || close == null) {
        close = false;
    }
    
    var hoverCss = $(element).attr('id') +'Hover';

    if (close == false) {
        if($(".Hover").length == 1 && $(element).hasClass('Hover') == true)
            if ($(element).hasClass(hoverCss) == false) {
                $(element).addClass(hoverCss);
                $(element).children().show();
            }
    }
    else {
        if ($(element).hasClass(hoverCss) && !$(element).hasClass('Hover')) {
            //setTimeout("$('#" + $(element).attr('id') + "').children().hide(); $('#" + $(element).attr('id') + "').removeClass('" + hoverCss +"');", 250);
            $(element).children().hide();
            $(element).removeClass(hoverCss);
        }      
    }
}

function OpenNewWindow(url) {
    var winH = window.open(url);
}

function onSplashImageBefore() {
    $(this).unbind('click');
    $(this).unbind('mouseover');
    
    $(this).mouseover(function() {
        $(this).css('cursor', 'pointer');
    });
    
    $(this).click(function() {
        var winH = window.open($(this).attr('url'));
        return false;
    });
}

function InitSplash() {
    $('#splashRotator').before('<div id="splashRotatorNav">').cycle({
        fx: 'fade',
        speed: 'fast',
        timeout: 5000,
        pager: '#splashRotatorNav',
        before: onSplashImageBefore
    });
}

function joinImeeting(URL) {
    day = new Date();
    id = day.getTime();
    
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=700,height=520');");
}