var video = {
	setGlobals: function() {
		video.openLinks = jQuery('a[rel="open-video"]');
		video.closeRel = 'close-video-window';
		video.videoWindowHTML = '<div id="video-window"><a href="#" id="close-link" rel="' + video.closeRel + '">close window</a><a id="view-collection" href="" class="displayNone">View Collection</a><div id="video-player"></div></div>'; 		
		video.backButtonMask = '<div style="position: absolute; top: 0; left: 0; cursor: default; z-index: 100; background: white; height: 36px; width: 41px; opacity: 0;"></div>';
	},

	setVideo: function() {
		video.init();
	},
	
	assignVideoWindow: function() {
		video.vw = jQuery('div#video-window');
	},

	openVideo: function(videoUrl, videoHeight) {
		var vUrl = videoUrl;
		jQuery('div#wrapper').append(video.videoWindowHTML);
		video.assignVideoWindow();
		var cl = jQuery('a[rel="' + video.closeRel + '"]');
		var vcl = jQuery('div#video-window a[rel="' + video.closeRel + '"]');
		video.setCloseLinks(cl);
		vcl.addClass('hidden')
			.animate({ opacity: 0.5 }, 250)
			.hover(				
				function(){ jQuery(this).animate({ opacity: '0.85' }, 100); },
				function(){ jQuery(this).animate({ opacity: '0.5' }, 100); }
		);
		jQuery('#thumb_scroller').css({ width: '0px', display: 'none', opacity: 0 });
		jQuery('#available-on').fadeOut('fast');
		brizo.sideNav.fadeOut('fast');
		brizo.scrollerTitles.fadeOut('fast');
		brizo.thumbWrapper.fadeOut('fast');		
		video.vw.animate({ opacity: 1, top: '120px', left: '214px', width: '688px', height: '542px' }, 100, brizo.easing, function(){
			// ALTERNATE/MULTIPLE VIDEOS
			// Look for vUrl param and if it exists, play the flv specified in the URL rather than page default
			if (vUrl.indexOf('vUrl') != -1) {
				if(vUrl.indexOf('?' != -1) && vUrl.indexOf('flv=' != -1)) {
					var splitString = vUrl.split('vUrl=');					
					video.playVideo(splitString[1]);
				} else {
					video.playVideo(vUrl);
				}
			} else {
				video.playVideo();
			}			
		}).css({ zIndex: 79 });
	},
	
	closeVideo: function() {
		video.assignVideoWindow();
		video.vw.animate({ opacity: '0', top: '275px', left: '401px', width: '300px', height: '200px' }, 200, brizo.easing, function(){			
			video.vw.remove();
			brizo.sideNav.fadeIn('fast');
			brizo.thumbWrapper.fadeIn('fast');
			jQuery('#thumb_scroller').css({ width: '680px', display: 'block', opacity: 1 });
			jQuery('#available-on').fadeIn('fast');
		});
	},
	
	setOpenLinks: function() {
		video.openLinks.bind('click', function(){
			brizo.hideContentBody();
			var vUrl = jQuery(this).attr('href');
			var $thisId = jQuery(this).attr('id');
			var $this = jQuery(this);
			setTimeout(function(){ video.openVideo(vUrl); }, 100);
			return false;
		});
	},

	setCloseLinks: function(closeLink) {
		closeLink.bind('click', function(){
			video.closeVideo();
			setTimeout(function(){ brizo.showContentBody(); }, 100);
			return false;
		});
	},

	playVideo: function(videoUrl) {
		if (typeof videoUrl === 'undefined') {
			swfobject.embedSWF( "/flash/videoplayer.swf", "video-player", "688", "522", "9.0.0", "flash/expressinstall.swf", flashvars, params, attributes);
		} else {
			flashvars.videoURL = videoUrl;
			swfobject.embedSWF( "/flash/videoplayer.swf", "video-player", "688", "522", "9.0.0", "flash/expressinstall.swf", flashvars, params, attributes);
		}
	},
	
	init: function(openLinks) {
		video.setGlobals();
		video.setOpenLinks();
	}
};

$(document).ready(function(){
	video.setVideo();

	if(document.location.hash.indexOf('video') != -1) {
		setTimeout(function(){
			video.openLinks.click();
		}, 500);
	}

});