// JavaScript Document

$(document).ready(function(){
	// Fix the bad css support in ie6	
	$('div.featuredProduct + div.section').css('border-top','none');
	$('div.featuredProduct + div.twoColumns').css('border-top','none');
	$('div.column1 div.section:first').css({
		'border-Top':'none',
		'padding-top':'0'
	});

	$('.section a').each(function(){
		var href = $(this).attr('href');
		if (href) {
			if (href.indexOf('.pdf') > -1 && $(this).text().length < 6) {
				$(this).prepend('PDF&nbsp;');
			}
		}
	});
	$('#mainBox li a').each(function(){
		var href = $(this).attr('href');
		if (href) {
			if (href.indexOf('.pdf') > -1) {
				$(this).append('&nbsp;&nbsp;<span class="orange">PDF</span>');
				//$(this).addClass('pdf');
			}
		}
	});
	
	/* Automatically add >> after links in bulleted lists */
	$('#mainBox ul li a').append('<span class="orange">&nbsp;&raquo;</span>');
	jQuery.each(jQuery.browser, function(i, val) { // IE 6 only actions
		if ((i=="msie" && val)&& jQuery.browser.version<7) {
		 	$('#mainBox ul li + li').css('margin-top','1em');
			$('div.infoBox').addClass('clearfix');
		}
	});
	
	// Popup text magic.
	$('p.popuptext').parent().hoverIntent(
			function() {
				$('p.popuptext',this).fadeIn('slow');
			},
			function() {
				$('p.popuptext',this).fadeOut('slow');
			}
		);
	//Dynamic  Infoboxes
	$('.infoBox div.switchable').css('display','none');
	$('.infoBox h3').removeClass('open');
	$('.infoBox h3').addClass('closed');
	$('.infoBox:first h3').removeClass('closed');
	$('.infoBox:first h3').addClass('open');
	$('.infoBox:first div.switchable').css('display','block');
	$('.infoBox h3').click(function(event){
		event.preventDefault();
		if ($(this).attr('class')=="open") {
			$("div.switchable", $(this).parent(".infoBox")).hide('fast');
			$(this).removeClass('open');
			$(this).addClass('closed');
		} else {
			$("div.switchable", $('.infoBox h3.open').parent(".infoBox")).hide('fast',function(){
				$('h3',$(this).parent(".infoBox")).removeClass('open');
				$('h3',$(this).parent(".infoBox")).addClass('closed');
			});
			$("div.switchable", $(this).parent(".infoBox")).show('fast')
			$(this).removeClass('closed');
			$(this).addClass('open');
		}
	});
	
	//Flash loader
	//$('#flashDiv').not('body.home #flashDiv').load("/envestnet/advisors/flashheader.php");
	
	$('.popupform').colorbox({iframe:true, innerWidth:320, innerHeight:380});
});

function emailthis() {
	var link = document.location.href;	
	var title = $('#mainBox h1:first').html();
	document.location.href = "/emailthis.php?link=" + link + "&title=" + title;
}