/*

	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 Project = {};

Project.pageLoaded = function () {
    //thunder.client.project.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.alphaImages();
    thunder.client.workarounds.labelAsBrowser();
    $('.header-bar-submenu-item-over').css({ opacity: 0 }).mouseover(Project.handleButton).mouseout(Project.handleButton);
    $('.header-search-input').focusin(Project.handleInputFocus).focusout(Project.handleInputFocus);
    $('.menu-dropdown-item').mouseover(Project.handleDropdownMouse).mouseout(Project.handleDropdownMouse);
	$('.sub-menu-item').mouseover(Project.handleSubmenuMouse).mouseout(Project.handleSubmenuMouse);
    
    $('.header-bar-image-container-sub-nav-item-over').css({ opacity: 0 }).mouseover(Project.handleButtonMouse).mouseout(Project.handleButtonMouse);
    $('.button-over').css({ opacity: 0 }).mouseover(Project.handleButtonMouse).mouseout(Project.handleButtonMouse);
    Project.initSubmenuBack();

    $(".menu-dropdown .menu-dropdown-item:last-child a").css("background", "url(/themes/main/images/clear.gif)");
	if(location.href.indexOf("/thunder") < 0){ $('.header-bar-image').cycle(); }

    if($(".slider").length > 0){
		$('.slider').scrollIt({
			menuHeight: 63,
			menuWidth: 460,
			itemHeight: 63,
			itemWidth: 76,
			itemMargin: 0,
			minItems: 6
		});
		$('.mainImageFrame').html($(".slider li:first-child").html().replace("thumb2_", "big2_"));
		$(".imageRotator li img").click(function () {
			$(".loading").css("display", "block");
			$('.curNum').html($(this).attr('thunder:number'));
			$('.mainImageFrame img').attr("src", $(this).attr("src").replace("thumb2_", "big2_"));
			$('.mainImageFrame img').load(function () {
				$(".loading").css("display", "none");
			});
		});
	}
	
	 
}

Project.handleButtonMouse = function( evt )
{
	$(this).stop(true,false).animate({opacity: evt.type == "mouseover" ? 1 : 0 }, 300 );	
}

Project.handleSubmenuMouse = function ( evt )
{
	if( evt.type == "mouseover" )
	{
		$(this).addClass('active');
	}
	else
	{
		$(this).removeClass('active');
	}
}

Project.handleDropdownMouse = function ( evt )
{
	if( evt.type == "mouseover" )
	{
		$(this).addClass('menu-dropdown-on');
	}
	else
	{
		$(this).removeClass('menu-dropdown-on');
	}
}

Project.initSubmenuBack = function () {
    var submenu = $('.sub-menu-back');

    if (submenu.size() > 0) {
        
        var targetY = submenu.parent().parent().height() + submenu.position().top + 20;
        var targetX = (targetY) / 435 * 24 + submenu.position().left;
        submenu.stop(true, false).animate({ top: targetY, left: targetX }, 800);
    }

}

Project.handleButton = function( evt )
{
	$(this).stop(true,false).animate({opacity: evt.type == "mouseover" ? 1 : 0}, 800 );
}

Project.handleInputFocus = function( evt )
{
	if( evt.type == "focusin" )
	{
		if( $(this).val() == "Search Our Site" ) 
		{	
			$(this).val("");
		}
	}
	else
	{
		if( $(this).val() == "" ) 
		{
			$(this).val("Search Our Site");
		}
	}
}

Project.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");
}

$(document).ready(Project.pageLoaded);
