// ================================
// = AV and AV Fail Tag Functions =
// ================================

function avtag() {
	trackPage('pagename=2009 Miller Lite Latino AV: Home,channel=2009 Miller Lite Latino AV');
}

function avfailtag() {
	trackPage('pagename=2009 Miller Lite Latino AV: Fail,channel=2009 Miller Lite Latino AV');
}

// ============================
// = On Content Load Function =
// ============================

function initPage() {
	// Add swfobject code here or any other scripts that need to be run onload.
	var flashvars = {};
	var flashparams = {};
	var flashattributes = {};
	
	//flashvars.luid = FrontendFramework.luid;
	flashvars.config = 'data/sys_config.xml';
	flashvars.sourceID = 'LLH';
	//flashvars.firstEntryURL = 'http://dev.emipromo.com/enjoythelites/register/process.php'; //Stage
	//flashvars.reEntryURL = 'http://dev.emipromo.com/enjoythelites/register/process2.php'; //Stage
	flashvars.firstEntryURL = 'https://secure.emipowered.com/millerbeer/enjoythelites/register/process.php'; //Live
	flashvars.reEntryURL = 'https://secure.emipowered.com/millerbeer/enjoythelites/register/process2.php'; //Live
	flashparams.quality = 'high';
	flashparams.wmode = 'opaque';
	flashparams.base = '.'
	flashparams.align = 'TL';
	flashparams.allowScriptAccess = 'always';
	flashparams.scale = 'showall';
	flashparams.menu = 'false';
	
	swfobject.embedSWF('main.swf', 'content', '100%', '100%', '9.0.0', 'expressInstall.swf', flashvars, flashparams, flashattributes);
}

// =======================
// = Sweeps Registration =
// =======================

var formLanguage = 'en';

function launchSweepsEN() {
	formLanguage = 'en';
	centerDiv('sweepsen');
	$('#sweepsen').show();
	$('#shared_formen').attr('src','http://sharedregistration.millercoors.com/SharedForm.aspx?SourceId=LLS');
	//$('#shared_formen').attr('src','http://millerlitelatino.stage.digitas.com/sweeps_success.html?SourceId=LLS&RESULT=false&MESSAGE=One%20visit%20per%20day');
	$('#sweeps_confirm').css('background','url("images/sweeps_confirm_bkg.png")');
	$('#play_game').css('background','url("images/sweeps_play_game.png")');
	$('#close_confirm').css('background','url("images/sweeps_confirm_close.png")');
}

function launchSweepsES() {
	formLanguage = 'es';
	centerDiv('sweepses');
	$('#sweepses').show();
	$('#shared_formes').attr('src','http://sharedregistration.millercoors.com/SharedForm.aspx?SourceId=LLS&language=spanish');
	$('#sweeps_confirm').css('background','url("images/sweeps_confirm_bkg_es.png")');
	$('#play_game').css('background','url("images/sweeps_play_game_es.png")');
	$('#close_confirm').css('background','url("images/sweeps_confirm_close_es.png")');
}

$(document).ready(function(){
	$("#closeen").bind("click", function(){
		$('#sweepsen').hide();
	});
	
	$("#closees").bind("click", function(){
		$('#sweepses').hide();
	});
	
	$("#close_confirm").bind("click", function(){
		$('#sweeps_confirm').hide();
	});
	
	$("#play_game").bind("click", function(){
		$('#sweeps_confirm').hide();
		document.getElementById('content').javaClick();
	});
});

function sweepsSuccess(status) {
	if(status == 'error') {
		if(formLanguage == 'en') {
			$('#sweeps_confirm').css('background','url("images/sweeps_error_bkg.png")');
			trackPage('pagename=Miller Lite Latino Soccer: Already Entered English,channel=Miller Lite Latino Soccer');
		} else {
			$('#sweeps_confirm').css('background','url("images/sweeps_error_bkg_es.png")');
			trackPage('pagename=Miller Lite Latino Soccer: Already Entered Spanish,channel=Miller Lite Latino Soccer');
		}
	} else {
		if(formLanguage == 'en') {
			trackPage('pagename=Miller Lite Latino Soccer: Confirmation English,channel=Miller Lite Latino Soccer');
		} else {
			trackPage('pagename=Miller Lite Latino Soccer: Confirmation Spanish,channel=Miller Lite Latino Soccer');
		}
	}
	$('#sweepsen').hide();
	$('#sweepses').hide();
	centerDiv('sweeps_confirm');
	$('#sweeps_confirm').show();
}

// ==============
// = Center Div =
// ==============

function centerDiv(div) {
	var div = $('#' + div);
	var height = $(window).height();
	var width = $(document).width();

  div.css({
  	'left' : width/2 - (div.width() / 2),  // half width - half element width
  	'top' : height/2 - (div.height() / 2), // similar
  	'z-index' : 15                        // make sure element is on top
  });
}


// ===============
// = Popup Links =
// ===============

var swfId = "mbc_mainSwf";

function getSwf( id ) 
{
  if ( navigator.appName.indexOf( "Microsoft" ) != -1 ) { return window[ id ]; }
  else { return document[ id ]; }
}

function launchSoccerGame() {
  var name = Math.round( 9999*Math.random( ) ) + new Date( ).getTime( );
  var win = window.open("soccer_game.html","SoccerGame" + name,"toolbar=0,menubar=0,width=1024,height=600,status=0,resizable=0,scrollbars=0" );
  if( !win ) { getSwf(swfId).openWindowFromSwf( "soccer_game.html" ); }
  else { winNew.focus( ); }
}

function launchSoccerRulesEN() {
  // removed mLink.action - as it is not currently working
  var name = Math.round( 9999*Math.random( ) ) + new Date( ).getTime( );
  var win = window.open( "soccer_sweeps_rules_en.html","SoccerRulesEN" + name,"toolbar=0,menubar=0,width=640,height=500,status=0,resizable=1,scrollbars=1" );
  if( !win ) { getSwf( swfId ).openWindowFromSwf( "soccer_sweeps_rules_en.html" ); }
  else { winNew.focus( ); }
}

function launchSoccerRulesES() {
  // removed mLink.action - as it is not currently working
  var name = Math.round( 9999*Math.random( ) ) + new Date( ).getTime( );
  var win = window.open( "soccer_sweeps_rules_es.html","SoccerRulesEN" + name,"toolbar=0,menubar=0,width=640,height=500,status=0,resizable=1,scrollbars=1" );
  if( !win ) { getSwf( swfId ).openWindowFromSwf( "soccer_sweeps_rules_es.html" ); }
  else { winNew.focus( ); }
}

function launchMusicaGame( ) 
{
  // removed mLink.action - as it is not currently working
  var name = Math.round( 9999*Math.random( ) ) + new Date( ).getTime( );
  var win = window.open( "/musicaGame.html","musicaGame" + name,"toolbar=0,menubar=0,width=1050,height=630,status=0,resizable=1,scrollbars=0" );
  if( !win ) { getSwf( swfId ).openWindowFromSwf( "/musicaGame.html" ); }
  else { winNew.focus( ); }
}
function launchFoto( ) 
{
  //alert(" Launch Foto Fired! ");
  var name = Math.round( 9999*Math.random( ) ) + new Date( ).getTime( );
  var win = window.open('http://new.pictureu.com/enter.aspx?batch=MILL&noshow=true',"PictureU" + name,'height=586,width=1005,toolbar=yes,menubar=no,scrollbars=yes');
  if( !win ) { getSwf( swfId ).openWindowFromSwf( 'http://new.pictureu.com/enter.aspx?batch=MILL&noshow=true' ); }
  else { winNew.focus( ); }
}
function launchIluminado( ) 
{
  var name = Math.round( 9999*Math.random( ) ) + new Date( ).getTime( );
  var win = window.open("iluminado.html","FooterLinks" + name,"toolbar=0,menubar=0,width=1020,height=750,status=0,resizable=1,scrollbars=1" );
  if( !win ) { getSwf(swfId).openWindowFromSwf( "iluminado.html" ); }
  else { winNew.focus( ); }
}
