/*

	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 ByHand = {};

ByHand.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();
	ByHand.currentSponsorFold = 0;
	ByHand.sponsorFolds = $('.sponsor-logo-fold');
	ByHand.sponsorTimer = setInterval(ByHand.scrollSponsors, 6000);


	
	loadTicker2("#newsScrolling");
}

ByHand.scrollSponsors = function()
{
	ByHand.sponsorFolds.eq(ByHand.currentSponsorFold).stop(true, false).slideUp(500);
	ByHand.currentSponsorFold ++;
	if(ByHand.currentSponsorFold >= ByHand.sponsorFolds.length) ByHand.currentSponsorFold = 0;
	ByHand.sponsorFolds.eq(ByHand.currentSponsorFold).stop(true, false).slideDown(500);
}


ByHand.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");
}

function loadTicker2(id) {
    var ticker = $(id);
    var tHeight = 0;
    //wrap dt:dd pairs in divs
    ticker.children('p').each(function () {
        tHeight += $(this).outerHeight();
    });

    if (tHeight < $(ticker).innerHeight()) return false;

    //hide the scrollbar
    ticker.css("overflow", "hidden");

    //animator function
    function animator(currentItem) {

        //work out new anim duration
        var distance = currentItem.outerHeight();
        duration = (distance + parseInt(currentItem.css("marginTop"))) / 0.015;

        if (duration == 0) duration = 600;

        //animate the first child of the ticker
        currentItem.animate({ marginTop: -distance }, duration, function () {
            //move current item to the bottom                                
            currentItem.appendTo(currentItem.parent()).css("marginTop", 0);

            //recurse
            animator(currentItem.parent().find("p:first"));
        });
    };

    //start the ticker
    animator(ticker.children("p:first"));

    //set mouseenter
    ticker.mouseenter(function () {
        ticker.children('p').stop();
    });

    //set mouseleave
    ticker.mouseleave(function () {
        animator(ticker.children("p:first"));
    });
}

$(ByHand.pageLoaded);
