/* Global.js */

// remove IE6 image flickering
try {document.execCommand('BackgroundImageCache', false, true);}
catch(e) {}


$(document).ready(function(){
	//text resizer
	$("#txtResizer span").eq(0).css("color", "#555");
	$("#txtResizer span").bind("click", function(){
		var newSize = $(this).prevAll("span").length;
		$("#txtResizer span").css("color", "#08a0b6").eq(newSize).css("color", "#666");
		$("#txtResizeArea").css("font-size", (newSize*0.2+1)+"em");
	});

	//initialize popup links
	$("a.popup").addClass("pop").attr("title", "[Opens in new window]").bind("click", function(){
		var popup = window.open($(this).attr("href"), "_blank", "height=500,width=600,scrollbars=yes");
		popup.focus();
		return false;
	});
	$("a.popup2").attr("title", "[Opens in new window]").bind("click", function(){
		var popup = window.open($(this).attr("href"), "_blank", "height=500,width=600,scrollbars=yes");
		popup.focus();
		return false;
	});

	//adding image and link to cmAd div
	$("body.tab_01 .cmAd").append('<a href="http://www.allyou.com/reality-checker"><img src="http://img4.allyou.com/static/i/cmAD_static.jpg" id="img_tout" height="199" width="397" /></a>');
	
	//prints the pages url on screen used on print pages
	$("#linkLocation").html(location.href);

	//convert add-this link lists to form
	if ($(".getRSS .getRSSList a").length > 0) {
		var str = "";
		$(".getRSS .getRSSList a").each(function() {
			str += "<option value='" + $(this).attr("href") + "'>" + $(this).text() + "</option>";
		});
		$(".getRSS .getRSSList").after("<form target='_top' action='#' method='post'><table cellspacing='10' summary=''><tr><td><label for='reader'>Add All You to:</label></td><td><select name='reader' id='reader'>" + str + "</select></td><td><input type='image' src='http://img4.allyou.com/static/i/btn_add.gif' alt='Add' /></td></tr></table></form>");
		$(".getRSS form").bind("submit", function(){
			$(this).attr("action", $(this).find("option:selected").val());
		});
		$(".getRSS .getRSSList").remove();
	}
	if ($(".addTo .getRSSList a").length > 0) {
		var str = "";
		$(".addTo .getRSSList a").each(function() {
			str += "<option value='" + $(this).attr("href") + "'>" + $(this).text() + "</option>";
		});
		$(".addTo .getRSSList").after("<form target='_top' action='#' method='post'><table cellspacing='4' summary=''><tr><td><label for='reader'>Add All You to:</label></td><td><select name='reader' id='reader'>" + str + "</select></td><td><input type='image' src='http://img4.allyou.com/static/i/btn_add.gif' alt='Add' /></td></tr></table></form>");
		$(".addTo form").bind("submit", function(){
			$(this).attr("action", $(this).find("option:selected").val());
		});
		$(".addTo .getRSSList").remove();
	}
});

//hide popunders from certain sites
var dref = document.referrer.toLowerCase();
if (dref.indexOf("google") > -1 || dref.indexOf("yahoo") > -1 || dref.indexOf("facebook") > -1 || dref.indexOf("primosearch") > -1 || dref.indexOf("righthealth") > -1 || dref.indexOf("alot") > -1 || dref.indexOf("digg") > -1 || dref.indexOf("reddit") > -1 || dref.indexOf("twitter") > -1 || dref.indexOf("stumbleupon") > -1 || dref.indexOf("cnn") > -1 || dref.indexOf("msn") > -1 || dref.indexOf("huffingtonpost") > -1) {
	adConfig.setPopups(false);
}

// initialize the calendar thumbnail module (flex module js copied from MHI)
function initCalTN(calFile) {
	var monthsAbbr = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
	var now = new Date();
	$(".calTN2").prepend("<div class='date'><div class='month'>" + monthsAbbr[now.getMonth()] + "</div><div class='day'>" + now.getDate() + "</div></div>");
	$.ajax({
		type: "GET",
		url: calFile,
		dataType: "xml",
		success: function(data){
			var currentDay = $(data).find("day").eq(now.getDate() - 1);
			var calLink = $(data).find("month").attr("url");
			$(".calTN h3").prepend($(data).find("title").eq(0).text() + " ");
			$(".calTN2").find("p").remove().end().append("<a href='" + calLink + "' class='title'>" + $(currentDay).find("title").text() + "</a><p>" + $(currentDay).find("short-deck").text() + " <a href='" + calLink + "' class='more'>&raquo; See Full Calendar</a></p>");
		}
	});
}