/**
 * @author jparkinson
 */

function muteMp3Player() {
	var flash;
	if(navigator.appName.indexOf("Microsoft") != -1) {
		flash = window.audioPlayer;
	} else {
		flash = window.document.audioPlayer;
	}
	flash.shush();
}

/*
$(document).ready(function(){
	var ringtones = document.getElementById("ringtones");
	var closebutton = document.getElementById("close-button2");
	var main = document.getElementById("left");
	
	ringtones.onclick = function(){
		if ($("#ringtones-info").hasClass("off")){
			if (document.getElementById("video-player") != null){
				main.removeChild(document.getElementById("video-player"));
				main.removeChild(document.getElementById("close-button"));
			}
			$("#ringtones-info").removeClass("off");
			$("#ringtones-info").addClass("on");
			$("#ringtones-text").removeClass("off");
			$("#ringtones-text").addClass("on");
			
			closebutton.onclick = function(){
				$("#ringtones-info").removeClass("on");
				$("#ringtones-info").addClass("off");
				$("#ringtones-text").removeClass("on");
				$("#ringtones-text").addClass("off");
			}
			return false;
		} else {
			$("#ringtones-info").removeClass("on");
			$("#ringtones-info").addClass("off");
			$("#ringtones-text").removeClass("on");
			$("#ringtones-text").addClass("off");
		}
	}
});
*/

$(document).ready(function (){
	var video = document.getElementById("video");
	var main = document.getElementById("left");
	var vidplayer = document.createElement("div");
	var closebutton = document.createElement("div");
	
	video.onclick = function(){
		if ($("#ringtones-info").hasClass("on")){
			$("#ringtones-info").removeClass("on");
			$("#ringtones-info").addClass("off");
			$("#ringtones-text").removeClass("on");
			$("#ringtones-text").addClass("off");
		}
		if (document.getElementById("video-player") == null){
			vidplayer.setAttribute("id", "video-player");
			var vidtext = document.createTextNode("This Flash movie requires a newer version of the Flash plug-in. Please upgrade your Flash plug-in by visiting ");
			
			var macrotag = document.createElement("a");
			macrotag.setAttribute("id", "macromedia-tag");
			macrotag.setAttribute("href", "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash");
			macrotag.setAttribute("target", "_blank");
			var macrotext = document.createTextNode("www.macromedia.com");
			
			closebutton.setAttribute("id", "close-button");
			var closetext = document.createTextNode("Close");
			
			main.appendChild(closebutton);		
			main.appendChild(vidplayer);
			vidplayer.appendChild(vidtext);
			closebutton.appendChild(closetext);
			macrotag.appendChild(macrotext);
			vidplayer.appendChild(macrotag);
			
			closebutton.onclick = function(){
				main.removeChild(vidplayer);
				main.removeChild(closebutton);
			}
			
			loadVideoPlayer("http://i.cdn.turner.com/adultswim/music/athfchristmas/tools/swf/meaty-christmas.swf", "http://ht.cdn.turner.com/adultswim/big/music/athfchristmas/video/ATHF_XMAS_ALBUM_PROMO_dl.flv");
			muteMp3Player();
			return false;
		} else {
			main.removeChild(vidplayer);
			main.removeChild(closebutton);
		}
	}
});

function loadVideoPlayer(url, flv) {
	var swfwidth = 715;
	var swfheight = 529;
	
	var movieID = "deth-vid";
	
	var so = new SWFObject(url, movieID, swfwidth, swfheight, "8", "#ffffff");
			//this is to allow a target to open in a window besides _blank
		so.addParam("allowScriptAccess", "always");
		so.addParam("wmode", "transparent");
		
			//set omniture to true to turn on omniture
		so.addVariable("omniture", "false");
		
		so.addVariable("swfHeight", swfheight);
		so.addVariable("swfWidth", swfwidth);
	   
			//flv loads in a single video file
			//if you use "flv" you have to comment out "xml"
		so.addVariable("flv", flv);
	   
			//flvWidth and flvHeight are required variables - don't comment them out
			//they define the width and height of the videoArea
		so.addVariable("flvWidth", 624);
		so.addVariable("flvHeight", 351);
			//the alignment for the video player in the swf window
			//must be defined: set to left, right or center
		so.addVariable("alignment", "center");
			//to add to the x and y values of the flv set these, comment them out if not needed
		so.addVariable("flvX", 5);
		so.addVariable("flvY", 75);
	   
			//use this to add or subtract to the control area y position
			//set it to 0 to use the default
		so.addVariable("controlsX", 0);
		so.addVariable("controlsY", 3);
	   
			//autoplay is required - it must not be commented out
			//true automatically plays the video, false requires you a click before playing
		so.addVariable("autoplay", "true");
	   
			//loop is required - it must not be commented out
			//true sets the entire video and video list to replay
			//false will play through the video once and the entire playlist once
		so.addVariable("loop", "false");
	   
	   		//buffer variables
			//to have no buffer, comment out bufferingMessage
			//bufferingAlignment can be "insideBottomLeft",
		so.addVariable("bufferingMessage", "Buffering...");
		so.addVariable("bufferingAlignment", "insideBottomLeft")
		so.addVariable("bufferingFont", "Trebuchet MS");
		so.addVariable("bufferingFontSize", 14);
		so.addVariable("bufferingFontColor", 0xFFFFFF);
	   
			//controls is required - it must not be commented out
			//if true, the main controls under the video area is visible
			//if false, there is no main control area
			//if controls == true, make sure to turn off innerControls & vice versa
		so.addVariable("controls", "true");
			//innerControls is required - it must not be commented out
			//if true, the play/pause is visible inside the video area
			//if false, there is no inner controls
			//if innerControls == true, make sure to turn off controls & vice versa 
		so.addVariable("innerControls", "false");
			//playlistControls is required - it must not be commented out
			//if false they are not active
			//if bottom, the prev/next controls are on the very bottom of the swf
			//if insidebottom, the controls are on the bottom of inside the flv area
			//if leftbottom, the controls are on the left of the video area towards the bottom
		so.addVariable("playlistControls", "false");
	   
			//descriptionAreaAlign is required - it must not be commented out
			//describes where the description area can be in relation to the player
			//if bottom, it's under the player
			//if lefttop, it's to the left and towards the top
		so.addVariable("descriptionAreaAlign", "lefttop");
	   
			//stillPlayer is the image that displays the video player if the autoplay is turned off
			//stillVideo is the image that displays in the video area if autoplay is off and when a single flv has stopped playing
			//to have no still image, comment this out
		so.addVariable("stillPlayer", "http://i.cdn.turner.com/adultswim/music/athfchristmas/tools/img/video-player/placeholder.jpg");
		so.addVariable("stillVideo", "http://i.cdn.turner.com/adultswim/music/athfchristmas/tools/img/video-player/placeholder.jpg");
			//playerbg is the background image behind the video area
			//to have no bg, comment this out
		so.addVariable("playerbg", "http://i.cdn.turner.com/adultswim/music/athfchristmas/tools/img/video-player/vidbg.png");
		//so.addVariable("offsetBgX", 20);
		//so.addVariable("offsetBgY", 20);
	   
			//the next six variables can be commented out if you want to use the default icons 
			//controlsbg is the bg for the entire main control area
		so.addVariable("controlsbg", "http://i.cdn.turner.com/adultswim/music/dethalbum2/tools/img/video-player/controls-bg.png");
			//set this to true if you want to see the play/pause button
		so.addVariable("playPause", "true");
			//playImage is the image for the play button
		so.addVariable("playImage", "http://i.cdn.turner.com/adultswim/music/dethalbum2/tools/img/video-player/vid-play.png");
			//pauseImage is the image for the pause button
		so.addVariable("pauseImage", "http://i.cdn.turner.com/adultswim/music/dethalbum2/tools/img/video-player/vid-pause.png");
	  
		so.addVariable("playImageRO", "http://i.cdn.turner.com/adultswim/music/dethalbum2/tools/img/video-player/vid-play.png");
		so.addVariable("pauseImageRO", "http://i.cdn.turner.com/adultswim/music/dethalbum2/tools/img/video-player/vid-pause.png");
			//playX is for the X coord of the play/pause area in pixels
		so.addVariable("playX", 0);
	  
			//set this to true if you want to see the scrubber track
		so.addVariable("track", "true");
			//thumbImage is the image for the scrubber thumb
			//if you use one of the next 3, you  have to use them all
		so.addVariable("thumbImage", "http://i.cdn.turner.com/adultswim/music/dethalbum2/tools/img/video-player/scrubber.png");
			//loadedTrackImage is the image for the loaded scrub bar
		so.addVariable("loadedTrackImage", "http://i.cdn.turner.com/adultswim/music/dethalbum2/tools/img/video-player/timeline.png");
			//trackImage is the image for the unloaded scrub bar
		so.addVariable("trackImage", "http://i.cdn.turner.com/adultswim/music/dethalbum2/tools/img/video-player/timeline.png"); 
			//trackX is for the X coord of the track in pixels
		so.addVariable("trackX", 20);
	   
			//the following 6 are required parameters
			//set elapsed and/or to true if you want the elapsed time and false if not
		so.addVariable("elapsed", "false");
		so.addVariable("duration", "false");
			//timeFont is for the font face of the time displays
		so.addVariable("timeFont", "Verdana");
			//timeSize is for the size of the time displays font
		so.addVariable("timeSize", 10);
			//elapsedX is the X coord for the elapsed time
		so.addVariable("elapsedX", 305);
			//durationX is the X coord for the duration time
		so.addVariable("durationX", 275);
	  		//if controls is turned on and no images are set above these must not be commented out
			//these control the color of the default icons on the control areas
		so.addVariable("elapsedColor", 0xFF0F56);
		so.addVariable("durationColor", 0xF0F0FF);
	  
			//set the start volume of the video
			//from 0 to 100  (you can set higher, but the volume becomes distorted)
		so.addVariable("startVolume", 100);
			//if you add a volumeImage, you have to add them all or comment them all out
			//set volumeIcon to true/false to turn it on or off
		so.addVariable("volumeIcon", "true");
			//volumeImage is the image for the speaker icon
		so.addVariable("volumeImage", "http://i.cdn.turner.com/adultswim/music/dethalbum2/tools/img/video-player/volume-icon.png");
			//volumeIconX is for the X coord of the volume Icon in pixels
		so.addVariable("volumeIconX", 540);
			//muteImage is the image for the mute icon
			//if one of these next 3 is commented out, all them have to be
		so.addVariable("muteImage", "http://i.cdn.turner.com/adultswim/music/dethalbum2/tools/img/video-player/volume-icon-off.png");
			//volumeThumbImage is the image for the thumb on the scrubber bar
		so.addVariable("volumeThumbImage", "http://i.cdn.turner.com/adultswim/music/dethalbum2/tools/img/video-player/scrubber.png");
			//set volumeTrack to true/false to turn it on or off
		so.addVariable("volumeTrack", "true");
			//volumeTrackImage is the image for the scrubber bar
		so.addVariable("volumeTrackImage", "http://i.cdn.turner.com/adultswim/music/dethalbum2/tools/img/video-player/volume.png");
			//volumeTrackX is for the X coord of the volume track in pixels
		so.addVariable("volumeTrackX", 550);

	   		//this offsets the entire playlist area as much as you want
	    //so.addVariable("playlistOffsetX", 20)
			//this sets the width of the entire playlist area
			//comment it out to use the default
		//so.addVariable("playlistWidth", 188)
			//if playlistControls is turned on, these control the images being on that controls
			//use left center or right
		//so.addVariable("playlistAlign", "center");
			//for setting the closeness of the playlist buttons
			//use close or far 
			//far can only use center aligned
		//so.addVariable("playlistKerning", "close");
			//the space in pixels between the playlist controls
		//so.addVariable("playlistButtonSpace", 3);
			//the space in pixels from the left
		//so.addVariable("playlistControlsOffsetX", 23);
	 
			//for playlistCtrlsBg, put in a transparent gif/png with the appropriate height & width if you don't want a bg to show up
		//so.addVariable("playlistCtrlsBg", "/tools/img/video-player/nav-controls-bg.png");
			//comment out the next 4 variables if you don't want a next/previous control area
		//so.addVariable("playlistCtrlsPrev", "/tools/img/video-player/left-arrow.png");
		//so.addVariable("playlistCtrlsPrevRO", "/tools/img/video-player/left-arrow-rollover.png");
		//so.addVariable("playlistCtrlsNext", "/tools/img/video-player/right-arrow.png");
		//so.addVariable("playlistCtrlsNextRO", "/tools/img/video-player/right-arrow-rollover.png");
			//these 3 must not be commented out
		//so.addVariable("playlistSelected", "/tools/img/video-player/nav-box-active.png");
		//so.addVariable("playlistUnselectedRO", "/tools/img/video-player/nav-box-rollover.png");
		//so.addVariable("playlistUnselected", "/tools/img/video-player/nav-box.png");
		
		so.write("video-player");
}
