var Video = {
	init: function() {
		window.videoOnStop = function(id) {			
			Video.videoStop(id);
		};
		
		this.slides = $$(".videoSlide");
		
		// map stop id to the correct videoslide	
		// <key:videoId> : <value:slides array slide index>
		this.stops = { 3: 2, 2: 3, 4: 4};
		
		this.curr = 0;
		
		this.slides.each(function(el, i) {
			el.setStyle("display", (i == this.curr) ? "" : "none");
		}, this);
		
		// check if there's a video query string, and play that video
		var query = window.location.href.indexOf("?") != -1,
			startVideo = null;
		
		if (query) {
			startVideo = window.location.href.split("?")[1].parseQueryString();
			if (startVideo.video) {
				(function() {
					this.playVideo(parseInt(startVideo.video))
				}).delay(1000, this);
			}
		}
		
		
	},
	
	playVideo: function(index) {
		/*
	    var numberOfFlashcontents=$$('#flashContent').length;
		alert(numberOfFlashcontents);
		var flashHolderContent = $('flashHolder').get('html');
		$('flashHolder').empty().adopt(new Element('div', {id: 'flashContent', html: flashHolderContent }));
		//$$('#flashContent a').set('class', 'exitlink');
		*/

		swfobject.embedSWF(applicationRoot + "/common/swf/videoSection.swf", "flashContent", "632", "379", "9.0.0", applicationRoot + "/common/swf/expressInstall.swf", flashvars, params, attributes);		
				
	    var numberOfFlashcontents=$$('div#flashContent').length;
		this.slides[1].show();
		this.slides[this.curr].hide();
		
		var page = window.location.href.split("/").getLast();
		var flashvars = {
			xmlConfigUrl: applicationRoot + "/common/swf/xml/videoPlayerConfig.xml",
			pageUrl: page,
			autoStartId: index
		};
		var params = {
			menu: "true",
			wmode: "opaque",
			bgcolor: "#FFFFFF",
			base: applicationRoot + "/common/swf/",
			swliveconnect: "true",
			allowscriptaccess: "always",
			allowfullscreen: "true"
		};
		var attributes = {
			id: "videoSection",
			name: "videoSection"
		};
		if (numberOfFlashcontents == 0){
			document.id('flashHolder').empty().adopt(new Element('div', {id: 'flashContent'}));			
			swfobject.embedSWF(applicationRoot + "/common/swf/videoSection.swf", "flashContent", "632", "379", "9.0.0", applicationRoot + "/common/swf/expressInstall.swf", flashvars, params, attributes);
		}
		else{};
		this.curr = 1;
	},
	
	videoStop: function(id) {
		var index = this.stops[id];
		
		this.slides[index].show();
		this.slides[this.curr].hide();
		
		document.id("flashHolder").empty();
		
		this.curr = index;
	}

};
