// inject Presenters and Spinners on the the page in the named div
function updatePresentersAndSpinners() {
	$.get('/resource/client/presentersAndSpinners/html.php?rnd='+Math.random(), {}, function(argHtml){$('#communityAreaPresenterAndSpinner').html(argHtml);});
}

$(document).ready(function() {		   	
	initialize();

	//update the Player Presenter area in the lobby on first load and then refresh every minute
	updatePresentersAndSpinners();
	setInterval(updatePresentersAndSpinners, 300000); // refresh every 5 minutes
});


function initialize() {
	
	$('.default-value').each(function() {
    var default_value = this.value;
    $(this).focus(function() {
        if(this.value == default_value) {
            this.value = '';
        }
    });
    $(this).blur(function() {
        if(this.value == '') {
            this.value = default_value;
        }
    });
	
});

	
	
	
	tabs();
	faq();

	
	
	$('#loginForm').corner("12px");
	
	// rightCont tabs
	rTabContainers = $('#rightCont div.tabs .tabsContent > div');
    rTabContainers.hide().filter(':first').show();
	
	
	$(document).ready(function() {	
	onlineGamesTabs();
	onlineGamesSlider();

	//liveGamesSlider();
	mobileGamesSlider();
	
	flashPresenters();
	
	flashTicker();
							   });
	

	/* rightCont tabs */
	$('#rightCont div.tabs ul li a').click(function() {
		rightContTabs(this); 
		return false;
	}).filter(':first').click();
	
	
	/* main menu */
	$('ul#menu>li').hover(
		function() { showMenu(this); }, 
		function() { hideMenu(this); }
	);	
	
	/* need help */
	$('.needHelp').click(toggleHelp);
	
	/* live games tooltip */
	$('ul#liveGames li').hover(function() {
		el = this;
		showTooltip(el);
	},function() {
		hideTooltip();
	});
	
		$('ul#liveGames li a.more').click(function() {
		el = this;
		showTooltip(el);
	},function() {
		hideTooltip();
	});		
		
	$(".modalPopUp").colorbox({iframe:true, innerWidth:680, innerHeight:522});	
	
/*	if(document.getElementById("ticker")){
	jQuery.fn.extend({
	everyTime: function(interval, label, fn, times, belay) {
		return this.each(function() {
			jQuery.timer.add(this, interval, label, fn, times, belay);
		});
	},
	oneTime: function(interval, label, fn) {
		return this.each(function() {
			jQuery.timer.add(this, interval, label, fn, 1);
		});
	},
	stopTime: function(label, fn) {
		return this.each(function() {
			jQuery.timer.remove(this, label, fn);
		});
	}
});

jQuery.event.special

jQuery.extend({
	timer: {
		global: [],
		guid: 1,
		dataKey: "jQuery.timer",
		regex: /^([0-9]+(?:\.[0-9]*)?)\s*(.*s)?$/,
		powers: {
			// Yeah this is major overkill...
			'ms': 1,
			'cs': 10,
			'ds': 100,
			's': 1000,
			'das': 10000,
			'hs': 100000,
			'ks': 1000000
		},
		timeParse: function(value) {
			if (value == undefined || value == null)
				return null;
			var result = this.regex.exec(jQuery.trim(value.toString()));
			if (result[2]) {
				var num = parseFloat(result[1]);
				var mult = this.powers[result[2]] || 1;
				return num * mult;
			} else {
				return value;
			}
		},
		add: function(element, interval, label, fn, times, belay) {
			var counter = 0;
			
			if (jQuery.isFunction(label)) {
				if (!times) 
					times = fn;
				fn = label;
				label = interval;
			}
			
			interval = jQuery.timer.timeParse(interval);

			if (typeof interval != 'number' || isNaN(interval) || interval <= 0)
				return;

			if (times && times.constructor != Number) {
				belay = !!times;
				times = 0;
			}
			
			times = times || 0;
			belay = belay || false;
			
			var timers = jQuery.data(element, this.dataKey) || jQuery.data(element, this.dataKey, {});
			
			if (!timers[label])
				timers[label] = {};
			
			fn.timerID = fn.timerID || this.guid++;
			
			var handler = function() {
				if (belay && this.inProgress) 
					return;
				this.inProgress = true;
				if ((++counter > times && times !== 0) || fn.call(element, counter) === false)
					jQuery.timer.remove(element, label, fn);
				this.inProgress = false;
			};
			
			handler.timerID = fn.timerID;
			
			if (!timers[label][fn.timerID])
				timers[label][fn.timerID] = window.setInterval(handler,interval);
			
			this.global.push( element );
			
		},
		remove: function(element, label, fn) {
			var timers = jQuery.data(element, this.dataKey), ret;
			
			if ( timers ) {
				
				if (!label) {
					for ( label in timers )
						this.remove(element, label, fn);
				} else if ( timers[label] ) {
					if ( fn ) {
						if ( fn.timerID ) {
							window.clearInterval(timers[label][fn.timerID]);
							delete timers[label][fn.timerID];
						}
					} else {
						for ( var fn in timers[label] ) {
							window.clearInterval(timers[label][fn]);
							delete timers[label][fn];
						}
					}
					
					for ( ret in timers[label] ) break;
					if ( !ret ) {
						ret = null;
						delete timers[label];
					}
				}
				
				for ( ret in timers ) break;
				if ( !ret ) 
					jQuery.removeData(element, this.dataKey);
			}
		}
	}
});

jQuery(window).bind("unload", function() {
	jQuery.each(jQuery.timer.global, function(index, item) {
		jQuery.timer.remove(item);
	});
});	
	n=0;
	$("#ticker").everyTime(7000, function(){	
		if(n == 1) {
			$("#DTicker").fadeOut(700,  function(){
												 $("#BTicker").fadeIn(1900);
												 n=0;
												 });
			
			
        }
		else{
			$("#BTicker").fadeOut(700, function(){
												 $("#DTicker").fadeIn(1900);
												 n=1;
												 });
			
			
		}
    		
	});	
	
	}*/
}


/* ---------------------------------------------------------------------------------------------------------------------- */


function generateTooltip(type) {
	if ( type === "live" )
		html = "<div id=\"lTooltip\"><div class=\"inner\"></div><img class=\"arrow\" src=\"images/tooltipTick.png\" /></div>";
	if ( type === "online" ) 
		html = "<div id=\"oTooltip\"><div class=\"inner\"></div><img class=\"arrow\" src=\"images/tooltipTick.png\" /></div>";
	$(html).appendTo('body');
}


function showMenu(el) { 

	submenu = $(el).find('ul');	
	$(el).addClass('hovered'); 
	if (typeof (submenu) != 'undefined') {
		$(submenu).fadeIn(200); 
	}
	
}


function hideMenu(el) { 

	$(el).removeClass('hovered'); 
	if (typeof (submenu) != 'undefined') {
		$(submenu).hide();
	}
}

function toggleHelp() { 

	$('.helpCenter ul.helpLinks').toggle('slideDown'); 
	
}

	



function showTooltip(el) {
	
	$('ul#liveGames li').not(el).css('opacity','0.3');
		
	elPos = $(el).position();
		
	posX = elPos.left;
	posY = elPos.top - $('.tooltip', el).height()-27;			
				
	$('.tooltip', el)
		.stop()
		.appendTo($(el))
		.css({'top':posY,'left':posX})
		.show()
		.animate({
			marginTop: '10',
			queue:true
		}
	,200);

}


function hideTooltip(type) {

	$('ul#liveGames li').css('opacity','1');
	$('.tooltip').stop().css({display:'none',marginTop: -10});
	
}

	
function generateTabContent() {

	oTabContainers = $('#online .tabsContent > div');	
	
}

	
function onlineGamesTabs() {

	generateTabContent();
					
	$('#online .tabs > ul li a').not('.selected').click(function() {
		
		oTabContainers.hide();
		tab = oTabContainers.filter(this.hash);		
		if (tab.html()) 
			tab.fadeIn();
		else {
			var divName = this.hash;
			divName = divName.substr(1);
			$('<div id="'+divName+'" class="gamesList">Loading..</div>').appendTo('#leftCont .tabsContent');
			$('#'+divName+'').load(''+divName+'.tpl').fadeIn(500);
			generateTabContent();
		}		
		$('#online .tabs > ul li a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	}).filter(':first').click();
	

}

	
function onlineGamesSlider() {

	$("#table").easySlider({
			controlsBefore:	'<p id="controls">',
			controlsAfter:	'</p>',
			pause: 8000,
			auto: true,
			continuous: true
	});
	$('#controls').appendTo('#table ul');
	
}

function tabs() {

	$('#pageDivide div.tabbed .tabsContent > div').not(':first').hide();
	$('#pageDivide div.tabbed ul li a').click(function() {
		el = this;
		
		$('#pageDivide div.tabbed .tabsContent > div').hide();
		$('#pageDivide div.tabbed .tabsContent > div').filter(el.hash).fadeIn();
		$('#pageDivide div.tabbed ul li a').removeClass('selected');
		$(el).addClass('selected');
		return false;
	});
	

}

function faq() {
	$('#pageDivide .faq li p').hide();
	$('#pageDivide .faq li').click(function() {
		$(this).find('p').slideToggle();
	});
}

//function liveGamesSlider() {

	//$("#liveGameScroll").easySlider({
		//controlsBefore:	'<p id="controls2">',
		//controlsAfter:	'</p>',	
		//prevId: 'prevBtn2',
		//nextId: 'nextBtn2'	
	//});
	//$('#controls2').appendTo('#liveG');
	
//}

function mobileGamesSlider() {

	$("#mobileGameScroll").easySlider({
		controlsBefore:	'<p id="controls7">',
		controlsAfter:	'</p>',	
		prevId: 'prevBtn7',
		nextId: 'nextBtn7'	
	});
	$('#controls7').appendTo('#mobileG');
	
}

function flashPresenters() {
					// changed . to %2E get around object/embed problem with xml. 
					//(tmpStr = tmpStr.replace(/\./g,"%2E");) this method only works in ie
					var tmpStr =		document.location.protocol+'//assets.supercasino.com/flashPromo/promotions.swf?configPath='+document.location.protocol+'//assets.supercasino.com/flashPromo/&configName1=menuItems2%2Exml';
					$('#fPromotions').flash({ 

					src: tmpStr,


					width: 249,
					height: 312,
					version: 10,
					wmode: 'opaque',
					allowScriptAccess: 'always'
				});						
					$('#flashPresenters').flash({ 

					src: document.location.protocol+'//assets.supercasino.com/presenters/Menu_pub.swf',

					width: 600,
					height: 460,
					version: 10,
					wmode: 'opaque'
				});				
					$('#LiveRouletteBroadcast').flash({ 

					src: document.location.protocol+'//assets.supercasino.com/broadcast/LR.swf',

					width: 600,
					height: 500,
					version: 10,
					wmode: 'opaque'
				});	
					
					$('#AutoWheelBroadcast').flash({ 

					src: document.location.protocol+'//assets.supercasino.com/broadcast/Autowheel.swf',

					width: 600,
					height: 500,
					version: 10,
					wmode: 'opaque'
				});	
					$('#LiveRouletteVidBut').flash({ 

					src: document.location.protocol+'//assets.supercasino.com/vidButtons/LiveVidBut.swf',

					width: 182,
					height: 98,
					version: 10,
					wmode: 'opaque'
				});
					$('#AutowheelVidBut').flash({ 

					src: document.location.protocol+'//assets.supercasino.com/vidButtons/AutoVidBut.swf',

					width: 182,
					height: 98,
					version: 10,
					wmode: 'opaque'
				});	
				$('#TvVidBut').flash({ 

					src: document.location.protocol+'//assets.supercasino.com/vidButtons/TvVidBut.swf',

					width: 182,
					height: 98,
					version: 10,
					wmode: 'opaque'
				});	
					var tmpStr =  document.location.protocol+'//assets.supercasino.com/promoHomeBig/Promo_Widget_xml_SC.swf?configPath='+document.location.protocol+'//assets.supercasino.com/promoHomeBig/&configName1=SC_PromoOddMonths%2Exml&configName2=SC_PromoEvenMonths%2Exml';
					$('#promotionsArea').flash({ 
					
					src:tmpStr,

					width: 683,
					height: 263,
					version: 9,
					wmode: 'opaque',
					allowScriptAccess: 'always'
				});	
				$('#joinVid').flash({ 

					src: document.location.protocol+'//assets.supercasino.com/vidButtons/join.swf',

					width: 246,
					height: 231,
					version: 9,
					wmode: 'opaque'
				});				
			
}
function flashTicker()
	{
	xmlLocation = document.location.protocol+'//'+document.location.hostname + '/resource/client/xml/SCTickerValues%2Exml.php';
	
	var tmpStr =	document.location.protocol+'//assets.supercasino.com/ticker/SuperCasinoJackpot.swf?configPath='+xmlLocation;	
	$('#ticker').flash({ 
			
		src: tmpStr,
	
		width: 952,
		height: 51,
		version: 10,
		wmode: 'opaque'
	});		
}

function openGameInfo(url)
{
	window.open(url, "game", "status=0,toolbar=0,location=0,menubar=0,resizable=0,scrollbars=1,height=500,width=645");
}



/*************Added by Ian Leggett 17/05/10**********************/
$(document).ready(function() {
	
	/********************************************************************************************************************
	SIMPLE ACCORDIAN STYLE MENU FUNCTION
	********************************************************************************************************************/	
	$('h3.accordionButton').click(function() {
		$('div.accordionContent').slideUp('normal');	
		$(this).next().slideDown('normal');
	});
	
	/********************************************************************************************************************
	CLOSES ALL DIVS ON PAGE LOAD
	********************************************************************************************************************/	
	$("div.accordionContent").hide();

});



