var videos = { 
		'ED-short' : 'http://dl.dropbox.com/u/6949138/ForerunED2short.flv', 
		'digitalpen1' : 'http://dl.dropbox.com/u/6949138/DigitalPen1600.flv',
		'it1' : 'http://dl.dropbox.com/u/6949138/halamka.flv',
	        'executives1' : 'http://dl.dropbox.com/u/6949138/levy.flv',
	        'clinicians1' : 'http://dl.dropbox.com/u/6949138/rosen.flv',
	        'dashboard1' : 'http://dl.dropbox.com/u/6949138/nathanson.flv',
		'testimonials1' : 'http://dl.dropbox.com/u/6949138/pinkes.flv',
		'testimonials2' : 'http://dl.dropbox.com/u/6949138/masser.flv'
	 };

$(document).ready(function() 
{
	var openVideo = function(tabno) {
                setVideoDocHeight();
                $('#video-overlay,#video-tabs,#video-tabs-shadow').removeClass('ui-helper-hidden');
		if(typeof tabno != 'undefined')
		{
			setTimeout("$('#video-tabs').tabs('select',"+tabno+");",300);
			if(tabno == 0)
			{
				embedVideo('#ED-short-video', videos['ED-short']);
			}
			else
			{
				embedVideo('#digitalpen-video', videos['digitalpen1']);
			}
		}
		else
		{
			embedVideo('#video', videos['ED-short']);
		}
	};
	var hideOverlay = function() {
		$('#video-overlay,#video-tabs,#video-tabs-shadow').addClass('ui-helper-hidden');
		$('#ED-short-video,#digitalpen-video').html('');
	};
	var setVideoDocHeight = function() {
		$('#video-overlay').css({ height: $(document).height() });
	};
	var embedVideo = function(id, video, width, height) {
		width = (typeof width == 'undefined') ? '640' : width;
		height = (typeof height == 'undefined') ? '480' : height;
		flashembed(id, {
			src: 'media/FlowPlayerLP.swf',
			width: width,
			height: height
		}, { config: {
			autoPlay: true,
		        autoBuffering: true,
	        	controlBarBackgroundColor:'0x055A8D',
		        initialScale: 'scale',
			videoFile: video,
			menuItems: [1,1,1,1,1,0],
			loop: false
		}});
	};

	//buttons
	$('#home-splash a.open-video,#contact-head a').button();
	$('#home-splash a.open-video,#home-pane2 a.open-video.digitalpen1').button({
		icons: { primary: 'ui-icon-arrowthick-1-e', secondary: 'ui-icon-video' }
	});

	//top navigation
	$('ul#top-navigation li').hover(function() {
		$(this).find('ul.subnav')
		.stop()
		.removeAttr('style')
		.slideDown('fast', function() {
			$(this).removeClass('ui-helper-hidden');
		}).parent().addClass('has-submenu');
	}, function() {
		$(this).find('ul.subnav')
		.stop()
		.slideUp('fast', function() {
			$(this).removeAttr('style')
			.addClass('ui-helper-hidden')
			.parent().removeClass('has-submenu');
		});
	});

	//video stuff
	$('#video-tabs').tabs()
	.find('.ui-tabs-nav').css({ visibility: 'hidden' });

	$(window).resize(setVideoDocHeight);
	
	$('#video-overlay,#video-close').click(hideOverlay);
	$('#video-close').hover(function() { 
		$(this).addClass('ui-state-hover');
	},function() {
		$(this).removeClass('ui-state-hover');
	});

	$('.side-video').click(function() {
		embedVideo('#'+$(this).parent().attr('id'), videos[$(this).find('img').attr('class')], 200, 150);
	});

	//only used on front page
	$('.open-video').data('video-index','0').click(function() { openVideo($(this).data('video-index')); return false; })
	.filter('.digitalpen1').data('video-index','1');

	if($('#open-video').val()) 
	{
		var tabno = 0;

		if(window.location.hash.length > 0)
		{
			if(window.location.hash.match(/digital.*pen/)) { tabno = 1; }
		}

		openVideo(tabno);
		//terrrrrrrible race condition workaround for FF anchor jump problem
		//FF jumps to the anchor AFTER the flash video loads; it cannot be overridden
		//and the time it takes to load the player is not constant
		setTimeout("$('html').scrollTop(0);",1000); 
	}
});
