$().ready(function() {
	// Uncomment to run promo
	// showPromo('04/1/2011','6/1/2011','#promo-button');
	checkCount();
	window.ivnqt();

});


function showPromo(startDate, endDate, elementToUpdate) {
	start_date = new Date(startDate);	
	end_date = new Date(endDate);
	now = new Date();
	show_promo = (now >= start_date && now < end_date);
	if (show_promo) {
		promoHTML = 
			'<a href="http://www.time4writing.com/vocabulary-and-writing-go-hand-in-hand/"><img src="/images/buttons/btn_VSCpromo.gif" alt="Find out how to get your free year of VocabularySpellingCity.com! Click here." border="0" /></a>';
	} else {
		promoHTML = 
			'<a href="http://www.time4writing.com/summer-courses-with-flexible-schedules"><img src="/images/buttons/btn_FlexibleSummertimeScheduling.gif" alt="Make the Most of Summertime with Flexible Course Schedules! Click here." border="0" /></a>';
	}
	$(elementToUpdate).html(promoHTML);
}

function checkCount() {
	count = GetCookie('count');
	expDays = 31; // number of days the cookie should last
	exp = new Date();
	exp.setTime(exp.getTime() + (expDays * 24 * 60 * 60 * 1000));
	if (count == null) {
		count = 1;
		SetCookie('count', count, exp);
		setTimeout("flvFSL1('DemoBox',5,5,1,10)", 700);
	} else {
		count++;
		SetCookie('count', count, exp);
	}
}

window.ivnqt = function() {
	// populate the array client side, using data from the seo friendly pre tag
	if (!this.aQuotes) {
		this.aQuotes = new Array('No Data');
		o = document.getElementById('ivndata');
		if (o) {
			tmp = o.innerHTML.split(/\{\}/);
			for ( var i = 0; i < tmp.length; i++) {
				if (tmp[i].length > 1)
					this.aQuotes[this.aQuotes.length] = tmp[i];
			}
		}
	}

	// if returning prematurely, cancel running timer
	if (this.mTimer) {
		clearTimeout(this.mTimer);
		this.mTimer = null;
	}

	// seconds to wait before swapping quote
	this.mInterval = 9000;
	f = document.ivnForm;
	if (f && f.interval) {
		this.mInterval = parseInt(f.interval.options[f.interval.selectedIndex].text) * 1000;
	}

	if (this.aQuotes) {
		// pick a starting point randomly
		if (!this.ivnlastqt)
			this.ivnlastqt = parseInt(Math.random() * (this.aQuotes.length - 1));
		if (++this.ivnlastqt > this.aQuotes.length - 1)
			this.ivnlastqt = 1;
		o = document.getElementById('ivnqt');
		if (o) {
			if (o.filters && o.filters[0])
				o.filters[0].apply();
			o.innerHTML = this.aQuotes[this.ivnlastqt];
			if (o.filters && o.filters[0])
				o.filters[0].play();
			this.mTimer = setTimeout('window.ivnqt()', this.mInterval);
		}
	}
};

function MM_findObj(n, d) { // v4.01
	var p, i, x;
	if (!d)
		d = document;
	if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
		d = parent.frames[n.substring(p + 1)].document;
		n = n.substring(0, p);
	}
	if (!(x = d[n]) && d.all)
		x = d.all[n];
	for (i = 0; !x && i < d.forms.length; i++)
		x = d.forms[i][n];
	for (i = 0; !x && d.layers && i < d.layers.length; i++)
		x = MM_findObj(n, d.layers[i].document);
	if (!x && d.getElementById)
		x = d.getElementById(n);
	return x;
}

function flvFSL1() {// v2.3
// Copyright 2002-2004, Marja Ribbers-de Vroed, FlevOOware
// (www.flevooware.nl/dreamweaver/)
	var v1 = arguments, v2 = v1[0], v3 = MM_findObj(v2), v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20 = window, v21 = navigator;
	if (v3) {
		v4 = parseInt(v1[1]);
		v5 = parseInt(v1[2]);
		v6 = parseInt(v1[3]);
		v7 = (v1.length > 4) ? parseInt(v1[4]) : 0;
		v8 = (v1.length > 5) ? parseInt(v1[5]) : 0;
		v9 = 10;
		v10 = document.layers ? v3 : v3.style;
		if (v3.SL1 != null) {
			clearTimeout(v3.SL1);
		}
		v11 = isNaN(parseInt(v10.left)) ? v3.offsetLeft : parseInt(v10.left);
		v12 = isNaN(parseInt(v10.top)) ? v3.offsetTop : parseInt(v10.top);
		if (v8 != 0) {
			if (v8 == 1) {
				v4 = v11 - v4;
				v5 = v12;
			} else if (v8 == 2) {
				v4 = v11 + v4;
				v5 = v12;
			} else if (v8 == 3) {
				v5 = v12 - v5;
				v4 = v11;
			} else {
				v5 = v12 + v5;
				v4 = v11;
			}
		}
		v13 = v4;
		v14 = v5;
		if ((v11 != v4) || (v12 != v5)) {
			if (v7 > 0) {
				v9 = v6;
				v15 = v7;
				v16 = v7, v17 = Math.abs(v11 - v4), v18 = Math.abs(v12 - v5);
				if (v17 < v18) {
					v16 = (v17 != 0) ? ((v18 / v17) * v7) : v7;
				} else {
					v15 = (v18 != 0) ? ((v17 / v18) * v7) : v7;
				}
				if (v15 >= v17) {
					v15 = Math.min(Math.ceil(v15), v7);
				}
				if (v16 >= v18) {
					v16 = Math.min(Math.ceil(v16), v7);
				}
				if ((v11 < v4) && (v11 + v15 < v4)) {
					v4 = v11 + v15;
				}
				if ((v11 > v4) && (v11 - v15 > v4)) {
					v4 = v11 - v15;
				}
				if ((v12 < v5) && (v12 + v16 < v5)) {
					v5 = v12 + v16;
				}
				if ((v12 > v5) && (v12 - v16 > v5)) {
					v5 = v12 - v16;
				}
			} else {
				v17 = ((v4 - v11) / v6);
				v18 = ((v5 - v12) / v6);
				v17 = (v17 > 0) ? Math.ceil(v17) : Math.floor(v17);
				v4 = v11 + v17;
				v18 = (v18 > 0) ? Math.ceil(v18) : Math.floor(v18);
				v5 = v12 + v18;
			}
			v19 = (document.layers || window.opera) ? "" : "px";
			if (v17 != 0) {
				v10.left = v4 + v19;
			}
			if (v18 != 0) {
				v10.top = v5 + v19;
			}
			var v22 = "flvFSL1('" + v2 + "'," + v13 + "," + v14 + "," + v6
					+ "," + v7 + ",0)";
			v3.SL1 = setTimeout(v22, v9);
		} else {
			if (v20.onSlideEnd) {
				onSlideEnd(v2);
			}
		}
	}
}

function GetCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
			break;
	}
	return null;
}

function SetCookie(name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = "/";
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape(value)
			+ ((expires == null) ? "" : ("; expires=" + expires.toGMTString()))
			+ ((path == null) ? "" : ("; path=" + path))
			+ ((domain == null) ? "" : ("; domain=" + domain))
			+ ((secure == true) ? "; secure" : "");
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf(";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
