// JavaScript Document
jQuery(function() {
    jQuery('ul.sf-menu').superfish();
});

$(window).ready(function() {
    $(".detailedInfo").hide();
});

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
	((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

(function($) {
    var cache = [];
    // Arguments are image paths relative to the current page.
    $.preLoadImages = function() {
        var args_len = arguments.length;
        for (var i = args_len; i--; ) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    };
})(jQuery)


$(document).ready(function() {

	
	
	$("table.striped tr:nth-child(even)").css("background-color", "#F5F5F5");

    function crossfadeFX(itemName, pos) {
        $(itemName)
			.css({ backgroundPosition: pos })
			.wrapInner("<div class=\"hoverarea\"></div>")
			.prepend("<div class=\"hoverimage\"></div>");
        $(itemName + " .hoverimage").css({ opacity: 0 })
        $(itemName + " .hoverarea").parent().parent()
			.mouseover(function() {
			    $(this).find("div.hoverimage").stop().animate({ opacity: 1 }, 250);
			})
			.mouseout(function() {
			    $(this).find("div.hoverimage").stop().animate({ opacity: 0 }, 550);
			})
    }

    crossfadeFX("a.imgCrossFade", "0 0");

    $("#memberLink").toggle(function() {
        $(this).css("backgroundImage", "url(../images/ui/icoArrowUpDarkGrey.gif)").css("color", "#025B7B");
        $("#loginHidden").slideDown();
    }, function() {
        $(this).css("backgroundImage", "url(../images/ui/icoArrowDownDarkGrey.gif)").css("color", "#777777");
        $("#loginHidden").slideUp();
    });

    $("ul.expandableList li > a").click(function(e) {
        e.preventDefault();
        $(this).next(".expandable").slideToggle();
        $(this).parent().toggleClass("active");
    });
    $("dl.expandableList dt > a").click(function(e) {
        e.preventDefault();
        $(this).parent().next(".expandable").slideToggle();
        $(this).parent().toggleClass("active");
    });

    $("div:not('.formRow.noborder') .btnMore").click(function() {

        $(".btnMore.active").css("background-image", "url(../images/ui/icoExpandPlus.gif)").next(".detailedInfo").slideUp();
        $(".detailedInfo").slideUp();
        if (!$(this).hasClass("active")) {
            $(".btnMore").removeClass("active");
            $(this).addClass("active");
            $(this).css("background-image", "url(../images/ui/icoCollapseMinus.gif)").next(".detailedInfo").slideDown();
        } else {

            $(this).removeClass("active");
        }


    });

    $("a.hoverFade").each(function(index) {
        thisHover = $(this);
        thisHover.css("background", "url('" + thisHover.find("img").attr("src") + "')").css("width", thisHover.find("img").attr("width") + "px").css("height", thisHover.find("img").attr("height") + "px").css("display", "block");
    });

    $("a.hoverFade img").each(function(index) {
        var thisImgOn = $(this).attr("src").replace("_off", "_on")
        $(this).css("display", "none").attr("src", thisImgOn);
        jQuery.preLoadImages("images/" + thisImgOn);
    });

    $("a.hoverFade").hover(function() {
        $(this).find("img").fadeIn();
    }, function() {
        $(this).find("img").fadeOut();
    });


    if ($("#bannerContainer a").length > 1) {
        $("#bannerContainer").cycle({ pager: '#bannerPager', slideExpr: 'img', timeout: 6000 });
    } else {
        if ($("#bannerContainer a").length == 1) {
            $("#bannerPager").remove();
        }
    }

    if ($("#homeBannerContainer a").length > 1) {
        $("#homeBannerContainer").cycle({ pager: '#homeBannerPager', slideExpr: 'img', timeout: 6000 });

    } else {
        if ($("#homeBannerContainer a").length == 1) {
            $("#bannerPager").remove();
        }
    }


    $(".fontSizeNormal").click(function() {
        $("#contentContainer").css("fontSize", "100%");
        setCookie("largeFont", "", 9999)
    });

    $(".fontSizeLarge").click(function() {
        $("#contentContainer").css("fontSize", "115%");
        setCookie("largeFont", "true", 9999)
    });

    if (getCookie("largeFont")) {
        $("#contentContainer").css("fontSize", "115%");
    }

    /*
	
	$("#loginHidden").live( "mouseout", function(){
    $("#loginHidden").slideUp();	
    });
    */

    $(".globalSearchButton").click(function() {
        if ($('.globalSearchText').val() == '') {
            return false;
        }
        else {
            return true;
        }
    });

    // Custom selector for flv files.
    $.expr[':'].flv = function(obj) {
        return obj.href.match(/^.+(\.(flv))$/i);
    };

    // Hook up video lightboxes
    $('a:flv').overlay({
        target: '#videoOverlay',
        effect: 'apple',

        // when overlay is closed, unload our player
        onBeforeLoad: function() {

            var flvFile = this.getTrigger().attr("href");

            var flashvars = {
                video: flvFile,
                preview: '/images/videoPlayerBackground.png',
                bkgColor: 'ffffff',
                accentColor: '007abb',
                scrubberColor: '007abb',
                hoverColor: '007abb',
                textColor: '007abb',
                width: '498',
                height: '398',
                volume: '0.7',
                videoScale: 'fit',
                autoplay: 'false'
            };

            var params = {
                src: '/flash/videoxpress.swf',
                bgcolor: '#ffffff',
                allowScriptAccess: 'always',
                allowfullscreen: 'true',
                wmode: 'transparent',
                id: 'objVideo',
                width: '498',
                height: '398'
            };

            $('#lightBoxContainer').flashembed(params, flashvars);

        },

        // when overlay is closed, unload our player
        onClose: function() {
            $('#objVideo').stop();
            $('#lightBoxContainer').html('');
        }
    });

    //add odd/even styling to search results
    $('div.searchResultBody div.searchResultEntry:odd').addClass('even');

    if ($('.messages ul.Success').length != 0) {
        setTimeout(function() {
            $('.messages ul.Success').slideUp("Slow");
        }, 5000);
    }
});


function RunResourceListSearch() {
    ReRunSearch('.resourceListKeyword');
}

function RunGlobalSearch(){
    ReRunSearch('.globalSearchInlineKeyword');
}

function ReRunSearch(txtboxID){
    var kwdtxt = $(txtboxID).val();
    if ((kwdtxt != '') && (kwdtxt != undefined)) {
        window.location = qstring.add({ kwd: kwdtxt }).toString();
    }
    if((kwdtxt != '') && (kwdtxt != undefined)){
        window.location = qstring.add({kwd:kwdtxt}).toString(); 
    }
    else {
        window.location = qstring.remove({ kwd: null }).toString();
    }
}

$(document).ready(function() {
    $(".globalSearchInlineKeyword").keyup(function(event){
        if(event.keyCode == 13)
        {
            RunGlobalSearch();
        }
    });
    
    $(".resourceListKeyword").keyup(function(event){
        if(event.keyCode == 13)
        {
            RunResourceListSearch();
        }
    });    
        
});
