﻿// 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('');
		});
	});
}

function hasAds(ads) {
	$.each(ads, function(adIndex, adCont){
		var adSrc = $(adCont),
		adImg = adSrc.find('img').width();
		if(adImg <= 1 || !adImg) {
		    adSrc.find('.channelSponsor').hide();	
		}
	});
}

function tabs() {
    var tabContainers = $('#tabsLayout > div.tab-content');
    tabContainers.hide().filter(':first').show();
    $('#tabsLayout ul.tab-nav a').click(function(){
        tabContainers.hide();
        tabContainers.filter(this.hash).show();
        $('#tabsLayout ul.tab-nav a').removeClass('selected');
        $(this).addClass('selected');
        return false;
    }).filter(':first').click();
}

//Override the AutoFocus function
function WebForm_AutoFocus(focusId) {} 

$(function(){
	/* var definitions */ 
	var fieldHint = {
		'#SearchTerms' : 'Begin Search'
	}, h1 = $("h1:first"), trimh1 = h1.html(),
	dt = new Date(), year = dt.getFullYear();
	
	/* trims leading nbsp if inserted */
	if (trimh1) {
		trimh1 = trimh1.replace(/^(&nbsp;)/, "");
		h1.html(trimh1);
	} 
	
	/* call fxns */
	fieldTip(fieldHint);
	hasAds(['#CopyID0EAAA', '#CopyID0EBAA', '#CopyID0ECAA', '#CopyID0EDAA', '#CopyID0EEAA', '#CopyID0EFAA', 
	        '#CopyID0EGAA', '#CopyID0EHAA', '#CopyID0EIAA', '#CopyID0EJAA', '#CopyID0EKAA', '#CopyID0ELAA']);
	tabs();
	
	//pagination
	$('.articleNewPaging').clone().insertBefore('#pageHolder');	
	
	$('#year').text(year + ' ');
	
	/* 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','#ColumnTwo.Article',
				'#ArticleComments','.globalNav','#MagazineSearch','#MagazineFooter','#TopAds','#BottomAds','#ColumnThree.Article','.login', '.printButton', '.smallTextButton',
				'.largeTextButton', '#FeedFlare', '#commentButton'];	
	
	//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();
	});
});