/* AJAX / PHP checks with the site to see if the stream page should be loaded */
/* Dev Saroop Singh Khalsa 25Jun2010 for Ayurvedic Institute */
var ThisPageLoad2 = {	
	
	init: function() {
		var timeout = 107;
		var stream = false;

		var loadPage2 = function() {
			// ask if the stream is on
			$.get("index.php", { vid: "test" },
				function(data) {
					// if stream is off and now came on
					if (data === "streamon" && stream === false) {
						// load the stream page element
						$('#streamwindow').load('index.php', {vid: "load"});
						$('#nowplaying').load('index.php', {vid: "loadsc"});
						stream = true;
						timeout = 5;
					} else {
						// if stream was on and now it is off
						if (data === "streamoff" && stream === true) {
							// load the blank page element
							$('#streamwindow').load('index.php', {vid: "load"});
							$('#nowplaying').load('index.php', {vid: "loadsc"});
							stream = false;
							timeout = 30;
						}
					}
			   }
			);

			setTimeout(loadPage2, timeout * 1000);
		};

		$('#streamwindow').load('index.php', {vid: "load"});
		$('#nowplaying').load('index.php', {vid: "loadsc"});
		loadPage2();
	}
};

ThisPageLoad2.init();

