/******************************************************************************
*  Alternate messaging & cookie check
*******************************************************************************/
function checkZumaMessage(){
	// TO SHOW A CUSTOM ALERT MESSAGE:
	// 	1) Set "var showCustomMessage" to (1)
	// 	2) Change "var zuma_message_content" to a new DATE
	// 	3) In index.xsl edit div#fb_message_custom with new content
	//
	// TO SHOW DEFAULT MESSAGE
	//  Set variable to (2)
	
	var showCustomMessage=2;						
	var zuma_message_content = 052909; 
	
	// If "1", Show Custom Message & Cookie Check
	var zuma_message = $.cookie('zuma_message');
	if (showCustomMessage == 1) {
		// If cookie equals zuma_message_content then show Default
		if (zuma_message == zuma_message_content) {
			$('#fb_message_default').css("display","block");
			$('#fb_message_custom').css("display","none");
			$('#fb_message_basic').css("display","none");
		}
		else{
		// If cookie does not equal zuma_message_content then 
		// set the cookie and show custom message
			$.cookie('zuma_message', zuma_message_content , { path: '/' });
			$('#fb_message_default').css("display","none");
			$('#fb_message_custom').css("display","block");
			$('#fb_message_basic').css("display","none");
		}
	}
	// If "2", Show Default Message
	if (showCustomMessage == 2){
			$('#fb_message_default').css("display","block");
			$('#fb_message_custom').css("display","none");
			$('#fb_message_basic').css("display","none");
	}
}


/******************************************************************************
*  FANCY TOOLTIPS
*******************************************************************************/
$(function() {
	$('a.medalTooltip').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		fade: 250
	});
});


/******************************************************************************
*  PRELOAD & SWAP MEDAL IMAGES
*******************************************************************************/
jQuery.preloadImages = function() {
	for(var i = 0; i<arguments.length; i++) {
		jQuery("<img>").attr("src", arguments[i]);
	}
};
$.preloadImages("../images/zuma-medal-15-mo.png", "../images/zuma-medal-25-mo.png", "../images/zuma-medal-50-mo.png", "../images/zuma-medal-75-mo.png", "../images/zuma-medal-100-mo.png", "../images/zuma-medal-115-mo.png", "../images/zuma-medal-130-mo.png");
      
function swapMedal(imgID){
	$("#" + imgID + "Link").attr("class", "tooltip");
	$("#" + imgID + "Link").attr("href", "javascript:starMedalFeed(" + imgID + ");");
	$("#" + imgID + "Link").attr("title", "");
	$("#" + imgID).attr("src", "../images/zuma-medal-" + imgID + "-color.png");
	$("#" + imgID).attr("class", "rollover");
}

function swapLifetimeMedal(imgID){
	$("#" + imgID + "millionLink").attr("class", "tooltip");
	$("#" + imgID + "millionLink").attr("href", "javascript:lifetimeStarMedalFeed(" + imgID + ");");
	$("#" + imgID + "millionLink").attr("title", "");
	$("#" + imgID + "million").attr("src", "../images/zuma-medal-" + imgID + "million-color.png");
	$("#" + imgID + "million").attr("class", "rollover");
}


/******************************************************************************
*  MEDAL ROLLOVERS
*******************************************************************************/
$(function(){
	// set up rollover
	$("img.rollover").hover(
		function(){
			this.src = this.src.replace("-color","-mo");
		},
		function(){
			this.src = this.src.replace("-mo","-color");
	});
});



/******************************************************************************
* REFRESH LIFETIME SCORE
*******************************************************************************/
function refreshLifetimeScore(newLifetimeScore){
	$("#trophyLifetime").html(newLifetimeScore);
	$("#trophyLifetime").attr("id", "trophyLifetimeHighlight");
}


/******************************************************************************
*  SCROLL TO TOP OF PAGE
*******************************************************************************/
function scrollToTop(){
	scrollTo(0,0);
}


/******************************************************************************
*  CHECK FOR FLASH PLUGIN
*******************************************************************************/
function getFlashVersion(){
 // ie
 try {
   try {
     // avoid fp6 minor version lookup issues
     // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
     var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
     try { axo.AllowScriptAccess = 'always'; }
     catch(e) { return '6,0,0'; }
   } catch(e) {}
   return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g,
',').match(/^,?(.+),?$/)[1];
 // other browsers
 } catch(e) {
   try {
     if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
       return (navigator.plugins["Shockwave Flash 2.0"] ||
navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g,
",").match(/^,?(.+),?$/)[1];
     }
   } catch(e) {}
 }
 return '0,0,0';
}

function checkFlash(){
	var version = getFlashVersion().split(',').shift();
	if(version < 9){
		// If no plugin, show install message
 		document.write('<div id="getflash"><img src="../images/noflash-zuma.gif" border="0" align="left" width="160" height="115" />To play Zuma online, you need the Adobe Flash Player.<br /><br /><a target="_blank" href="http://get.adobe.com/flashplayer/">Click here to install the Flash Player from Adobe.com</a>.<br /><br />It only takes a minute!<div class="clearfloat"></div></div>');
	}else{
		// If yes plugin, show the game
		thePopCapGame.write();
		theAdSpot.write();
		if (theAdSpot.canRunAsPreroll()) theAdSpot.runAsPreroll();
	}
}

/******************************************************************************
*  SWAP FBLOGIN LINK AND SHOW JQUERY PROMPT 
*******************************************************************************/
function swapLoginLink(){
	$(".fblogin").attr("href", "javascript:openprompt();");
}

function revertLoginLink(){
	$(".fblogin").attr("href", "index.php?login=1");
}

// Popup Alert for non-logged in users
function openprompt(){
	scrollToTop();
	$.prompt('<p>Logging in with Facebook will end the current game without saving your score. <b>Do you want to continue?</b></p>',{ 
	buttons: { 'Yes, Connect with Facebook!': true, Cancel: false },
	submit:function(v,m){ 
		 if(!v) return true;
               else
               window.location='index.php?login=1'
              return false; 
		 } });	
	}

