/*

	Filename             sitewide.js
	Detail               Site functionality
	Author:              thunder::tech inc.
	License:             CLIENT is defined as the owner of online property from which this file resides or this code is referenced in.
						 ADDITIONAL PARTY is defined as anyone other than thunder::tech or CLIENT.
						 No right is granted to ADDITIONAL PARTY to sell, distribute, modify or otherwise transfer the following source code without explicit written permission by CLIENT or thunder::tech.

*/

/*  ================================
     Sitewide JavaScript
    ================================ */

var CorporateUnited = {};

CorporateUnited.pageLoaded = function () {
    //thunder.client.CorporateUnited.flashReplace();
    //thunder.client.modify.rollImages();
    //thunder.client.modify.linkOptions();
    //thunder.client.modify.tabSet();
    //thunder.client.modify.treeMenu(false);
    //thunder.client.modify.treeMenu(false, [thunder.client.modes.separatorTreeMenu]);
    //thunder.client.modify.treeMenu(false, [thunder.client.modes.imageTreeMenu]);
    thunder.client.modify.selfLabelFields();
    //thunder.client.modify.requireFields();
    //thunder.client.modify.dropSelector(true);
    //thunder.client.modify.scrollFeature(640, 3000, 500);
    thunder.client.workarounds.labelAsBrowser();
    $('.home-header-menu').children('a').mouseenter(CorporateUnited.homeMenuMouse).mouseleave(CorporateUnited.homeMenuMouse);
    CorporateUnited.homeNews = $('.scrolling-news').children('a');
    $('.home-news').mouseenter(CorporateUnited.controlNewsScroll).mouseleave(CorporateUnited.controlNewsScroll);
    CorporateUnited.currentNewsItem = -1;
    CorporateUnited.scrollNews();
    CorporateUnited.newsTimer = setInterval(CorporateUnited.scrollNews, 5000);
    //$('.tab, .tab-set').corner('top 8px round');
    CorporateUnited.tabs = $('.tab').mouseenter(CorporateUnited.hoverTab).mouseleave(CorporateUnited.hoverTab).click(CorporateUnited.activateTab);
    CorporateUnited.tabPages = $('.tab-page');
    if ($(".tab-on").length <= 0) { activateTabs($('.tab:first-child')); }

    CorporateUnited.activateTable();

}

CorporateUnited.hoverTab = function(evt)
{
	if(evt.type=='mouseenter')
	{
		$(this).addClass('tab-over');
	}
	else
	{
		$(this).removeClass('tab-over');
	}
}

// Desperate attempt to call function and pass object
function activateTabs(temp) {
    $(temp).addClass('tab-on');
    CorporateUnited.tabs.not(temp).removeClass('tab-on');
    var tabPage = CorporateUnited.tabPages.eq(CorporateUnited.tabs.index(temp));
    CorporateUnited.tabPages.not(tabPage).stop(true, false).css({ height: '' }).slideUp(400);
    tabPage.stop(true, false).css({ height: '' }).slideDown(600);
}

CorporateUnited.activateTab = function()
{
	$(this).addClass('tab-on');
	CorporateUnited.tabs.not(this).removeClass('tab-on');
	var tabPage = CorporateUnited.tabPages.eq(CorporateUnited.tabs.index(this));
	CorporateUnited.tabPages.not(tabPage).stop(true, false).css({height: ''}).slideUp(400);
	tabPage.stop(true, false).css({height: ''}).slideDown(600);
}

CorporateUnited.scrollNews = function()
{
	if(CorporateUnited.currentNewsItem >= 0)
	{
		CorporateUnited.homeNews.eq(CorporateUnited.currentNewsItem).stop(true, false).animate({top: -25}, {duration: 400});
	}
	CorporateUnited.currentNewsItem ++;
	if(CorporateUnited.currentNewsItem >= CorporateUnited.homeNews.length) CorporateUnited.currentNewsItem = 0;
	CorporateUnited.homeNews.eq(CorporateUnited.currentNewsItem).stop(true, false).css({top: 35}).animate({top: 8}, {duration: 400});
}

CorporateUnited.controlNewsScroll = function(evt)
{
	if(evt.type=='mouseenter')
	{
		clearInterval(CorporateUnited.newsTimer);
		CorporateUnited.newsTimer = null;
	}
	else
	{
		if(CorporateUnited.newsTimer === null) CorporateUnited.newsTimer = setInterval(CorporateUnited.scrollNews, 5000);
	}
}

CorporateUnited.homeMenuMouse = function(evt)
{
	var sliderBar = $(this).children('.slider-bar');
	if(evt.type=='mouseenter')
	{
		sliderBar.stop(true, false).animate({height: 14}, {duration: 400});
	}
	else
	{
		sliderBar.stop(true, false).animate({height: 0}, {duration: 400});
	}
}

CorporateUnited.flashReplace = function()
{
	var so;
	so = new SWFObject("flash/swf1.swf", "swf-obj-1", "300", "250", "9", "");
	so.addParam("quality", "high");
	so.addParam("wmode", "transparent");
	so.write("swf-holder-1");
}

CorporateUnited.activateTable = function () {
    if ($('.offerings-tabs').length == 0) return false;
    $(".offerings-content tr:nth-child(2n)").addClass("alt");
    $(".offerings-content tr td:nth-child(2)").css("background", "#1F629A").addClass("middle");
    $(".alt td:nth-child(2)").css("background", "#2D76AE").addClass("middle");
    $(".offerings-tabs a:last").css("background", "none");

    $(".offerings-tabs a").click(function () {
        $(".offerings-tabs a").each(function () {	 //reset all tabs
            $(this).attr("class", $(this).attr("class").replace("active-", ""));
            $(this).css("background", "url(images/divider.jpg) no-repeat right 8px");
        });
        $(".offerings-tabs a:last").css("background", "none");

        $(this).css("background", "url(images/bg-offering" + $(this).attr("class") + ".png) no-repeat");
        $(this).attr("class", "active-" + $(this).attr("class"));

        $(".human-resources, .facilities, .general-office, .telecom, .view-all").addClass("hidden"); //jquery + IE7 + changing css display of class = not work
        $($(this).attr("name")).removeClass("hidden");
        $(this).prev().css("background", "none");


    });

    $(".offerings-content a").each(function () {
        if ($(this).siblings("img").length > 0) {
            if ($(this).html().length <= 19) { $(this).css("padding-top", "15px"); }
            else if ($(this).html().length <= 39) { $(this).css("padding-top", "3px"); }
        } else {
            $(this).css("padding-left", "58px");
        }
    });
    if ($(".active-tab3").length > 0) {
        $(".active-tab3").css("background", "url(images/bg-offeringtab3.png)");
        $(".human-resources, .facilities, .telecom, .view-all").addClass("hidden");
    } else {
        $(".active-tab1").css("background", "url(images/bg-offeringtab1.png)");
    }
}

///message board search 
function forumSearch() {
    if (document.getElementById("forumsearchfield")) {

        var searchterm = document.getElementById("forumsearchfield").value;
        window.location = "/messageboard/search/default.aspx?keywords=" + searchterm;
        return false;


    } else { return false; }
}

$(CorporateUnited.pageLoaded);
