jQuery(document).ready(function($){
	
	//Enable drop downs
	$('#menu li').hover(
		function () { $(this).find('ul:first').show(); },
		function () { $(this).find('ul:first').hide(); }
	);
	
	//Enable external links
	$('a[rel~=external], a[href^="http://"], a[href^="https://"]').attr('target','_blank');
	
	//Enable product videos
	if ( $('#enterprise-video').length ) {
		var setupVideoPlayer = function (selector, redirectTo) {
			var theLink = $(selector);
			theLink.fancybox({
				autoScale : false,
				centerOnScroll : true,
				content : "<a id='flowplayer-container' href='" + theLink.attr('href') + "' style='display: block; height: 540px; width: 960px;'></a>",
				height : 540,
				margin : 0,
				padding : 0,
				overlayColor : '#000',
				overlayOpacity : 0.8,
				titleShow : false,
				width : 960,
				onComplete : function () {
					flowplayer('flowplayer-container', base_url + 'js/flowplayer-3.1.5.swf', {
						clip: {
							autoPlay : true, 
							autoBuffering : true,
							onFinish : function () {
								location.href = redirectTo;
							}
						}
					});
				}
			});
		};
		setupVideoPlayer('#enterprise-video', 'http://www.cloudswitch.com/page/enterprise-trial-registration');
		setupVideoPlayer('#explorer-video', 'https://www.cloudswitch.com/page/cloudswitch-enterprise-registration');
	}


	
		if ( $('#intro-video').length ) {

		 var reDirect = function (redirectTo)
                 {
			location.href = 'http://www.cloudswitch.com/page/enterprise-cloud-computing-product-overview';
                 }

		var setupVideoPlayer = function (selector, redirectTo) {
			var theLink = $(selector);
			var theRedirTimeout ;

			theLink.fancybox({
				autoScale : false,
				centerOnScroll : true,
				content : "<a id='flowplayer-container' href='" + theLink.attr('href') + "' style='display: block; height: 540px; width: 960px;'></a>",
				height : 540,
				margin : 0,
				padding : 0,
				overlayColor : '#000',
				overlayOpacity : 0.8,
				titleShow : false,
				width : 960,
				onComplete : function () {
					flowplayer('flowplayer-container', base_url + 'js/flowplayer-3.1.5.swf', {
						clip: {
							autoPlay : true, 
							autoBuffering : true,
						        onStart : function () { clearTimeout(theRedirTimeout); },	
							onFinish : function () {
							 theRedirTimeout = setTimeout(function () {reDirect(redirectTo)},4000);	
							}
						}
					});
				}
			});
		};
		setupVideoPlayer('#intro-video', 'http://www.cloudswitch.com/page/enterprise-cloud-computing-product-overview');
	}

	
	//Setup form field with default value
	function setFieldValue(id,value){
		$('#'+id).val(value).focus(function(){
			if( $(this).val() == value)
				$(this).val('');
		}).blur(function(){
			if( $(this).val() == '')
				$(this).val(value);
		});
	}
	
	//Add table stripes
	if ( $('table.styled').length ) {
		$('table.styled tbody tr:nth-child(even)').css('backgroundColor','#EEE');
	}
	
	//Fix IE
	if( $.browser.msie && parseFloat($.browser.version) < 9.0 ){
		if ( $('#sidebar-menu').length )
			$('#sidebar-menu li:last').css('border','none');
	}
	
});

