/*

	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
    ================================ */

thunder.client.project.pageLoaded = function()
{
	//thunder.client.project.flashReplace();
	//thunder.client.modify.rollImages();
	//thunder.client.modify.linkOptions();
	//thunder.client.modify.tabSet();
	//thunder.client.modify.treeMenu(false, true);
	//thunder.client.modify.treeMenu(false, true, [thunder.client.modes.separatorTreeMenu]);
	thunder.client.modify.treeMenu(false, true, [thunder.client.modes.fadeHeadingsTreeMenu, thunder.client.modes.fadeDropdownsTreeMenu]);
	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();
	$('.clear-form').click(thunder.client.project.clearForm);
	$('.waverly-industry-content').click( thunder.client.project.handleIndustryClick );
	thunder.client.project.flashReplace();
	thunder.client.project.handleQueryString();
}

thunder.client.project.clearForm = function()
{
	$('.contact-form').find('.field').val('');
}

thunder.client.project.flashReplace = function()
{
	$('.feature').flash(
		{
			swf: 'flash/waverly-banner-4.swf',
			height: 331,
			width: 622,
			allowFullScreen: true,
			allowScriptAccess: 'always',
			hasVersion: 9,
			wmode: 'transparent',
			flashvars: {
				basePath: ''
			}
		}
	);
}

thunder.client.project.handleIndustryClick = function( evt )
{
	var childs = $(this).find('.waverly-industry-content-container');
	var id;
	
	if( $(this).hasClass('is-open') )
	{
		//hide industry content
		$(this).removeClass('is-open');
		childs.css({'display' : ''});
		id = null;
	}
	else
	{
		//show industry content
		$(this).addClass('is-open');
		$(this).children().css({'display' : 'block'});
		id = $(this).attr('target');
		$('.section-menu').children().each( function(){ $(this).attr('href').search('target='+id) >= 0 ? $(this).addClass( 'current-page' ) : $(this).removeClass( 'current-page' ); } );
	}
}

thunder.client.project.getQueryStringItem = function( id )
{
	var qs = window.location.href.toString().split("?")[1].toString().split("&");
	
	for( var i = 0; i < qs.length; i ++ )
	{
		if(qs[i].search(id) != -1)
		{
			return qs[i].substr(id.length + 1).toString();	
		}
	}
}

thunder.client.project.handleQueryString = function()
{
	
	var loc = window.location.href.split("?")[0];
	
	if(loc.search("industries-served.asp") >= 0)
	{
		thunder.client.project.showIndustryDetail(thunder.client.project.getQueryStringItem('target'));
	}
}

thunder.client.project.showIndustryDetail = function( id )
{
	var industry = $('.industry-'+id.toString());
	//show industry content
	$(industry).addClass('is-open');
	industry.children().css({'display' : 'block'});
	//alert( $('.section-menu').children().each( function(){ alert( $(this).attr('href') ); } ) );
	$('.section-menu').children().each( function(){ $(this).attr('href').search('target='+id) >= 0 ? $(this).addClass( 'current-page' ) : $(this).removeClass( 'current-page' ); } );
}

$(thunder.client.project.pageLoaded);
