/*

	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.project.customMenu]);
    //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.project.resumeOpen = false;
    $('.work-for-psp, .close-work').click(thunder.client.project.toggleResume);
    thunder.client.workarounds.alphaImages();
    thunder.client.workarounds.labelAsBrowser();
    $('.work-file').css('opacity', 0).change(thunder.client.project.reflectUpload);
    $('.callout-accent').css({ opacity: 0 });
    thunder.client.project.callouts = $('.callout').mouseenter(thunder.client.project.calloutEnter).mouseleave(thunder.client.project.calloutLeave);
    thunder.client.project.writeCarousel('0');
    $('.close-book').click(thunder.client.project.closePopup);
    thunder.client.project.carouselCategories = $('.header-image').find('img').click(thunder.client.project.getCategory).mouseenter(thunder.client.project.getCategory).mouseleave(thunder.client.project.getCategory);
    $('.header-imagesub').find('img').click(function () { window.location = '/default.aspx'; });
}

thunder.client.project.getCategory = function(evt)
{
	if(evt.type=='click')
	{
		thunder.client.project.writeCarousel(thunder.client.project.carouselCategories.index(this) + 1);
		thunder.client.project.closePopup();
	}
	else if(evt.type=='mouseenter')
	{
		$(this).stop(true, false).animate({opacity: 1}, {duration: 400});
		thunder.client.project.carouselCategories.not(this).stop(true, false).animate({opacity: 0.15}, {duration: 400});
	}
	else
	{
		thunder.client.project.carouselCategories.not(this).stop(true, false).animate({opacity: 1}, {duration: 400});
	}
}

function selectCategoryZero()
{
	thunder.client.project.writeCarousel('0');
}


thunder.client.project.writeCarousel = function (categoryNumber) {
    if ($('#carousel').length > 0) {
        var so = new SWFObject('/themes/main/flash/carousel.swf', 'carouselSwf', '955', '650', '9', '');
        so.addParam('quality', 'high');
        so.addParam('wmode', 'transparent');
        so.addVariable('dataPath', '/themes/main/flash/flash.ashx');
        so.addVariable('basePath', '');
        so.addVariable('category', categoryNumber);
        if (so.write('carousel') == false) {
            $('#carousel').html('<div class="flash-warning">We detect that you are not using the latest version of Adobe Flash Player. For optimal viewing, download the latest version <a href="http://get.adobe.com/flashplayer/" target="_blank">here</a>.</div>');
        }
    }
}

thunder.client.project.reflectUpload = function()
{
	$('.work-file-changer').text($(this).val());
}

thunder.client.project.toggleResume = function()
{
	thunder.client.project.resumeOpen = !thunder.client.project.resumeOpen;
	$('.work-dropdown').stop(true, false).animate({height: thunder.client.project.resumeOpen ? 345 : 0}, {duration: 300});
}

thunder.client.project.customMenu = {
	over: function(obj)
	{
		if(thunder.client.project.resumeOpen) thunder.client.project.toggleResume();
		var o = $(obj);
		var h = o.find('.thunder-dropdown').children().length * 24;
		$('.thunder-dropdown').removeClass('dropdown-in-front');
		o.find('.nav-menu-heading').addClass('nav-menu-heading-on').stop(true, false).animate({top: -10, paddingTop: 6, paddingBottom: 8}, {duration: 300});
		o.find('.thunder-dropdown').addClass('dropdown-in-front').css('display', 'block').stop(true, false).animate({height: h}, {duration: 400});
	},
	out: function(obj)
	{
		var o = $(obj);
		o.find('.nav-menu-heading').stop(true, false).animate({top: 0, paddingTop: 1, paddingBottom: 2}, {duration: 300});
		o.find('.thunder-dropdown').stop(true, false).animate({height: 0}, {duration: 400, complete: thunder.client.project.endMenu});
		if (o.find('.thunder-dropdown').length <= 0) {
            o.find('.nav-menu-heading-on').removeClass('nav-menu-heading-on');
        }
    },
	init: function(obj)
	{
		var o = $(obj);
		o.find('.thunder-dropdown').css({left: -130 + ((o.find('.nav-menu-heading').width()+15) / 2) });
	}
}

thunder.client.project.calloutEnter = function()
{
	$(this).find('.callout-accent').stop(true, false).animate({opacity: 1}, {duration: 200});
	thunder.client.project.callouts.not(this).stop(true, false).animate({opacity: .3}, {duration: 500});
}

thunder.client.project.calloutLeave = function()
{
	$(this).find('.callout-accent').stop(true, false).animate({opacity: 0}, {duration: 200});
	thunder.client.project.callouts.not(this).stop(true, false).animate({opacity: 1}, {duration: 500});
}

thunder.client.project.endMenu = function() { var t = $(this); t.css('display', 'none'); t.parent().find('.nav-menu-heading-on').removeClass('nav-menu-heading-on'); }

$(thunder.client.project.pageLoaded);

function expandEMag(n,a) {
    //alert(a);
	$('.hoop').css('display','none');
	$('.close-book').css({display: 'block'});
	$('.open-book').attr('src', n).css({display: 'block'});
//	window.open(n, 'expandedEMag', 'location=0,status=0,scrollbars=0,width=640,height=480,directories=0,toolbar=0');
}

thunder.client.project.closePopup = function()
{
	$('.hoop').css('display','');
	$('.close-book').css({display: 'none'});
	$('.open-book').css({display: 'none'});
}
