$(document).ready(function() { 
	randomNum = Math.floor(Math.random()*2);
	$('div#random_promo a:eq('+randomNum+')').show();
});


$(function(){

	if( $('#flash').size() == 1 ){
	
		function flashPanel(){
		
			total = $('#flash li').length;
			i = 1;
			c = 1;
			pauseTimer = {};
			autoTimer = {};
			mooseBan = false;
			
			$('#flash li:not(:first)').hide();
			
			$('<div id="flash_nav"/>').prependTo('#flash').css({opacity:0.6});
			
			$('#flash li .slide').each(function(){
				i++;
				
				if( $(this).children('img').length == 0 ){
					$(this).parent('li').data('settings', {flashFile: $(this).text(), url: $(this).attr('href'), pause: $(this).attr('title'), external: $(this).hasClass('external')});
					
					$(this).html('<img src="/flash/homepage/' + $(this).parent('li').data('settings').flashFile + '.jpg" alt=""/>');
				}else{
					$(this).parent('li').data('settings', {flashFile: 'noFlash', url: $(this).attr('href'), pause: $(this).attr('title')});
				}
				
				$(this).removeAttr('title');
				
				$('<a/>', {
					'href'	:	'#',
					'css'	:	{opacity:0.6},
					'click'	:	function(){
						if( mooseBan == true || $(this).hasClass('active') == true ) return false;
						c = $(this).index() + 1;
						loadFlash(c);
						return false;
					}
				}).appendTo('#flash_nav');
				
				if( i == total ) loadFlash(1);
			});
			
			$('#flash_nav a').hover(function(){
				$(this).css({opacity:1});
			},function(){
				if( !$(this).hasClass('active') ) $(this).css({opacity:0.6});
			});
			
			$('#flash').hover(function(){
				$('#flash_nav').stop([]).animate({opacity:1},200);
			},function(){
				$('#flash_nav').stop([]).animate({opacity:0.5},200);
			});
			
			function loadFlash(n){
	
				mooseBan = true;
	
				$.clearTimer(pauseTimer);
				
				$('#flash_nav a:eq(' + ( n - 1 ) + ')').addClass('active').css({opacity:1}).siblings('a').removeClass('active').css({opacity:0.6});
				
				$('#flash .loading').css({display:'block'}).animate({opacity:1},400,function(){
					
					$('#flash li.flash-replaced').removeClass('flash-replaced').empty();
					
					$('#flash .flash_link').remove();
				
					$this = $('#flash li:eq(' + ( n - 1 ) + ')');
					
					$this.show().addClass('active').siblings().removeClass('active').hide();
					
					if( $this.data('settings').url != undefined ){
						$('#flash').prepend('<a href="' + $this.data('settings').url + '" class="flash_link"></a>');
					}
					
					if( $this.data('settings').flashFile != 'noFlash' ){
	
						$this.flash({
							src: '/flash/homepage/' + $this.data('settings').flashFile + '.swf',
							width: 492,
							height: 245,
							wmode:'transparent'
						},{
							update: false
						});
						
						if( $this.hasClass('flash-replaced') == false ) nextFlash();
					
					}else{
						nextFlash();
					}
					
					$('#flash .loading').animate({opacity:0},400,function(){
						$(this).hide();
						mooseBan = false;
					});

					if( $this.data('settings').external == true ){
					
						$('#flash .flash_link').attr('target','_blank');
					
					}
	
				});
				
			}
			
			nextFlash = function(){
				$this = $('#flash li.active');
				
				if( c == total ){
					c = 1;
				}else{
					c++;
				}
				
				p = $this.data('settings').pause;
				
				if( p != 0 ){
					pauseTimer = $.timer(( p * 1000 ), function(){
						$.clearTimer(pauseTimer);
						loadFlash(c);
					});
				}else{
					loadFlash(c);
				}
			}
		}
		
		// Initiate
		flashPanel();
	
	}


// HOMEPAGE FLASH - Only executes on homepage

	$('#header_left').addClass('flash_enabled');
	$('#header_right').addClass('flash_enabled');

	
		/*
$('#flash').flash({
			src: '/flash/reel.swf',
			width: 492,
			height: 245,
			wmode: 'transparent'
		});
*/
		
		/*$('#header_left').flash({
			src: '/flash/speaker.swf',
			width: 500,
			height: 169,
			wmode: 'transparent'
		});*/
		
		$('#header_right').flash({
			src: '/flash/tshirt.swf',
			width: 268,
			height: 169,
			wmode: 'transparent'
		});

});


function speakerGrow(){
	$('div#header_left').css({width: 500});
}
function speakerShrink(){
	$('div#header_left').css({width: 218});
}

function homeHover(){
	$('ul#navigation .home').addClass('homeon');
}
function homeOff(){
	$('ul#navigation .home').removeClass('homeon');
}
function contactHover(){
	$('ul#navigation .contact').addClass('contacton');
}
function contactOff(){
	$('ul#navigation .contact').removeClass('contacton');
}

function shopPopup(){
	window.open('http://www.mojobar.co.uk/ecomcart/list.php','popup','width=560,height=500,scrollbars=yes');
}

function radioPopup(){
	window.open('http://www.mojobar.co.uk/popup/','popup','width=311,height=390');
}
