$(function() {
	
	//var html = $("html");
	var o = $("#overlay");
	var s = $("#spotlight");
	var so = $("#spotlight-overlay");
	var cs = $("#close-spotlight");
	
	//Close horizontal spotlight 
	$("div.horizontal_spotlight_close").click(function() {
		$.post('/hide_horizontal_spotlight', {}, function(){});
		$(this).parent().hide();
	})
	
	//Functionality on spotlight near bottom of dashboard, campaign page
	$("a.spotlight_video").click(function(event) {
		//hide other flash
		$("div.campaign_video_wrapper").css("visibility", "hidden");
		
		event.preventDefault();
		var video_link_part = $(this).attr("rel");
		var video_host = '';
		
		if (video_link_part.indexOf("youtube") != -1) {
			video_host = 'youtube';
			if (video_link_part.indexOf("&") != -1) {
				video_link_part = video_link_part.substr(0, video_link_part.indexOf("&")+1);
			}
			video_link_part = video_link_part.split("=");
			video_link = 'http://www.youtube.com/v/'+video_link_part[1]+'?rel=0';
		} else if (video_link_part.indexOf("vimeo") != -1) {
			video_host = 'vimeo';
			video_link = video_link_part.replace('http://www.vimeo.com/','').replace('http://vimeo.com/','');
		}
		
		if (video_host == 'youtube') {
			s.html('<object width="480" height="385"><param name="movie" value="'+video_link+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+video_link+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>');
		} else {
			s.html('<object width="480" height="385"><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id='+video_link+'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" />	<embed src="http://vimeo.com/moogaloop.swf?clip_id='+video_link+'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="480" height="385"></embed></object>');
		}
		
		o.css("display", "inline");
		so.fadeIn(400).css("top", (($(window).height() - so.outerHeight())/2) + (!$.support.cssFloat ? document.documentElement.scrollTop : 
		self.pageYOffset));
		
		
		return false;
	});
	
	//Close pop up video spotlight
	cs.click(function() {
		so.fadeOut(500);
		o.hide();
		s.html("");
		//show other flash
		$("div.campaign_video_wrapper").css("visibility", "visible");
	})
	
	o.click(function(){
		if (so.css("display") == 'block') {
			cs.trigger('click');
		}
	})
});