/*

	Filename             sitewide.js
	Detail               Site functionality
	Author:              thunder::tech inc.
	License:              No right is granted to any other party than thunder::tech to sell, distribute, modify or otherwise transfer the following source code without explicit written permission by thunder::tech.

*/

var ThunderWeb = { constantInterval : false, animateSwapVisibleParams: false, preventPrimaryShortcutKeys: false, canAnimate: true, currentViewIsChanging: false, preloadObjectsCount: 0, preloadObjectsFlag: false, preloadPageFlag: false, preloadables: [], preloadList: []}, ua = {};

var ARBITRARY_CHANGE_LATER = 0; // remove all instances of this from final code

// Set up for browser environment
ua.Opera = navigator.userAgent.match(/Opera Mini/i);
ua.Android = navigator.userAgent.match(/Android/i);
ua.AndroidTablet = navigator.userAgent.match(/Android/i) && (!navigator.userAgent.match(/Mobile/i));
ua.BlackBerry = navigator.userAgent.match(/BlackBerry/i);
ua.iPhone = navigator.userAgent.match(/iPhone/i);
ua.iPad = navigator.userAgent.match(/iPad/i);
ua.iPod = navigator.userAgent.match(/iPod/i);
ua.ie = navigator.appName == 'Microsoft Internet Explorer' ? "ie" : "";
ua.noPointer = ua.Android || ua.BlackBerry || ua.iPhone || ua.iPod;
ua.noFlash = ua.iPhone || ua.iPad || ua.iPod;
ua.tablet = ua.AndroidTablet || ua.iPad;
//ua.window = $(window).load(ThunderWeb.onLoad);
ua.window = $(window);
ua.window.load(function(evt){ThunderWeb.onLoad(evt);});
ua.document = $(document);

/* ----------------------------------------------------------------------------------------------------

	Main Event Handlers

---------------------------------------------------------------------------------------------------- */

ThunderWeb.onStart = function () {
	
	ThunderWeb.pageContainer = $('#page-container');
	
    if ($.browser.webkit) ThunderWeb.scrollTarget = $('body'); else ThunderWeb.scrollTarget = $('html');

    // Init user interface
    ThunderWeb.selfLabelFields();
    ThunderWeb.treeMenu();

    ThunderWeb.menuHeadings = $('.menu-heading');
    ThunderWeb.fadeOverContainer = $('#fade-over-container');
    ThunderWeb.fadeOver = $('#fade-over');

    if (ThunderWeb.onTemplateStart) ThunderWeb.onTemplateStart();

    var metaViewport = $('#ctl00_viewport');
    if ((ua.iPhone || ua.Android || ua.iPod || ua.BlackBerry) && (window.forceMobile))
	{
		metaViewport.attr('content', 'width=350, maximum-scale=1.0, user-scalable=yes');
	}
    
	//if(ua.iPad) metaViewport.attr( 'content', 'width=device-width, maximum-scale=1.0, initial-scale=1.0, user-scalable=yes' );

    ua.phoneStyle = document.getElementById('ctl00_phone_style');
    ua.desktopStyle = document.getElementById('ctl00_desktop_style');

    ThunderWeb.preload = $('#preload').css({ display: 'block' });

/*	if(!forceMobile) forceMobile = false;
	if(window.location.hash == '#mobile') forceMobile = true;*/

    ua.document.keydown(ThunderWeb.onKeyDown).mousedown(ThunderWeb.onMouse).mouseup(ThunderWeb.onMouse).mousemove(ThunderWeb.onMouse).mouseenter(ThunderWeb.onMouse).mouseleave(ThunderWeb.onMouse);
    ua.window.scroll(ThunderWeb.onViewChange).resize(ThunderWeb.onViewChange);
    ThunderWeb.onViewChange();
	
    $('*').each(ThunderWeb.createPreloadable);
	//document.write(ThunderWeb.preloadList)

    ThunderWeb.preloadScroller = $('#preload-scroller');
    if(ThunderWeb.preloadScroller.length > 0) ThunderWeb.preloadScrollerTimer = setInterval(function () { ThunderWeb.onPreloadScrollerTimer() }, 33);

    if ($('#relevant').length > 0) {
        $('#relevant a').each(function () {
            $(this).append('<img src="/themes/main/images/desktop/page-relevant-bottom-bg.png" alt="" class="relevant-bottom-cap" /><img src="/themes/main/images/desktop/page-relevant-top-bg.png" alt="" class="relevant-top-cap" />');
            $(this).addClass("relevant-button");
        });
    }
	$('.visible-on-hover').css({opacity:0,display:'block'}).parent().mouseenter(ThunderWeb.handleButtonOver).mouseleave(ThunderWeb.handleButtonOver);
}

ThunderWeb.handleButtonOver = function( event )
{
	var t = $(this).children('.visible-on-hover');
	if(event.type == "mouseenter" )
	{
		t.stop(true,false).animate({'opacity':'1'}, 200);
	}
	else
	{
		t.stop(true,false).animate({'opacity':'0'}, 200);
	}
}

ThunderWeb.onLoad = function(evt)
{
	/*ThunderWeb.preloadPageFlag = true;
	ThunderWeb.preloaderComplete();
	clearInterval( ThunderWeb.preloadScrollerTimer );*/
}

ThunderWeb.createPreloadable = function()
{
    if ($(this).hasClass('no-preload')) return;
    
	var preloadSrc = false, preloadable = false;
	if(this.nodeName.toUpperCase() == 'IMG')
	{
		preloadSrc = this.src;
	}
	else
	{
		var jThisCss = $(this).css('background-image');
		if(jThisCss.replace(/url\(/ig, '') != jThisCss)
		{
			preloadSrc = jThisCss.replace(/url\(/ig, '').replace(/\)/g, '').replace(/\'/g, '').replace(/\"/g, '');
		}
	}
	if($.inArray(preloadSrc, ThunderWeb.preloadList) > -1) preloadSrc = false;
	if(preloadSrc !== false)
	{
		preloadable = new Image();
		$(preloadable).load(ThunderWeb.onPreloadableLoad).error(ThunderWeb.onPreloadableError)
		preloadable.src = preloadSrc;
		ThunderWeb.preloadables.push(preloadable);
		ThunderWeb.preloadList.push(preloadSrc);
	}
	
	
}

ThunderWeb.getHrefQuery = function(hrefQuery)
{
    var hrefSplit, index;
    if(!ThunderWeb.hrefVars)
    {
    	hrefSplit = window.location.href.split('?');
    	if(hrefSplit.length > 1)
    	{
            ThunderWeb.hrefVars = hrefSplit[1].split('&');
            for(index = 0; index < ThunderWeb.hrefVars.length; index++)
            {
                ThunderWeb.hrefVars[index] = ThunderWeb.hrefVars[index].split('=');
            }
        } else ThunderWeb.hrefVars = [];
    }
    for(index = 0; index < ThunderWeb.hrefVars.length; index++)
    {
        if(ThunderWeb.hrefVars[index][0].toUpperCase() == hrefQuery.toUpperCase())
        {
            if(ThunderWeb.hrefVars[index].length == 1) return true; else return ThunderWeb.hrefVars[index][1];
        }
    }
    return false;
}

ThunderWeb.onPreloadScrollerTimer = function()
{
	//alert(ThunderWeb.preloadScroller.position().left);
	ThunderWeb.preloadScroller.css({'left':(ThunderWeb.preloadScroller.position().left - 1).toString() + 'px'})
}

ThunderWeb.onPreloadableLoad = function()
{
	ThunderWeb.preloadObjectsCount++;
	if(ThunderWeb.preloadObjectsCount >= ThunderWeb.preloadables.length - 1) { ThunderWeb.preloadObjectsFlag = true; ThunderWeb.preloaderComplete(); }
	var pct = ThunderWeb.preloadObjectsCount / ThunderWeb.preloadables.length;
	$('#preload-percent').html(Math.floor(pct * 100) + '%');
	$('#preload-percent-over').html(Math.floor(pct * 100) + '%').css({'top': (Math.round(-200 + (pct * 200))).toString() + 'px'});
	$('#preload-percent-over-container').css({'height': (Math.round(pct * 200)).toString() + 'px'})
	
}

ThunderWeb.onPreloadableError = function()
{
	ThunderWeb.preloadObjectsFlag = true;
}

ThunderWeb.preloaderComplete = function()
{
	/*
	if((ThunderWeb.preloadObjectsFlag) && (ThunderWeb.preloadPageFlag))
	{*/
		ThunderWeb.preload.remove();
		//ThunderWeb.preload = false;
//		ThunderWeb.pageContainer[0].style.overflow = 'visible';
		ThunderWeb.pageContainer[0].style.width = 'auto';
		ThunderWeb.pageContainer[0].style.height = 'auto';
//		.css({overflow: 'visible', width: 'auto', height: 'auto'});
		if(ThunderWeb.onTemplatePreloaderComplete) ThunderWeb.onTemplatePreloaderComplete();
		ThunderWeb.onViewChange();
	/*}*/
}

ThunderWeb.onMouse = function(evt)
{
	if(ThunderWeb.onTemplateMouse) ThunderWeb.onTemplateMouse(evt);
}

ThunderWeb.onKeyDown = function(evt)
{
	if(ThunderWeb.onTemplateKeyDown) ThunderWeb.onTemplateKeyDown(evt)
}

ThunderWeb.preventDefault = function(evt) { evt.preventDefault(); }

// ARBITRARY_CHANGE_LATER in this function is height of the gliding footer container
ThunderWeb.onViewChange = function(evt)
{
	// store useful values
	ua.lastHeight = ua.window.height();
	ua.lastWidth = ua.window.width();
	ua.deviceWidth = screen.width;
	//ua.deviceWidth = 320;
	// switch between stylesheets
	/* */
	if ((ua.deviceWidth < 700 || ua.lastWidth < 700 || ua.Android) && (window.forceMobile)) {
		ua.desktopStyle.disabled = true; 
		ua.phoneStyle.disabled = false;
		if( ThunderWeb.currentView != 'phone' ) 
		{ 
			ThunderWeb.currentViewIsChanging = true;
			ThunderWeb.currentView = 'phone';
			if( ThunderWeb.onCurrentViewChange ) ThunderWeb.onCurrentViewChange(evt); 
		}
		else
		{
			ThunderWeb.currentView = 'phone';
		}
		 
		ua.outerWidth = (ua.lastWidth - 350) / 2; 
	}
	else {
		//if(ThunderWeb.preload) { ThunderWeb.preload.css({paddingTop: (ua.lastHeight / 2) - 200 }); }
		ua.phoneStyle.disabled = true; 
		ua.desktopStyle.disabled = false;  
		if( ThunderWeb.currentView != 'desktop' ) 
		{ 
			ThunderWeb.currentViewIsChanging = true;
			ThunderWeb.currentView = 'desktop';
			if( ThunderWeb.onCurrentViewChange ) ThunderWeb.onCurrentViewChange(evt); 
		}
		else
		{
			ThunderWeb.currentView = 'desktop';
		}
		 
		ua.outerWidth = (ua.lastWidth - 1360) / 2; 
	}
	ua.lastTop = ThunderWeb.scrollTarget.scrollTop();
	ua.lastDocumentHeight = ua.document.height();

	ThunderWeb.menuHeadings.each(ThunderWeb.changeMenuTitles);

	// if the footer is scrollable, scroll it
	if(ThunderWeb.onTemplateViewChange) ThunderWeb.onTemplateViewChange(evt);

	ThunderWeb.currentViewIsChanging = false;
	
}

/* ----------------------------------------------------------------------------------------------------

	Animation and Utilities

---------------------------------------------------------------------------------------------------- */

$.fn.smartFadeOut = function(a) { if($.browser.msie) this.css({display: 'none'}); else this.stop(true, false).css({opacity: 1}).fadeOut(a); }

$.fn.smartFadeIn = function(a) { if($.browser.msie) this.css({display: 'block'}); else this.stop(true, false).fadeIn(a); }

$.fn.dropDownVisible = function(n)
{
	if(n)
	{
		if($.browser.msie) this.css({display: 'block'});
		else this.stop(true, false).css({display: 'block', transform: 'scale(.1,.1)'}).animate(true, false).animate({transform: 'scale(1,1)'}, {duration: 250});
	}
	else
	{
		if($.browser.msie) this.css({display: 'none'});
		else this.stop(true, false).animate(true, false).animate({transform: 'scale(.1,.1)'}, {duration: 250, complete: ThunderWeb.hide});
	}
}

ThunderWeb.hide = function() { this.style.display = 'none'; }

ThunderWeb.remove = function() { $(this).remove(); }

ThunderWeb.allowAnimate = function() { ThunderWeb.canAnimate = true; }

ThunderWeb.noBreakHTML = function(text) { return text.replace(/&/g, '&amp;').replace(/ /g, '&nbsp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'); }

ThunderWeb.nothing = function() { }

ThunderWeb.fadeOverVisible = function(n, transitionComplete)
{
	if(!transitionComplete) transitionComplete = ThunderWeb.nothing;
	if(n==true)
	{
		//make container visible, reset opacity
		if($.browser.msie) { ThunderWeb.fadeOverContainer.css({display: 'block'}); transitionComplete(); }
		else ThunderWeb.fadeOverContainer.css({display:'block', opacity:0}).stop(true,false).animate({opacity: 1}, 200, transitionComplete);

		//ThunderWeb.fadeOver.css({'display':'block', 'opacity':'0'})
		//ThunderWeb.fadeOver.css({display:'block'});
	}
	else
	{
		
		if($.browser.msie) { ThunderWeb.fadeOverContainer.css({display: 'none'}); transitionComplete(); }
		else ThunderWeb.fadeOverContainer.stop(true,false).fadeOut(200, transitionComplete);
	}
}

/* ----------------------------------------------------------------------------------------------------

	Actions

---------------------------------------------------------------------------------------------------- */

ThunderWeb.selfLabelFields = function()
{
	// Auto-label search field
	$(".thunder-self-labeled").each(function(i)
	{
		this.setAttribute('thunder.markup:label',this.value)
	}).focus(ThunderWeb.onSelfLabelRemove).blur(ThunderWeb.onSelfLabelReplace);
};

ThunderWeb.onSelfLabelRemove = function()
{
	if(this.value==this.getAttribute('thunder.markup:label'))
	{
		this.value='';
		$(this).addClass('thunder-label-cleared');
		$(this).css({'color':'#000'});
		ThunderWeb.preventPrimaryShortcutKeys = true;
	}
}

ThunderWeb.onSelfLabelReplace = function()
{
	if(this.value=='')
	{
		this.value=this.getAttribute('thunder.markup:label');
		$(this).removeClass('thunder-label-cleared');
		$(this).css({'color':''});
		ThunderWeb.preventPrimaryShortcutKeys = false;
	}
}

ThunderWeb.treeMenu = function()
{
	var items = $('.menu-item').each(ThunderWeb.initTreeMenu);
	/*if(ua.noPointer) items.children('.menu-heading').children('a').click(ThunderWeb.filterMenuHeadingClick);
	else*/ items.mouseenter(ThunderWeb.hoverTreeMenu).mouseleave(ThunderWeb.hoverTreeMenu);
};

ThunderWeb.filterMenuHeadingClick = function(evt)
{
	var c, p;
	c = $('.item-on');
	if(c.length > 0)
	{
		ThunderWeb.hoverTreeMenu.call(c, {type: 'mouseleave'});
	}
	p = $(this).parent().parent();
	if(c[0] !== p[0]) ThunderWeb.hoverTreeMenu.call(p, {type: 'mouseenter'});
	evt.preventDefault(); return false;
}

ThunderWeb.hoverTreeMenu = function(evt)
{
	var jThis = $(this);
	var jChevrons = jThis.children('.menu-heading-chevron');
	var jThis = $(this);
	var jChevrons = jThis.children('.menu-heading-chevron');
	if(evt.type=='mouseenter')
	{
		jThis.addClass('item-on');
		if(!jThis.hasClass('menu-current-section')) jChevrons.stop(true, false).animate({top: -10}, {duration: 500});
		else ThunderWeb.animateSwapVisible(jChevrons.children('.menu-heading-hover-chevron')[0], jChevrons.children('.menu-heading-current-chevron')[0], 'inline', 5);
		jThis.children('.dropdown').dropDownVisible(true);
	}
	else
	{
		jThis.removeClass('item-on');
		if(!jThis.hasClass('menu-current-section')) jChevrons.stop(true, false).animate({top: -100}, {duration: 500});
		else ThunderWeb.animateSwapVisible(jChevrons.children('.menu-heading-current-chevron')[0], jChevrons.children('.menu-heading-hover-chevron')[0], 'inline', 3);
		jThis.children('.dropdown').dropDownVisible(false);
	}
}

ThunderWeb.menuColumnMap = [
{ left: -70, width: 300, columns: [{ topics: 2, width: 250}] }, //HOME
{ left: -70, width: 300, columns: [{ topics: 1, width: 250 }] }, //OUR COMPANY
{left: -70, width: 300, columns: [{ topics: 1, width: 250}] },  //PORTFOLIO
{left: -70, width: 300, columns: [{ topics: 1, width: 250}] },  //PORTFOLIO
{left: -70, width: 300, columns: [{ topics: 1, width: 250}] },  //PORTFOLIO
{left: -70, width: 300, columns: [{ topics: 1, width: 250}] },  //PORTFOLIO

//{left: -270, width: 700, columns: [{ topics: 3, width: 210 }, { topics: 3, width: 210, upper: -10, lower: -10 }, { topics: 2, width: 210, upper: -10, lower: -10}] }, //SERVICES
//{left: -70, width: 300, columns: [{ topics: 1, width: 250}] }, //SOLUTIONS
//{left: -70, width: 300, columns: [{ topics: 1, width: 250}] }, //KNOWLEDGE
{ left: -70, width: 300, columns: [{ topics: 1, width: 250 } ] } ]; //CONTACT

ThunderWeb.menuCapsMap = {at300: 58, at500: 64, at700: 69};

ThunderWeb.initTreeMenu = function(itemIndex)
{
	var jThis = $(this);
	var jChevrons = jThis.children('.menu-heading-chevron');
	var jDropdown = jThis.children('.dropdown');
	var jTopics = jDropdown.children('.dropdown-list').prev().andSelf();
	var columnMap = ThunderWeb.menuColumnMap[itemIndex];
	var identity = 'home';
	if(jThis.hasClass('menu-current-section'))
	{
		ThunderWeb.createImageIn('/themes/main/images/desktop/chevron-current-' + identity + '.png','menu-heading-current-chevron',jChevrons);
		$(ThunderWeb.createImageIn('/themes/main/images/desktop/chevron-hover-' + identity + '.png','menu-heading-hover-chevron',jChevrons)).css({display: 'none'});
	}
	else
	{
		ThunderWeb.createImageIn('/themes/main/images/desktop/chevron-hover-' + identity + '.png', 'menu-heading-hover-chevron', jChevrons);
		jChevrons.css({top: -100});
	}
	if(columnMap.columns.length > 1)
	{
		var jTopic;
		var columnIndex = 0;
		var columnTopicIndex = 0;
		var currentColumn = $(ThunderWeb.createDivIn('dropdown-column', jDropdown)).css({width: (columnMap.columns[0].width-15)+'px'});
		var columnTotalWidth = columnMap.columns[0].width;
		for(var topicIndex = 0; topicIndex < jTopics.length; topicIndex += 2)
		{
			//alert('itemIndex:'+itemIndex+'topicIndex:'+topicIndex+', columnTopicIndex:'+columnTopicIndex+', columnIndex:'+columnIndex);
			currentColumn.append(jTopics.eq(topicIndex).next().andSelf().remove());
			columnTopicIndex++;
			if((columnTopicIndex >= columnMap.columns[columnIndex].topics) && (topicIndex < jTopics.length - 2))
			{
				columnTopicIndex = 0;
				columnIndex++;
				$(ThunderWeb.createDivIn('dropdown-column-separator', jDropdown)).css({left: (columnTotalWidth + 23) + 'px', top: columnMap.columns[columnIndex].upper + 'px', bottom: columnMap.columns[columnIndex].lower + 'px'});
				columnTotalWidth += columnMap.columns[columnIndex].width;
				currentColumn = $(ThunderWeb.createDivIn('dropdown-column', jDropdown)).css({width: (columnMap.columns[columnIndex].width-15)+'px'});
			}
		}
		ThunderWeb.createDivIn('clearer', jDropdown);
	}
	$(ThunderWeb.createImageIn('/themes/main/images/desktop/dropdown-top-' + columnMap.width + '.png', 'dropdown-cap-top', jDropdown)).css({top: 0 - ThunderWeb.menuCapsMap['at'+columnMap.width]});
	$(ThunderWeb.createImageIn('/themes/main/images/desktop/dropdown-bottom-' + columnMap.width + '.png', 'dropdown-cap-bottom', jDropdown)).css({bottom: 0 - ThunderWeb.menuCapsMap['at'+columnMap.width]});
	jDropdown.css({backgroundImage: 'url(/themes/main/images/desktop/dropdown-background-' + columnMap.width + '.png)', width: (columnMap.width - 48) + 'px', top: ThunderWeb.menuCapsMap['at'+columnMap.width] + 20, left: columnMap.left + 'px'});
}

ThunderWeb.animateSwapVisible = function(el, el2, displayVisible, countTotal)
{
	if(ThunderWeb.enableConstantInterval(ThunderWeb.doAnimateSwapVisible)) ThunderWeb.animateSwapVisibleParams = {el: el, el2: el2, displayVisible: displayVisible, count: 0, countTotal: countTotal};
	else
	{
		if(ThunderWeb.animateSwapVisibleParams !== false)
		{
			ThunderWeb.animateSwapVisibleParams.el.style.display = ThunderWeb.animateSwapVisibleParams.displayVisible;
			ThunderWeb.animateSwapVisibleParams.el2.style.display = 'none';
			ThunderWeb.animateSwapVisibleParams = false;
			ThunderWeb.disableConstantInterval();
		}
	}
}

ThunderWeb.doAnimateSwapVisible = function()
{
	ThunderWeb.animateSwapVisibleParams.el.style.display = ThunderWeb.animateSwapVisibleParams.count % 2 == 1 ? 'none' : ThunderWeb.animateSwapVisibleParams.displayVisible;
	ThunderWeb.animateSwapVisibleParams.el2.style.display = ThunderWeb.animateSwapVisibleParams.count % 2 == 1 ? ThunderWeb.animateSwapVisibleParams.displayVisible : 'none';
	ThunderWeb.animateSwapVisibleParams.count++;
	if(ThunderWeb.animateSwapVisibleParams.count >= ThunderWeb.animateSwapVisibleParams.countTotal)
	{
		ThunderWeb.animateSwapVisibleParams = false;
		ThunderWeb.disableConstantInterval();
	}
}

ThunderWeb.enableConstantInterval = function(onConstantInterval) { if(ThunderWeb.constantInterval===false) { ThunderWeb.constantInterval = setInterval(onConstantInterval, 85); return true; } else return false; }

ThunderWeb.disableConstantInterval = function() { if(ThunderWeb.constantInterval!==false) { clearInterval(ThunderWeb.constantInterval, ThunderWeb.onConstantInterval); ThunderWeb.constantInterval = false; } }

ThunderWeb.createImageIn = function(src, cssClass, jWithin)
{
	var img = document.createElement('img');
	img.className = cssClass;
	img.src = src;
	jWithin.append(img);
	return img;
}

ThunderWeb.createDivIn = function(cssClass, jWithin)
{
	var div = document.createElement('div');
	div.className = cssClass;
	jWithin.append(div);
	return div;
}

ThunderWeb.changeMenuTitles = function(evt)
{
	var jThis = $(this);
	var jTextTarget = jThis.children('a');
	if(jTextTarget.length==0) jTextTarget = jThis;
	if(ThunderWeb.currentView=='desktop')
	{
		if(this.getAttribute('thunder:desktop-name'))
		{
			jTextTarget.text(jThis.attr('thunder:desktop-name'));
		}
	}
	else
	{
		//Change Menu Headings for phone view - i.e. 'Our Company' becomes 'Us'
		if(this.getAttribute('thunder:phone-name'))
		{
			if(!this.getAttribute('thunder:desktop-name')) jThis.attr('thunder:desktop-name', jThis.text());
				//var n = jthis.html().slice('\<\.}\>') + name + ''
			//var old = jthis.html();
			jTextTarget.text( jThis.attr('thunder:phone-name') );
			//$(this).text(( (this).getAttribute('thunder:phone-name') ));
		}
	}
}


ThunderWeb.showCustomJBox = function(content, showClose){
    return $(this).jBox({ 
'fadeInDelay':300,
'fadeOutDelay':300,
'backgroundcolor':'white', 
'border':'2px solid black', 
'autoHide': 0, 
'showClose':showClose, 
'fixedWidth': '',
'fixedHeight': '',
'zIndex': 99999,
'clickToClose':true
}).showWindow('<div style="padding: 20px;">' + content + '</div>');

}

ThunderWeb.submitNewsletter = function(sender){
    var email = $("#newsletter-email");
    var re = new RegExp(/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/);
    
    if (!email.val().match(re)) {
        ThunderWeb.showCustomJBox('<div><h3>Invalid Email Address</h3><br/>Please enter a valid email address.', true);
        return false;		          
    }
    if (email.val() == '') {
        ThunderWeb.showCustomJBox('<h3>Invalid Email Address</h3><br/>Please enter a valid email address.', true);
        return false;		          
    }
	
	if (email.val() == 'yourname@email.com'){
		ThunderWeb.showCustomJBox('<h3>Invalid Email Address</h3><br/>Please enter a valid email address.', true);
		return false;
	}
	
	$(sender).attr('value', 'Processing...');
	var loader = ThunderWeb.showCustomJBox('<h3>Newsletter Signup</h3><br/>Submitting your email address. <br/><br/>Please wait...', false);
	var nlData = { "action":"marketing",  "email": email.val()};
	$.ajax({
        type: "POST",
        url: "/services/contactHandler.ashx",
        data: nlData,
        success: function(html){	
            loader.close();		
			ThunderWeb.showCustomJBox('<h3>Newsletter Signup</h3><br/>' + html, true);
			$(sender).attr('value', 'Let\'s do this!');
			email.val('enter your email address!').removeClass('thunder-label-cleared');
        },
		error: function(e){
		    loader.close();
			ThunderWeb.showCustomJBox('<h3>ERROR</h3><br/>I\'m sorry. We are unable to process your request. Please try again later.', true);
			$(sender).attr('value', 'Let\'s do this!');			
		}		
    });
    
    return false;
}

///newsletter page  http://www.thundertech.com/e-newsletter.aspx
function showYear(year) {
    if ($("." + year).css("display") == "none") {
        $("." + year).css("display", "block");
    } else {
        $("." + year).css("display", "none");
    }
}

$(document).ready(function () {
    $(".mm-archive:first").css("display", "block");
});
//==================================




$(ThunderWeb.onStart);
