/*
# $Id$
*/

/*
# Init
*/
$(document).ready(function() {

	// Embed all video assets
	$('.lead-video div').each(function() {

		// Gather video/image sources
		var container = $(this);
		var vSrc = container.find('input').val();
		var iSrc = container.find('img').attr('src');

		// Embed SWF
		if(vSrc.match(/\.swf$/)) {
			swfobject.embedSWF(
				vSrc,
				container.attr('id'),
				"545",
				"340",
				"9.0.0",
				"/swf/expressInstall.swf", {
				}, {
					menu: "false",
					allowfullscreen: "true",
					allowscriptaccess: "always",
					wmode: "transparent"
				},{
				}
			);
		}
		else {
			swfobject.embedSWF(
				"/swf/flvplayer.swf?r=151",
				container.attr('id'),
				"545",
				"340",
				"9.0.0",
				"/swf/expressInstall.swf", {
					file: vSrc,
					image: iSrc
				}, {
					menu: "false",
					allowfullscreen: "true",
					allowscriptaccess: "always",
					wmode: "transparent"
				},{
					'class': 'flvplayer'
				}
			);
		}
	});

	// If Advice Channels are present, add handlers
	if($('#advice-channels')) {

		// Add handlers to tabs
		$('#advice-channels ul.channel-tabs li a').click(function() {
			openAdviceChannel(this.href.toString().replace(/^.*#+channel\-/, ''));
			return false;
		});

		// Open the tab currently defined in the URL, or choose the "email" tab
		// by default
		var channel = 'email';
		if(self.location.hash.toString().match(/#([a-z\-]+)$/)) {
			var m = self.location.hash.toString().match(/#([a-z\-]+)$/);
			channel = m[1].replace(/^channel\-/i, '');
		}
		openAdviceChannel(channel);
	}
});

function openAdviceChannel(c) {
	$('#advice-channels div.channel-summary').each(function(i, el) {
		el = $(el);
		el.css('display', el.attr('rel')=='channel-'+c ? 'block' : 'none');
	});
}