/*

	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);
	if ($(".slide").length > 1) { thunder.client.modify.scrollFeature(674, 8000, 500); }
	if ($(".slidemilan").length > 1) { Project.scrollFeatureMilan(480, 8000, 500); }
	thunder.client.workarounds.alphaImages();
	thunder.client.workarounds.labelAsBrowser();
	
	$(".menu-dropdown").each(function(){
		var widest = null;
		$(".menu-item", this).each(function() {
		  if (widest == null){
			widest = $(this).width();
		  }else{
			if ($(this).width() > widest){ widest = $(this).width(); }
		  }
		});
		
		$(this).width(widest);
		$(".menu-item", this).each(function(){ $(this).width(widest); });
	});

	$(".thunder-menu > .menu-item:first a").css("border", "none");
}

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");
}

Project.sitesearch = function () {
    var keywords = $("#searchfield").val();

    if (keywords != '') {
        window.location = '/site-search.aspx?keywords=' + keywords;
    }
    return false;

}

$(Project.pageLoaded);

function disableMe(t) {
    $(t).attr('disabled', 'disabled');
    $("#processing").html("<img src='/thunder/images/processingbar.gif'/>");
}


// method thunder.client.modify.scrollFeature()
// parameters
// - scrollImageWidth
// - scrollImageTime (ms)
// - scrollImageAnimationTime (ms)
// hook: .thunder-scroll-feature [total object], .thunder-scroll-viewport [overflow container], .thunder-scroll-left [click], .thunder-scroll-right [click]
// output: controlling style.left
// returns: object with control functions
Project.scrollFeatureMilan = function (scrollImageWidth, scrollImageTime, scrollImageAnimationTime, scrollCallback) {
    var _feature = {};
    _feature.counting = false;
    _feature.index = -1;
    _feature.direction = 1;
    _feature.precommence = function () {
        _feature.timeout = setTimeout(_feature.change, scrollImageTime);
        _feature.counting = true;
    }
    _feature.commence = function () {
        if (_feature.counting == true) {
            _feature.counting = false;
            clearTimeout(_feature.timeout);
        }
        _feature.change();
    }
    _feature.next = function () { _feature.direction = 1; _feature.commence(); }
    _feature.previous = function () { _feature.direction = -1; _feature.commence(); }
    _feature.change = function () {
        _feature.previndex = _feature.index;
        _feature.index += _feature.direction;
        if (_feature.index >= _feature.images.length) _feature.index = 0;
        if (_feature.index < 0) _feature.index = _feature.images.length - 1;
        _feature.scrollNow();
    }
    _feature.changeTo = function (newIndex) {
        clearTimeout(_feature.timeout);
        _feature.previndex = _feature.index;
        _feature.index = newIndex;
        if (_feature.index >= _feature.images.length) _feature.index = 0;
        if (_feature.index < 0) _feature.index = _feature.images.length - 1;
        if (_feature.index != _feature.previndex) _feature.scrollNow();
    }
    _feature.scrollNow = function () {
        if (scrollCallback) scrollCallback(_feature);
        if (_feature.previndex >= 0) {
            if (_feature.direction > 0)
                $(_feature.images[_feature.previndex]).animate({ 'left': 0 - scrollImageWidth }, { duration: scrollImageAnimationTime, queue: false });
            else
                $(_feature.images[_feature.previndex]).animate({ 'left': scrollImageWidth }, { duration: scrollImageAnimationTime, queue: false });
        }
        if (_feature.index >= 0) {
            if (_feature.direction > 0)
                _feature.images[_feature.index].style.left = scrollImageWidth + 'px';
            else
                _feature.images[_feature.index].style.left = '-' + scrollImageWidth + 'px';
            $(_feature.images[_feature.index]).animate({ 'left': 0 }, { duration: scrollImageAnimationTime * .95, queue: false });
        }
        _feature.precommence();
    }
    _feature.images = $('.thunder-scroll-featureslidemilan').children('.scroll-viewportslidemilan').find('.slidemilan');
    _feature.images.css('left', '-' + scrollImageWidth + 'px');
    if (_feature.images.length > 0) { _feature.commence(); _feature.images[0].style.left = 0; }
    $('.thunder-scroll-featureslidemilan').children('.scroll-left').click(_feature.previous);
    $('.thunder-scroll-featureslidemilan').children('.scroll-right').click(_feature.next);
    return _feature;
};

