/*

	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);
    //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();
    if ($.cookie('csctheme') != null) thunder.client.project.changeTheme($.cookie('csctheme'));
    if ($.cookie('cscsize') != null) thunder.client.project.initSizeTo($.cookie('cscsize')); else thunder.client.project.spatialize();
    
    if ($("#bannerImage").html() == '&nbsp;' || $("#bannerImage").html() == '') {        
        $("#bannerImage").html('<img src="/media/images/main-photo-1.jpg" alt="banner image of girl smiling"/>')
    }
}

thunder.client.project.theme = 'light';
thunder.client.project.size = 0;
thunder.client.project.sizeDirection = 0;

thunder.client.project.changeTheme = function (themeId) {
    $.cookie('csctheme', themeId);
    $('body').removeClass('theme-light').removeClass('theme-dark').removeClass('theme-mono').addClass('theme-' + themeId);
    
    if (!thunder.client.workarounds.isIE6) {
        if (themeId == 'mono') {
            $('.shadow-blue')[0].src = '/themes/main/images/shadow-gray.png';
        }
        else if (thunder.client.project.theme == 'mono') {
            $('.shadow-blue')[0].src = '/themes/main/images/shadow-blue.png';
        }
    }
    thunder.client.project.theme = themeId;
}

thunder.client.project.changeSizeUp = function()
{
	if(thunder.client.project.size < 5)
	{
		thunder.client.project.size ++;
		thunder.client.project.sizeDirection = 2;
		$('.theme-text-sizable').find('*').each(thunder.client.project.changeElementSize);
		$('.theme-text-children-sizable').children().each(thunder.client.project.changeElementSize);
		thunder.client.project.sizeDirection = 1;
		$('.theme-text-reduced-sizable').find('*').each(thunder.client.project.changeElementSize);
	}
	thunder.client.project.completeResize();
}

thunder.client.project.changeSizeDown = function()
{
	if(thunder.client.project.size > 0)
	{
		thunder.client.project.size --;
		thunder.client.project.sizeDirection = -2;
		$('.theme-text-sizable').find('*').each(thunder.client.project.changeElementSize);
		$('.theme-text-children-sizable').children().each(thunder.client.project.changeElementSize);
		thunder.client.project.sizeDirection = -1;
		$('.theme-text-reduced-sizable').find('*').each(thunder.client.project.changeElementSize);
	}
	thunder.client.project.completeResize();
}

thunder.client.project.initSizeTo = function(n)
{
	n = parseInt(n);
	if(n>0)
	{
		thunder.client.project.size = n;
		thunder.client.project.sizeDirection = n * 2;
		$('.theme-text-sizable').find('*').each(thunder.client.project.changeElementSize);
		$('.theme-text-children-sizable').children().each(thunder.client.project.changeElementSize);
		thunder.client.project.sizeDirection = n;
		$('.theme-text-reduced-sizable').find('*').each(thunder.client.project.changeElementSize);
	}
	thunder.client.project.completeResize();
}

thunder.client.project.completeResize = function()
{
	$.cookie('cscsize', thunder.client.project.size);
	thunder.client.project.spatialize();
}

thunder.client.project.spatialize = function()
{
	var m = $('.menu-one').height();
	$('.shadow-gray').height(m + 150)
	var columnOne = $('.content-column-one');
	if(columnOne.length > 0)
	{
		var columnTwo = $('.content-column-two');
		columnTwo[0].style.height = '';
		var h = parseInt(columnOne.height());
		if(h>columnTwo.height()) columnTwo[0].style.height = h + 'px';
		$('.shadow-blue').height($('.content-area').height() - m + 300)
	}
	else
	{
		$('.shadow-blue').height($('.content-area').height() - m + 270)
	}
}

thunder.client.project.changeElementSize = function()
{
	var q = $(this);
	var s = parseInt(q.css('font-size'));
	if(s > 0)
	{
		var l = parseInt(q.css('line-height'));
		q.css({'fontSize': s + thunder.client.project.sizeDirection, 'lineHeight': (l + thunder.client.project.sizeDirection) + 'px'});
	}
}

thunder.client.project.flashReplace = function()
{
	$('.flash-billboard').flash(
		{
		    swf: '/themes/main/flash/billboard.swf',
			height: 200,
			width: 800,
			allowFullScreen: true,
			allowScriptAccess: 'always',
			hasVersion: 9,
			wmode: 'transparent',
			flashvars: {
				basePath: ''
			}
		}
	);
}

$(document).ready(thunder.client.project.pageLoaded);

