videoSections = [
		["Snaplock" , [
				["3950076102811036874", "Introduction", "4:07" ],
				["-1759182532634024067", "Installation (Part 1)", "3:14" ],
				["2744811460814021028", "Installation (Part 2)", "1:45" ] ]
		],
		["Nailup" , [
				["-132256749577129636", "Nailup Installation", "1:50"],
				["-2574749241401069303", "Nailup #27 Install", "3:46" ] ]
		],
		["Standard DropIn" , [
				["2152834548899799225", "Standard DropIn", "3:00" ],
				["5099777922205509574", "Painting the Grid", "2:31"],
				["-8259682084412651893", "The Edge", "2:00"] ]
		],
		["3D DropIn" , [
				["-1522781052068526606", "Introduction", "3:24" ],
				["-4113803173981760709", "Recessed Lights", "1:33" ],
				["-9031057101980201878", "Filler Options", "1:48" ],
				["-3942949731102020441", "Introduction Animation", "0:24" ],
				["-8461248688555027764", "Fitting Small Spaces", "2:05" ],
				["-8707206159314552210", "Manufacture Cuts", "0:57" ] ]
		],
		["BackSplash" , [
				["3596304207663897588", "Introduction", "3:10" ],
				["3525295648627957977", "Animated Demonstration", "1:22" ],
				["-284699161439275773", "Installation (Part 1)", "1:04" ],
				["8963224972240477862", "Installation (Part 2)", "1:06" ],
				["4060871191764732911", "Introducing Pattern 30", "1:47" ] ]
		],
		["Molding" , [
				["-1047780259322605910", "Introduction", "2:58" ],
				["-7015880105722984660", "Installation (General)", "2:27" ],
				["-6677418977106876507", "Installation (Miters)", "0:38" ],
				["-7387307115740678532", "Installation (Compound)", "0:56" ],
				["6464609608967491837", "Flat Molding", "2:43" ] ]
		],
		["Misc" , [
				["-5706968828955318852", "Recess Lights", "0:35" ],
				["-1150111403070395343", "24in Patterns", "0:56" ],
				["-3055668081970264016", "Painting Techniques", "0:21"]]
		]
		];	

GoogleVideoPlayer = function(){

	var player = this;
	
	this.isVisible = false;
	this.isBuilt = false;
	
	this.accordion = "";
	this.active = null;
	
	this.togglers = [];
	this.stretchers = [];
	this.bgFx = [];	
	
	this.attachPlayer = function(){

			if( !document.getElementsByTagName) return;
			
			var links = $S('a');
			
			links.each(function(link){
				if( link.getProperty('rel') == 'video' ){
						link.onclick = function(){
							if(player.isVisible) return false;
							if(!player.isBuilt) player.buildPlayer();
							player.render(this.href);
							return false;
						}
				}
			});
			
	 }
	 
	 this.buildPlayer = function(){

			var gPlayer = new Element('div').setProperty('id', 'GoogleMoviePlayer');
			gPlayer.setStyle('display', 'none');
			
			var leftSide = new Element('div').addClass("leftSide");
						
			var titleBar = new Element('div').addClass("format");
			titleBar.appendChild( new Element('span').addClass("title").setProperty('id','GoogleMoviePlayerTitle') );
		
			var closeX = new Element('span').addClass("close");
			var closeXlink = new Element('a').setProperty('href','#').appendText('X');
			closeXlink.onclick = function() { player.hidePlayer(); return false; }
			closeX.appendChild( closeXlink );
			titleBar.appendChild(closeX);
							 
			leftSide.appendChild(titleBar);
					
			var embedContainer = new Element('div').setProperty('id','GoogleMoviePlayerEmbedContainer');
			embedContainer.setStyle('color',"#000000");
				
			leftSide.appendChild(embedContainer);
																		
			var footBar = new Element('div').addClass("format");
			footBar.appendChild( new Element('span').addClass('bottomPlayer').
				appendText("* Video will start automatically. May require time to load.") );
			leftSide.appendChild(footBar);								
														
			gPlayer.appendChild(leftSide);
						
			var rightSide = new Element('div').addClass('rightSide');
			var related = new Element('div').addClass('format');
			related.appendChild( new Element('span').addClass('title').appendText('Related Videos') );
			rightSide.appendChild(related);
						
			var movieSection = new Element('div').setProperties({ 'id' : "GoogleMovieSections", 'class' : "format" });

			var colorChange = new Fx.Color(embedContainer, 'color', {duration:1250, 
					onComplete : function(){ $('GoogleMoviePlayerEmbed').setStyle('display', 'block')}
			});
					
			videoSections.each(function(section,sectionIdx){
												
				var aToggler = new Element('p').addClass('toggler').appendText(section[0]+" Videos");
				movieSection.appendChild( aToggler );
								
				player.togglers[sectionIdx] = aToggler;
				aToggler.defaultColor = "#FFF";			
				player.bgFx[sectionIdx] = new Fx.Color(aToggler, 'background-color', {wait: false});
									
				var aAccordion = new Element('ul').addClass('accordion').setStyles({'height': '0', 'overflow': 'hidden'});
				player.stretchers[sectionIdx] = aAccordion;
		
		
		
				section[1].each(function(video){
					var aLi = new Element('li').setProperties({
											'docId' :	"http://video.google.com/googleplayer.swf?docId="+video[0]+"&hl=en&autoplay=true",
											'id' 	: 	'gvid_'+video[0],
											'title' : video[1],
											'section' : sectionIdx});
		
					aLi.appendChild( new Element('span').appendText(video[1]) );
					aLi.appendChild( new Element('span').addClass('time').appendText(video[2]) );
					aLi.onmouseover = function(){ this.addClass('over'); }
					aLi.onmouseout = function(){ this.removeClass('over'); }
					aLi.onclick = function(){
					
						if( player.active ){ $(player.active).removeClass('active'); }
						player.active = this.id;
						this.addClass('active');
						
						$('GoogleMoviePlayerTitle').setHTML( videoSections[this.getProperty('section')][0] + ": " + this.getProperty('title') );
						
						var embedContainer =  $('GoogleMoviePlayerEmbedContainer');	
						embedContainer.innerHTML = "";
						embedContainer.appendChild(player.newEmbed(this.getProperty('docId')) );
			
						embedContainer.setStyle('color','#000000');
					}
					aAccordion.appendChild( aLi );								
				});							
								
				movieSection.appendChild( aAccordion );	
							
			});
					
			this.accordion = new Fx.Accordion(player.togglers, player.stretchers, { opacity: false, start: false, transition: Fx.Transitions.quadOut,
			
				onActive: function(toggler, i){
					player.bgFx[i].toColor('#e0542f');
					toggler.setStyle('color', '#FFF');
				},
		
				onBackground: function(toggler, i){
					player.bgFx[i].clearTimer();
					toggler.setStyle('background-color', toggler.defaultColor);
					toggler.setStyle('color', '#222');
				}
			});
								
			rightSide.appendChild(movieSection);
						
			gPlayer.appendChild( rightSide );
																
			document.getElementsByTagName('BODY')[0].appendChild(gPlayer);	 
	 
	 		this.isBuilt = true;

	 }  //end of buildPlayer	 
			
	this.render = function(aLink){
	
			this.isVisible = true;	
			
			var key = this.getKey("docId",aLink);
	
			$("gvid_"+key).onclick();

			var gPlayer = $('GoogleMoviePlayer');
			
			var wW = Window.getWidth();
			var wH = Window.getHeight();
			
			var wSt = Window.getScrollTop();
			var wSl = Window.getScrollLeft();
			
			var left = ( wSl + (( wW / 2 ) - 335 ) ) < 0 ? 0 : (  wSl + (( wW / 2 ) - 335 ) );
			var top  = ( wSt + (( wH / 2 ) - 194 ) ) < 0 ? 0 : (  wSt + (( wH / 2 ) - 194 ) );
			
			gPlayer.setStyles({top: top+"px", left: left+"px", display : 'block'});
			this.accordion.showThisHideOpen( $('gvid_'+key).getProperty('section') );
	}
	
	this.hidePlayer = function(){
			this.isVisible = false;
			$('GoogleMoviePlayer').setStyle('display','none');
	}
	
	this.getKey = function (key,url){
		if( url.indexOf("?") >= 0 ){
			qs = url.substring( url.indexOf("?")+1, url.length);
		} else return null;
		
		var pairs = qs.match(/^\??(.*)$/)[1].split('&');
		var params = {};
		
		for(var i = 0; i < pairs.length; i++ ){
			pair = pairs[i].split('=');
			params[pair[0]] = pair[1];
		}		
		return params[key];
	}
	
	this.newEmbed = function(aSrc){

		return  new Element('embed').setProperties({ 
				FlashVars : "playerMode=embedded", 
				salign : "TL", 
				scale : "noScale", 
				bgcolor : "#ffffff",
				quality : "best",
				align : "middle",
				type : "application/x-shockwave-flash",
				src : aSrc,
				id : "GoogleMoviePlayerEmbed" });
	
	}
}

var gvp = new GoogleVideoPlayer();
old_addEvent(window, 'onload', gvp.attachPlayer);