/*****************************************
 * JS for showing Flash movie on home page
 * Created: 2008-09-06
 *****************************************/
if (!zzcylaw) {
	var zzcylaw = {};
}

zzcylaw.TVSpot = {
	/**
	 * Shows "Play again" link
	 */
	finishMovie: function() {
		var playAgain = document.getElementById("play-again");
		playAgain.onclick = function() {
			zzcylaw.TVSpot.play();
			return false;
		};
		playAgain.style.display = "block";
	},
	
	/**
	 * Set up event handlers for showing Flash movie
	 */
	init: function() {
		/* Set up variables that we'll refer back to later */
		this.movie = document.getElementById("movie");
		this.movieImg = document.getElementById("movie-img");
		this.playEl = document.getElementById("play");
		
		/* Set onclick events for play button and image */
		this.playEl.onclick = function() {
			zzcylaw.TVSpot.play();
			return false;
		};
		this.movieImg.onclick = function() {
			zzcylaw.TVSpot.play();
			return false;
		};
	},
	
	/**
	 * Show a loading image after user selects to play movie
	 * Then after one second show the movie
	 */
	play: function() {
		/* Show loading image then show movie */
		this.playEl.getElementsByTagName("span")[0].innerHTML = "Loading";
		this.playEl.getElementsByTagName("img")[0].src = "images2/loading.gif";
		setTimeout("zzcylaw.TVSpot.showMovie()", 1000);
	},

	/**
	 * Show the movie; hides play button and preview image;
	 * shows text asking user to download Flash if they don't have Flash;
	 * otherwise uses swfobject to dynamically create a Flash movie, using
	 * the code most appropriate for the browser.
	 * Also sets a timeout to show a "Play again" link after the movie is over.
	 */
	showMovie: function() {
		this.playEl.style.display = "none";
		this.movieImg.style.display = "none";
		document.getElementById("as-seen-on-tv").style.display = "none";
		var p = document.getElementById("swf-movie").getElementsByTagName("p")[0];
		if (typeof p != "undefined") {
			p.style.visibility = "visible";
		}
		
		var params = {
			loop: "false",
			menu: "false",
			quality: "high"
		};
		
		swfobject.embedSWF("swf/texas_pi_law_firm.swf", 
			"swf-movie", "240", "160", "7", null, null, params);
		
		/* Show play again link */
		setTimeout("zzcylaw.TVSpot.finishMovie()", 15000);
	}
};

zzcylaw.TVSpot.init();
