
VideoManager = {

	imgPath: "_images/fomlc/campaign/",
	
	defaultId: "z11",		
	
	songPaths:[{id:"z", path:"http://datagram.cottoninc.com/fomlc/mp3/ZooeyDeschanel_FabricOfMyLife.mp3.zip"},
			   {id:"m", path:"http://datagram.cottoninc.com/fomlc/mp3/MirandaLambert_FabricOfMyLife.mp3.zip"},
			   {id:"j", path:"http://datagram.cottoninc.com/fomlc/mp3/JazmineSullivan_FabricOfMyLife.mp3.zip"}],
	
	currId:null,
	
	currSongPath:null,
	
	init: function(event) {
		$(".videoList a").click(function(event){
			this.blur();			// Remove focus (gets rid of box outline on link)
			var vidId = $(this).attr("rel");
			VideoManager.featuredRequest(vidId);
			event.preventDefault();
		});
		
		$("#downloadLink a").click(function(event){
			this.blur();
			if (VideoManager.currSongPath != null) {
				window.location = VideoManager.currSongPath;
				// window.open(VideoManager.currSongPath,'Download');
			}
			event.preventDefault();
		});
		
		// Set our initial video.
		var vidId = (!$.jqURL.get('vidId')) ? VideoManager.defaultId : $.jqURL.get('vidId');
		// VideoManager.featuredRequest(vidId);
		
		// Set our share popup.
		VideoManager.initShareMenu();
	},
	
	featuredRequest: function(vidId) {
		// Notify videoMenu of featuredRequest selection.  
		Utils.getSwfReference("videoMenu").vidSelected(vidId);
	},
	
	setVideo: function(vidId, vidCode, vidTitle) {
		if (vidCode == "") return;
		
		VideoManager.currId = vidId;
		
		// Set the title.
		vidTitle = VideoManager.clearBreaks(vidTitle);
		$("#nowPlaying .title").html(vidTitle);
		
		// Set the video.
		var embedStr = "";
		embedStr += '<object width="640" height="385"><param name="movie" value="http://www.youtube-nocookie.com/v/';
		embedStr += vidCode + '&hl=en&fs=1&color1=0x3a3a3a&color2=0x999999&rel=0&showinfo=0&autoplay=1&ap=%2526fmt%3D18"></param><param name="allowFullScreen" ';
		embedStr += 'value="true"></param><param name="allowscriptaccess" value="always"></param>';
		embedStr += '<param name="wmode" value="transparent"></param><embed ';
		embedStr += 'src="http://www.youtube-nocookie.com/v/' + vidCode + '&hl=en&fs=1&color1=0x3a3a3a&color2=0x999999&rel=0&showinfo=0&autoplay=1&ap=%2526fmt%3D18" ';
		embedStr += 'type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" width="640" height="385">';
		embedStr += '</embed></object>';
		
		$("#video").html(embedStr);	
		
		// Update the featured video thumbs.
		VideoManager.updateFeatured();
		
		// Track the request.
		/*
		var tag;
		switch (vidId.charAt(0)) {
			case "m":
				tag = "/TheFabricOfMyLife/Campaign-MirandaTV";
				break;
			case "j":
				tag = "/TheFabricOfMyLife/Campaign-JazmineTV";
				break;
			case "z":
				tag = "/TheFabricOfMyLife/Campaign-ZooeyTV";
				break;
		}
		pageTracker._trackPageview(tag);
		*/
	},
	
	clearBreaks: function(str) {
		var strArr = str.split("<br>");
		str = strArr.join(" ");
		return str;
	},
	
	updateFeatured: function() {
		// Set all 3 thumbs to active state.
		$(".videoList .thumb a").addClass("active").removeClass("selected");
		// If current vid is a 'featured', update thumb.
		var id = VideoManager.currId.charAt(0);
		switch (id) {
			case "m":
				$(".videoList .miranda .thumb a").removeClass("active").addClass("selected");
				break;
			case "j":
				$(".videoList .jazmine .thumb a").removeClass("active").addClass("selected");
				break;
			case "z":
				$(".videoList .zooey .thumb a").removeClass("active").addClass("selected");
				break;
		}
		// Set the current song path.
		VideoManager.currSongPath = VideoManager.getSongPath(id);
	},
	
	getSongPath: function(id) {
		for (var i=0; i < VideoManager.songPaths.length; i++) {
			if (VideoManager.songPaths[i].id == id) {
				return VideoManager.songPaths[i].path;
			}
		}
	},
	
	initShareMenu: function() {
		$("#shareButton").popupmenu({
							target: "#shareMenu", 
							time: 300,
							speed: "80"});
		
		/*
		$("#shareMenu a").tooltip({track: true, 
								   showURL:false});
		*/
		
		$("#shareMenu a.social").click(function(event){
			var shareType = $(this).attr("rel");
			var params = "vidId=" + VideoManager.currId;
			var title = "Video at TheFabricOfMyLife.com";
			
			Utils.sharePage(shareType, title, params);
			
			// Track the event.
			pageTracker._trackPageview("/TheFabricOfMyLife/Campaign-Share");
			
			event.preventDefault();
		});
		
		// Initialize the share popup link.
		$("#shareMenu .send a").click(function(event) {
			var params = "vidId=" + VideoManager.currId;
			Utils.sharePage("send", null, params);
			event.preventDefault();
		});
	}
};

