
// Author: Kris Khoury, Duo Consulting 2010
// Project: Web Content 2010
// Requirements: SWF Object Class & jQuery
// Created On: 7/14/2010

(function($){
	$.fn.duoVideos = function(options) {
		var defaults = {
			this_site: 		"http://www.webcontent2010.com/",
			this_player: 	"res/flash/player.swf",
			this_page: 		"videos.html",
			no_photo: 		"res/img/no_photo.gif"
		};
		var options = $.extend(defaults, options);
		return this.each(function(){
								  
			var attributes = {};
			
			var presenter_data = {"movies":
				[
					{"name":"Jeff MacIntyre","photo":["res/img/bio-jeff-macintyre.jpg"],"company":"Predicate","title":"A Methodology for Content Strategy","hash":"jeff-macintyre","file":"2534013660b5","width":480,"height":270,"use_flash":"true"},
					{"name":"Ben Brown","photo":["res/img/bio-benbrown.jpg"],"company":"XOXCO","title":"Building and Running an Online Community","hash":"ben-brown","file":"135a57e3c953","width":480,"height":360,"use_flash":"true"},
					{"name":"Kelly Tetterton &amp; Fred Salchli","photo":["res/img/bio-kellyt.jpg","res/img/bio-fred.jpg"],"company":"Duo Consulting","title":"Building Christian Science Monitor","hash":"tetterton-salchli","file":"a6c8a7f5b58a","width":480,"height":360,"use_flash":"true"},
					{"name":"Kristina Halvorson","photo":["res/img/bio-kristina-halvorson.jpg"],"company":"Brain Traffic","title":"Content First","hash":"kristina-halvorson","file":"b1b5b94ce79d","width":480,"height":270,"use_flash":"true"},
					{"name":"Emanual London","photo":[""],"company":"Duo Consulting","title":"Drupal","hash":"emanual-london","file":"c797f82af07f","width":480,"height":360,"use_flash":"true"},
					{"name":"Jeff Eaton","photo":["res/img/bio-eaton.jpg"],"company":"Lullabot","title":"Drupal","hash":"jeff-eaton","file":"db8f7a71d034","width":480,"height":360,"use_flash":"true"},
					{"name":"Josh Ward","photo":[""],"company":"Volacci","title":"Drupal","hash":"josh-ward","file":"105b8e661969","width":480,"height":360,"use_flash":"true"},
					{"name":"Ryan Szrama","photo":["res/img/bio-ryan.jpg"],"company":"Commerce Guys","title":"Drupal","hash":"ryan-szrama","file":"59a108b336f2","width":480,"height":360,"use_flash":"true"},
					{"name":"Sonny Cohen &amp; Doug Vann","photo":["res/img/bio-sonny.jpg","res/img/bio-dougvann.jpg"],"company":"Duo Consulting","title":"Drupal","hash":"cohen-vann","file":"794f31f8b32c","width":480,"height":360,"use_flash":"true"},
					{"name":"Joe Pulizzi","photo":["res/img/bio-joe-pulizzi.jpg"],"company":"Content Marketing Evangelist","title":"Finding Your Content Marketing Strategy in 8 Steps","hash":"joe-pulizzi","file":"edc27ecd1948","width":480,"height":270,"use_flash":"true"},
					{"name":"Margot Bloomstein","photo":["res/img/bio-bloomstein.jpg"],"company":"Appropriate, Inc.","title":"Leave Them Begging For More","hash":"margot-bloomstein","file":"214466472931","width":480,"height":270,"use_flash":"true"},
					{"name":"Robert Rose","photo":["res/img/bio-robrose.jpg"],"company":"Big Blue Moose","title":"Social Media Brand Management","hash":"rob-rose","file":"4860f854fed0","width":480,"height":270,"use_flash":"true"},
					{"name":"Scott Abel","photo":["res/img/bio-scottabel.jpg"],"company":"The Content Wrangler","title":"Socially-enabled Everything","hash":"scott-abel","file":"81c3ba81676e","width":480,"height":270,"use_flash":"true"},
					{"name":"Arona Primalani","photo":["res/img/bio-arona.jpg"],"company":"Earley & Associates","title":"Taxonomy and Metadata in Digital Asset Management","hash":"arona-primalani","file":"722f5d578a3b","width":480,"height":360,"use_flash":"true"},
					{"name":"Rachel Lovinger","photo":["res/img/bio-rachel-lovinger.jpg"],"company":"Razorfish","title":"There's No Semantic Web without Content and Data","hash":"rachel-lovinger","file":"2bd82a065f24","width":480,"height":270,"use_flash":"true"},
					{"name":"Rob Purdie","photo":["res/img/bio-robpurdie.jpg"],"company":"The Economist","title":"Transforming the Economist using SCRUM","hash":"rob-purdie","file":"64d49b46299c","width":480,"height":360,"use_flash":"true"},
					{"name":"Karen McGrane &amp; Jeff Eaton","photo":["res/img/bio-KarenMcGrane.jpg","res/img/bio-eaton.jpg"],"company":"Bond Art + Science & Lullabot","title":"Content Strategy Will Make or Break Your Process","hash":"mcgrane-eaton","file":"51867b55e407","width":480,"height":270,"use_flash":"true"}					
				]
			};

			//BUILDS CODE FOR MODAL WINDOW
			function build_modal(modal_id,flash_id,title,presenter,width,height,movie_guid,use_flash){
				
				//BUILDS OUTER SHELL
				var modal_outer = 		document.createElement('div');
				modal_outer.setAttribute("class","modal_outer");
				modal_outer.setAttribute("id",modal_id);
				modal_outer.setAttribute("align","center");
				
				//BUILDS INNER SHELL
				var modal_inner = 		document.createElement('div');
				modal_inner.setAttribute("class","modal_inner");
				modal_outer.appendChild(modal_inner);
				
				//BUILDS TITLE
				var modal_title = 		document.createElement('h2');
				modal_title.innerHTML = title;
				modal_inner.appendChild(modal_title);
				
				//BUILDS DIV THAT GETS REPLACED WITH FLASH CODE
				var modal_flash = 		document.createElement('div');
				modal_flash.setAttribute("id",flash_id);
				if(use_flash == "false"){
					modal_flash.innerHTML = '<embed src="'+movie_guid+'"  width="'+width+'" height="'+height+'" autoplay="false" loop="false" controller="true" pluginspage="http://www.apple.com/quicktime/"></embed>';
				}
				modal_inner.appendChild(modal_flash);
			
				//TAG FOR PRESENTER NAME
				var modal_presenter = 	document.createElement('h3');
				modal_presenter.innerHTML = "by "+presenter;
				modal_inner.appendChild(modal_presenter);
				
				//DIV FOR EMBED INFORMATION
				var modal_embed = 		document.createElement('div');
				modal_embed.setAttribute("class","embed");
				modal_inner.appendChild(modal_embed);
			
				//TEXT INSTRUCTIONS FOR EMBED
				var modal_text_message = document.createElement('span');
				modal_text_message.innerHTML = "<div style='float:left'>Embed this in your site:</div><div style='float:right'>click to select code</div>";
				
				//TEXTAREA HOUSING EMBED CODE
				var modal_text = 		document.createElement('textarea');
				modal_text.setAttribute("readonly","readonly");
				modal_text.setAttribute("onfocus","var self=this;setTimeout(function(){self.select()},300);");
				if(use_flash == "true"){
					modal_text.value = '<object width="'+width+'" height="'+height+'"><param name="movie" value="'+options.this_site+options.this_player+'?swfid='+movie_guid+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+options.this_site+options.this_player+'?swfid='+movie_guid+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+width+'" height="'+height+'"></embed></object>';
				}else{
					modal_text.value = '<embed src="'+movie_guid+'"  width="'+width+'" height="'+height+'" autoplay="false" loop="false" controller="true" pluginspage="http://www.apple.com/quicktime/"></embed>';
				}
			
				modal_embed.appendChild(modal_text_message);
				modal_embed.appendChild(modal_text);
				
				return modal_outer;
			}

			
			var presenter_shell = 	document.createElement('div');
			presenter_shell.setAttribute("class","presenter_shell");
			
			for(var i=0;i<presenter_data.movies.length;i++)
			{
				var obj = 			presenter_data.movies[i];
				var name = 			obj.name;
				var photo = 		obj.photo;
				var company = 		obj.company;
				var title =			obj.title;
				var file = 			obj.file;
				var width = 		obj.width;
				var height = 		obj.height;
				var hash = 			obj.hash;
				var use_flash = 	obj.use_flash;
				
				var modal_window_name = 	"modal" + i;
				var modal_flash_name = 		"flash" + i;
				var hash_url = 				options.this_site+options.this_page+"#"+hash;
				
				if(document.location.hash.length > 0){
					if(document.location.hash == "#"+hash){
						$(".presenter_shell").html("");
						presenter_shell.appendChild(build_modal(modal_window_name,modal_flash_name,title,name,width,height,file,use_flash));
						swfobject.embedSWF(options.this_site+options.this_player, modal_flash_name, width, height, "9.0.0","expressInstall.swf", {swfid:file}, {menu:"false",play:"true",allowfullscreen:"true"}, attributes);
					}
				}else{
					var presenter_box = document.createElement('div');
					presenter_box.setAttribute("class","presenter_box");
					var presenter_photo = document.createElement('div');
					presenter_photo.setAttribute("class","presenter_photo");
					var presenter_info = document.createElement('div');
					presenter_info.setAttribute("class","presenter_info");
			
					for(var x=0;x<photo.length;x++){
						var presenter_img = document.createElement('img');
						var presenter_br = document.createElement('br');
						if(photo[x] == ""){
							presenter_img.setAttribute("src",options.this_site+options.no_photo);
						}else{
							presenter_img.setAttribute("src",photo[x]);
						}
						presenter_img.setAttribute("width","110");
						presenter_img.setAttribute("height","110");
						presenter_img.setAttribute("class","speakerImage");
						presenter_photo.appendChild(presenter_img);
						if(x < photo.length-1){
							presenter_photo.appendChild(presenter_br);
						}
					}
					presenter_box.appendChild(presenter_photo);
					
					var presenter_name = document.createElement('h2');
					var presenter_title = document.createElement('b');
					var presenter_watch = document.createElement('a');
					var presenter_share = document.createElement('a');
					
					var presenter_modal_hidden = document.createElement('div');
					presenter_modal_hidden.setAttribute("style","display:none");
					
					var presenter_modal = 		document.createElement('div');
					
					presenter_modal.setAttribute("id",modal_window_name);
					presenter_modal.appendChild(build_modal(modal_window_name,modal_flash_name,title,name,width,height,file,use_flash));
					
					presenter_name.innerHTML = name + "<br>" + company;
					presenter_title.innerHTML = title;
					
					presenter_watch.innerHTML = "&nbsp;";
					presenter_share.setAttribute("href",hash_url);
					presenter_share.innerHTML = "Permalink";
					
					presenter_watch.setAttribute("href","#");
					presenter_watch.setAttribute("class",modal_window_name+" watch");
					presenter_watch.setAttribute("title","&nbsp;");
					
					presenter_info.appendChild(presenter_name);
					presenter_info.appendChild(presenter_title);
					presenter_info.appendChild(presenter_watch);
					presenter_info.appendChild(presenter_share);
					
					presenter_box.appendChild(presenter_info);
					presenter_shell.appendChild(presenter_box);
					presenter_modal_hidden.appendChild(presenter_modal);
					presenter_shell.appendChild(presenter_modal_hidden);
					
					if(use_flash == "true"){
						swfobject.embedSWF(options.this_site+options.this_player, modal_flash_name, width, height, "9.0.0","expressInstall.swf", {swfid:file}, {menu:"false",play:"true",allowfullscreen:"true"}, attributes);
					}
				}
			}

			$(this).append(presenter_shell);

			for(var i=0;i<presenter_data.movies.length;i++)
			{
				var obj = 					presenter_data.movies[i];
				var _width = 				obj.width+170;
				var _height = 				obj.height+300;
				var modal_window_name = 	"modal"+i;
				
				$("."+ modal_window_name).colorbox({width:_width, height:_height, inline:true, href:"#"+modal_window_name});
			}
			
		});
	};
})(jQuery);







