/*

	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 IXPistonPower = {};

IXPistonPower.pageLoaded = function()
{
	//thunder.client.IXPistonPower.flashReplace();
	//thunder.client.modify.rollImages();
	//thunder.client.modify.linkOptions();
	//thunder.client.modify.tabSet();
	thunder.client.modify.treeMenu(false, [IXPistonPower.ixTreeMenu]);
	//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();
	IXPistonPower.mayTransition = true;
	IXPistonPower.boxes = $('.box-button').click(IXPistonPower.expandCollapseBox).parent().parent();
	$('.box-close').click(IXPistonPower.expandCollapseBox);
	//IXPistonPower.flashVideo();
	IXPistonPower.homeNews = $('.recent-news-item');
	IXPistonPower.currentNewsItem = -1;
	IXPistonPower.scrollNews();
	if (IXPistonPower.homeNews.length > 1)
	    IXPistonPower.newsTimer = setInterval(IXPistonPower.scrollNews, 4000);

	IXPistonPower.currentSponsorFold = 0;
	IXPistonPower.sponsorFolds = $('.sponsor-logo-fold');
	IXPistonPower.sponsorTimer = setInterval(IXPistonPower.scrollSponsors, 6000);
}

IXPistonPower.scrollSponsors = function()
{
	IXPistonPower.sponsorFolds.eq(IXPistonPower.currentSponsorFold).stop(true, false).slideUp(500);
	IXPistonPower.currentSponsorFold ++;
	if(IXPistonPower.currentSponsorFold >= IXPistonPower.sponsorFolds.length) IXPistonPower.currentSponsorFold = 0;
	IXPistonPower.sponsorFolds.eq(IXPistonPower.currentSponsorFold).stop(true, false).slideDown(500);
}

IXPistonPower.scrollNews = function()
{
	if(IXPistonPower.currentNewsItem >= 0)
	{
		IXPistonPower.homeNews.eq(IXPistonPower.currentNewsItem).stop(true, false).animate({top: -160}, {duration: 1000});
	}
	IXPistonPower.currentNewsItem ++;
	if(IXPistonPower.currentNewsItem >= IXPistonPower.homeNews.length) IXPistonPower.currentNewsItem = 0;
	IXPistonPower.homeNews.eq(IXPistonPower.currentNewsItem).stop(true, false).css({top: 160}).animate({top: 0}, {duration: 1000});
}

IXPistonPower.expandCollapseBox = function()
{
	if(IXPistonPower.mayTransition)
	{
		IXPistonPower.mayTransition = false;
		var expandedBoxes = $('.box-on');
		if(expandedBoxes.length>0)
		{
			expandedBoxes.removeClass('box-on');
			IXPistonPower.boxes.stop(true, false).animate({paddingLeft: 2, paddingRight: 2, width: 154}, {duration: 500}).next().stop(true,false).animate({paddingLeft: 0, paddingRight: 0, width: 0}, {duration: 500, complete: IXPistonPower.allowTransition});
			$('.box-button').text('click to learn more');
		}
		else
		{
			expandedBoxes = $(this).parent().parent();
			expandedBoxes.addClass('box-on');
			expandedBoxes.next().stop(true,false).animate({paddingLeft: 20, paddingRight: 40, width: 730}, {duration: 500, complete: IXPistonPower.allowTransition});
			$('.box-button').text('click to close');
			IXPistonPower.boxes.not(expandedBoxes).stop(true, false).animate({paddingLeft: 0, paddingRight: 0, width: 0}, {duration: 500});
		}
	}
}

IXPistonPower.allowTransition = function()
{
	IXPistonPower.mayTransition = true;
}

IXPistonPower.ixTreeMenu = {
	over: function(obj)
	{
	},
	out: function(obj)
	{
	},
	init: function(obj)
	{
		var menuItem = $(obj);
		var w = menuItem.children('.menu-heading').width();
		if(menuItem.hasClass('dropdown-moved'))
		{
			menuItem.children('.menu-activated').css({left: (w / 2) - 200});
		}
		else
		{
			menuItem.children('.menu-activated').css({left: (w / 2) - 118});
		}
	}
}


IXPistonPower.flashVideo = function()
{
	if($('#flash-video').length == 0) return false;
	var so;
	so = new SWFObject("/presentation/pistonpower/flash/pistonPower.swf", "swf-obj-1", "289", "260", "9", "");
	so.addParam("quality", "high");
	so.addParam("wmode", "transparent");
	so.write("flash-video");
}

IXPistonPower.flashVideoCustom = function(customPath)
{
	if($('#flash-video').length == 0) return false;
	var so;
	so = new SWFObject("/presentation/pistonpower/flash/video-player.swf", "swf-obj-1", "289", "260", "9", "");
	so.addParam("quality", "high");
	so.addParam("wmode", "transparent");
	
	so.addVariable("autoStart","true");
	so.addVariable("content_video", customPath);
	so.write("flash-video");
}



$(document).ready(IXPistonPower.pageLoaded);
