/********************* Begin slideshow module *********************/
var currPic = 0;
var paused = false;
var ssTxt = new Array(5);
var ssPh = new Array(5);
var ssBtns = new Array(5); 
var ppBtn;
var timer1;

function initPageComponents() {
	/*  Used to load all components on the page */
	ssTxt[0] = document.getElementById('txt1');
	ssTxt[1] = document.getElementById('txt2');
	ssTxt[2] = document.getElementById('txt3');
	ssTxt[3] = document.getElementById('txt4');
	ssTxt[4] = document.getElementById('txt5');
	ssPh[0] = document.getElementById('ph1');
	ssPh[1] = document.getElementById('ph2');
	ssPh[2] = document.getElementById('ph3');
	ssPh[3] = document.getElementById('ph4');
	ssPh[4] = document.getElementById('ph5');
	ssBtns[0] = document.getElementById('a1'); 
	ssBtns[1] = document.getElementById('a2');
	ssBtns[2] = document.getElementById('a3');
	ssBtns[3] = document.getElementById('a4');
	ssBtns[4] = document.getElementById('a5');
	ppBtn = document.getElementById('ppBtn');
	timer1 = setTimeout('timedStory()', 6000);
}

function change(num) {
	currPic = num;
	ssTxt[0].style.display = (num == 0 ? "block" : "none"); 
	ssTxt[1].style.display = (num == 1 ? "block" : "none"); 
	ssTxt[2].style.display = (num == 2 ? "block" : "none");
	ssTxt[3].style.display = (num == 3 ? "block" : "none");
	ssTxt[4].style.display = (num == 4 ? "block" : "none"); 
	ssPh[0].style.display = (num == 0 ? "block" : "none"); 
	ssPh[1].style.display = (num == 1 ? "block" : "none"); 
	ssPh[2].style.display = (num == 2 ? "block" : "none");
	ssPh[3].style.display = (num == 3 ? "block" : "none");
	ssPh[4].style.display = (num == 4 ? "block" : "none"); 
	ssBtns[0].className = (num == 0 ? "on" : "off");
	ssBtns[1].className = (num == 1 ? "on" : "off");
	ssBtns[2].className = (num == 2 ? "on" : "off"); 
	ssBtns[3].className = (num == 3 ? "on" : "off");
	ssBtns[4].className = (num == 4 ? "on" : "off");
}

/* change picture, wait some seconds, repeat */
function timedStory() {
	currPic = (currPic + 1)%5;
	change(currPic);
	timer1 = setTimeout('timedStory()', 6000);
}

/* executed when the play/pause button is selected */
function doButton() {
	paused = !paused;
	doImageSwap();
	if (paused) {
		clearTimeout(timer1); /* stop the image loop */
	} else {
		timedStory(); /* restart the image loop */
	}
}

/*executed when a number link is selected */
function doNumber(num) {
	paused = true;
	doImageSwap();
	clearTimeout(timer1);
	change(num);
} 

/* swap the play/pause button image */
function doImageSwap() {
	ppBtn.style.backgroundPosition = (paused ? "-190px -150px" : "-190px -125px");
}
/********************* End slideshow module *********************/


function switchTab(n) {
	document.getElementById("tab_b_on").style.display = (n==0 ? "block" : "none");
	document.getElementById("tab_m_on").style.display = (n==1 ? "block" : "none");
	document.getElementById("tab_c_on").style.display = (n==2 ? "block" : "none");
}


tii_callFunctionOnWindowLoad (function () {
	// for slideshow
	initPageComponents();

	// for "for your consideration" email signup widget
	var fyc_email = document.getElementById('fyc_email');
	if (fyc_email) {
		var fyc_default = fyc_email.value;
		tii_addEventHandler(fyc_email, 'focus', function(event) {
			if (fyc_email.value == fyc_default) {
				fyc_email.value = "";
				fyc_email.className = "active";
			}
		}, false);
		tii_addEventHandler(fyc_email, 'blur', function(event) {
			if (fyc_email.value == "") {
				fyc_email.value = fyc_default;
				fyc_email.className = "";
			}
		}, false);
	}
});




function addTo() {
	$(".addTo").each(function(){
		if ($(this).find(".getRSSList a").length > 0) {
			var str = "";
			$(this).find(".getRSSList a").each(function() {
				str += "<option value='" + $(this).attr("href") + "'>" + $(this).text() + "</option>";
			});
			$(this).find(".getRSSList").after("<form target='_blank' action='#' method='post'><label for='reader'>Add MyRecipes to:</label> <select name='reader' id='reader'>" + str + "</select> <input type='image' src='http://img.timeinc.net/recipes/static/i/btn_add2.png' alt='Add' /></form>");
			$(this).find("form").bind("submit", function(){
				$(this).attr("action", $(this).find("option:selected").val());
			});
			$(this).find(".getRSSList").remove();
		}
	});
}