// Video player
var player;

// Overlay settings
var overlaySettings = {
	api:true,
	expose:{ 
		color: '#000', 
		loadSpeed: 200, 
		opacity: 0.7
	},

	
	// when overlay is opened, load our player
	onLoad: function(content) {
		player.load();
	},
	
	// when overlay is closed, unload our player
	onClose: function(content) {
		player.unload();
	}
}

function videoClickHandler()
{
	$("#player").attr('href',$(this).attr('href'));
	player = $f("player",{src:"http://altium.com/app_templates/coretemplates/js/flowplayer-commerical/flowplayer.commercial-3.1.5.swf"},{key: '#$0ed0d710dc34053e41d'});
	$("div.overlay").overlay(overlaySettings).load();
	return false;
}

$(function(){
	
	// Append video player to bottom of body
	$("body").append('<div class="overlay"><a class="close">X</a><a id="player" href="#">&nbsp;</a></div>');
	
	// Disable Contibute author mode stylesheet
	$("link[id='authorMode']").remove();
	
	// Init tabs
	$(".tabs").tabs("div.panes > div",{ history: true });
	//$('.tabs a').click(function () {location.hash = $(this).attr('href');}); 
	
	// Init scrollable
	$(".scrollable").scrollable();
	
	// Init inline videos
	$(".carousel .items a").click(videoClickHandler);
	$("a.video").click(videoClickHandler);
	
	// Append all URL variables to iframe urls
	$('iframe').each(function()
	{
		var urlVars = window.location.href.split("?")[1];
		if(urlVars) $(this).attr('src',$(this).attr('src') + "?" + urlVars);
	});
	
	// Make summary boxes clickable
	$('.summary a').each(function(){
		$(this).closest('.box.').attr('rel',$(this).attr('href')).css('cursor','pointer');
		$(this).closest('.box.').click(function(){
			window.location.href = $(this).attr('rel');
		});
	});
	
});
