﻿// archive dropdown menu
function FP_jumpMenu(el,frm,sel) {//v1.0
 var href=el.options[el.selectedIndex].value; if(sel) el.selectedIndex=0;
 '_new'==frm ? open(href) : eval(frm+".location='"+href+"'");
}

//search and form field hints
function fieldTip(fieldHint) {
	$.each(fieldHint, function(el, text){
		$(el).val(text).focus(function() {
			$(this).val('');
		});
	});
}

//fix top ad flash for small screen resolution
function smallScreen(el){
	$(this).css({
		'position' : 'relative',
		'z-index' : '0'
	});
}

//Override the AutoFocus function
function WebForm_AutoFocus(focusId) {}

// relocates ads for featured channels
function adPlace(obj) {
	$.each(obj, function(key, value){
		var adSrc = $(value),
		ad = adSrc.find('a img'),
		adImg = ad.attr('width');
		if(adImg <= 1) {
			return true;
		}
		else if(!adImg || adImg.length == 0){
			adSrc.find('object').appendTo($(key));
		}
		else {
			var link = ad.parent();
			link.prependTo($(key)).wrap('<span class="channelSponsor"></span>').before('<p>Sponsored by</p>');
		}
	});
}

$(function(){
	/* var definitions */ 
	var fieldHint = {
		'#SearchTerms' : 'Begin Search',
		'#email' : 'Enter Your Email Address'
	}, h1 = $("h1:first"), trimh1 = h1.html(), 
	dt = new Date(), curMonth = $("#currentMonth, #currentMonthFooter"), 
	month = '', year = dt.getFullYear();
	
	/* trims leading nbsp if inserted */
	if (trimh1) {
		trimh1 = trimh1.replace(/^(&nbsp;)/, "");
		h1.html(trimh1);
	}  
	
	/* call fxns */
	fieldTip(fieldHint);
	smallScreen($('#topAd object'));
	adPlace({
		'#CopyID0EFAA h6' : '#ad1', 
		'#CopyID0EEAA h6' : '#ad2', 
		'#CopyID0EDAA h6' : '#ad3',
		'#CopyID0ECAA h6' : '#ad4',
		'#CopyID0EBAA h6' : '#ad5',
		'#CopyID0EAAA h6' : '#ad6'
	});

	/* date fxns */
	$('#year').text(year + ' ');
	month = dt.getMonth() + 1;	
	if (month == 1) {
		curMonth.attr("href","/Pages/Florida-Underwriter-Magazine-Events.aspx?key=January");
	} else if (month == 2) {
		curMonth.attr("href","/Pages/Florida-Underwriter-Magazine-Events.aspx?key=February");
	} else if (month == 3) {
		curMonth.attr("href","/Pages/Florida-Underwriter-Magazine-Events.aspx?key=March");
	} else if (month == 4) {
		curMonth.attr("href","/Pages/Florida-Underwriter-Magazine-Events.aspx?key=April");
	} else if (month == 5) {
		curMonth.attr("href","/Pages/Florida-Underwriter-Magazine-Events.aspx?key=May");
	} else if (month == 6) {
		curMonth.attr("href","/Pages/Florida-Underwriter-Magazine-Events.aspx?key=June");
	} else if (month == 7) {
		curMonth.attr("href","/Pages/Florida-Underwriter-Magazine-Events.aspx?key=July");
	} else if (month == 8) {
		curMonth.attr("href","/Pages/Florida-Underwriter-Magazine-Events.aspx?key=August");
	} else if (month == 9) {
		curMonth.attr("href","/Pages/Florida-Underwriter-Magazine-Events.aspx?key=September");
	} else if (month == 10) {
		curMonth.attr("href","/Pages/Florida-Underwriter-Magazine-Events.aspx?key=October");
	} else if (month == 11) {
		curMonth.attr("href","/Pages/Florida-Underwriter-Magazine-Events.aspx?key=November");
	} else {
		curMonth.attr("href","/Pages/Florida-Underwriter-Magazine-Events.aspx?key=December");
	}
	
	/* article controls */
	$(".largeTextButton").css("cursor","pointer").click(function(){
		$("#Pagination").css("font-size","16px");
	});
	$(".smallTextButton").css("cursor","pointer").click(function(){
		$("#Pagination").css("font-size","12px");
	});
	
	//elements to hide					
	var arr = [ ".ms-navframe",".ms-bannerframe",".ms-sbtable",".ms-searchform",".ms-sbtopcorner",".ms-sblbcorner","#ArticleTools","#ArticleComments","#mainNav","#siteFooter","#relatedContent","#relatedContentSkyscraper","#feedFlare","#subscribeRight","#adColumnSkyscraper",".ArticlePagingCurrentPage","#searchBox","#handleBar","#relatedContentRectangle","#relatedContent",".printButton",".largeTextButton",".smallTextButton","#contentRectangle h2" ];	

	//hide the items	
	$(".printButton").css("cursor","pointer").click(function(){
		$.grep(arr, function(x){$(x).hide();
			$("#Pagination").css("font-size","12pt");
		});
		//shows the print change link and shows the items of the array		
		$(".returnButton").show().css("cursor","pointer").click(function(){
			$.grep(arr, function(x){
				$(x).show();
			});
			$("#Pagination").css("font-size","12px");
			$(this).hide();
		});
		print();
	});
	
	var news = /\/news\//,
	exclusives = /\/exclusives\//,
	url = cssInclude.path;
	
	if (url.match(news) == null && url.match(exclusives) == null) {
		$('#articleDate').show();
	}
	else if(url.match(news)) {
		$('#articleDate, .articleIssueDate, #recentIssues').hide();
		$('.breakingNews, #recentNews').css('display', 'block');
	}
	else if(url.match(exclusives)) {
		$('.breakingNews, .articleIssueDate').hide();
		$('.webExclusives').css('display', 'block');
	}
	else {
		$('#articleDate').show();
	}
});