/* ----------------------------------------------------------------------------------------------------*/
// Functions required as soon as the page loads
/* ----------------------------------------------------------------------------------------------------*/
$(document).ready(function(){
	
	// Ini ShadowBox
	Shadowbox.init();
	
	// Ini ie6 PNG fix
	//$(document).pngFix();
	$('img[@src$=.png]').ifixpng(); 

	/* Add Flash
	/* ------------------------------------------------------------------*/
	$('.index #mainFlash').flash({
		src: 'flash/featured_shows.swf',
		width: 657,
		height: 443
	});	
	$('.whats_on #mainFlash').flash({
		src: 'flash/whats_on.swf',
		width: 657,
		height: 680
	});

	
	/* Fix the column heights
	/* ------------------------------------------------------------------*/
	function fixCols(){
	   $("div#contentMain").height($("div#innerWrapper").height());
	}	
	fixCols();

	/* Capture mouse clicks for style sheet changing
	/* ------------------------------------------------------------------*/
	$('.styleswitch').click(function()
	{
			switchStylestyle(this.getAttribute("rel"));
			return false;
	});

	/* Capture mouse clicks for main Flash changing
	/* ------------------------------------------------------------------*/
	$('.hideFlash').click(function(event) {
		event.preventDefault();		
		
		var flashTarget = "#" + this.getAttribute("rel");
		var fallbackTarget = "#" + this.getAttribute("title");
		
		$(flashTarget).fadeOut("fast", function(){
			$(fallbackTarget).fadeIn("fast", function(){
				fixCols();
			});
		});
	});	
	$('a.showFlash').click(function(event) {
		event.preventDefault();		
		
		var flashTarget = "#" + this.getAttribute("rel");
		var fallbackTarget = "#" + this.getAttribute("title");
		
		$(fallbackTarget).fadeOut("fast", function(){
			$(flashTarget).fadeIn("fast", function(){
				fixCols();
			});
		});
	});	
	
	/* Show Text replacements
	/* ------------------------------------------------------------------*/
	$('a.mb_TheTeam').click(function(event) {
		event.preventDefault();		
		$("#mb_ShowInfo").hide(1, function(){
			$("#mb_TheTeam").show(1, function(){
				fixCols();
				$('#showFlash')[0].flashGotoSection("ShowImg");				
			});
		});
	});		   	   
	
	$('a.mb_ShowInfo').click(function(event) {
		event.preventDefault();		
		$("#mb_TheTeam").hide(1, function(){
			$("#mb_ShowInfo").show(1, function(){
				fixCols();
			});
		});												
	});
	
	/* Show Flash replacements
	/* ------------------------------------------------------------------*/	
	$('a.m_podcasts').click(function(event) {
		$('#showFlash')[0].flashGotoSection("ShowMp3s");
	});	
	
	$('a.m_video').click(function(event) {
		$('#showFlash')[0].flashGotoSection("ShowVideo");
	});	
	
	
	/* ReadCookies
	/* ------------------------------------------------------------------*/	
	var c = readCookie('style');
	if (c) switchStylestyle(c);	
		
	
});

/* ----------------------------------------------------------------------------------------------------*/
/* Functions to run on user interaction
/* ----------------------------------------------------------------------------------------------------*/

// Hide the colomns if style sheet is clean
/* ------------------------------------------------------------------*/
function hideCols(){
   $("div#leftColumn").hide();
   $("div#rightColumn").hide();
}

// Show the colomns if style sheet is dirty
/* ------------------------------------------------------------------*/
function showCols(){
   $("div#leftColumn").show(0);
   $("div#rightColumn").show(0);
}

// Switch style sheet
/* ------------------------------------------------------------------*/
function switchStylestyle(styleName)
{
		if(styleName == "style_clean"){
			hideCols();	
		} else { 
			showCols();
		}
		$('link[@rel*=style][@title]').each(function(i)
        {
                this.disabled = true;
                if (this.getAttribute('title') == styleName) this.disabled = false;
        });		
        createCookie('style', styleName, 365);
}


// cookie functions http://www.quirksmode.org/js/cookies.html
/* ------------------------------------------------------------------*/
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
// /cookie functions

window.onload = function(){
    
};

Shadowbox.loadSkin('classic', 'src/skin');
Shadowbox.loadLanguage('en', 'src/lang');
Shadowbox.loadPlayer(['flv', 'html', 'iframe', 'img', 'qt', 'swf', 'wmp'], 'src/player');

