	/* *******************************************************************************
	* Global variables declaration
	******************************************************************************* */
	var currentPageNumber = 0;//The current visible text page
	var urlVariable = null; //Will hold the URL variable
	var urlSource = "source" //The URL varible name to pass to the links
	var textPagesCount = 0; //The total text box pages count
	var isLink = false;
	var userLeftWindow = false;
	var xsellTimer = null;
	
	// Mansion Brands objects  
	// Contains data on each of the three brands: casino.com, lesacasino.com mansioncasino.com
	var mansionBrands = {
			cc:{
				homepage:"http://act.casino.com/redirect/5913/",
				download:"http://act.casino.com/redirect/5914/",
				classAtt:"cc_download"
			},
			mc:{
				homepage:"http://act.mansioncasino.com/redirect/5917/",
				download:"http://act.mansioncasino.com/redirect/5918/",
				classAtt:"mc_download"
			},
			lc:{
				homepage:"http://act.lesacasino.com/redirect/5919/",
				download:"http://act.lesacasino.com/redirect/5920/",
				classAtt:"lc_download"
			}
	}
	
	/* *******************************************************************************
	* Initializing all script
	******************************************************************************* */
	function init(){
		//Start image slider
        startSliderCycle();
		
        //Start main text box navigation logic
		textPagesCount = $('.why_mansion_text_block').children('div').size(); //get the text pages count
		$('.why_mansion_pages').empty().append((currentPageNumber+1)+"/"+textPagesCount);//Update pages on page
		$('.navigate_right_button').click(function(){textBoxNavigation("right")});
		$('.navigate_left_button').click(function(){textBoxNavigation("left")});
		textBoxNavigation();
		
		//Open xsell popup window
		$(window).unload(function(){
			if(!isLink){
				on_unload();
			}
		});
		$(document).mousemove(function(e){
			if(e.pageY < 10){
				if(!userLeftWindow){
					showXsell();
				}
			} else {
				userLeftWindow = false;
				clearTimeout(xsellTimer);
				xsellTimer = null;
			}
		});
		
		//Append URL variable to link url
		urlVariable = getURLSource(getUrlVars());
		updateDownloadLinks();
		
		//Start Download
		var linkClasses = "." + mansionBrands.cc.classAtt + 
		", ." + mansionBrands.lc.classAtt + 
		", ." + mansionBrands.mc.classAtt;
		$(linkClasses).click(function(){startDownload(this)});
		
		//Capture all click events
		$("*").click(function(){
				isLink=true;
		})
	}
	
	/* *******************************************************************************
	* Start scripts when page loads (jQuery function)
	******************************************************************************* */
    $(document).ready(function(){
        init();
		updateDateSpan();
    });
	
	/* *******************************************************************************
	* Why Mansion text page switch											
	******************************************************************************* */
	function textBoxNavigation(navDirection) {	
		switch(navDirection) {
			case "right":
				if(currentPageNumber <( textPagesCount -1)){
					currentPageNumber++;	
				} 
				break;
			case "left":
				if(currentPageNumber > 0){
					currentPageNumber--;				
				}
				break;
		}
		displayTextBox(currentPageNumber);
		displayTextBoxTitle(currentPageNumber);
		$('.why_mansion_pages').empty().append((currentPageNumber+1)+"/"+textPagesCount);//Update pages on page
	}
	
	//Display a text box page title by index number
	function displayTextBoxTitle(textIndex){
		$('.why_mansion_title > h3').each(function(index){
			if(index == textIndex){
				$(this).fadeIn();
			 }else {
				$(this).hide();
			}
		});
	}
	//Display a text box page by index number
	function displayTextBox(textIndex){
		$('.why_mansion_text_block > div').each(function(index){
			if(index == textIndex){
				$(this).fadeIn();
			 }else {
				$(this).hide();
			}
		});
	}
	
    /* *******************************************************************************
    * Homepage Box Slider - only HOMEPAGE 
    ******************************************************************************* */
	function startSliderCycle() {
		$('#image_slider ul').cycle({
            delay: 1000,
            speed: 500,
            sync: 1,
            timeout: 4000,
            pager: '.main-banner-dots'
        });
        $('#image_slider .main-banner-dots a').click(function () {
            var curDots = $('#main-banner .main-banner .main-banner-dots a').index(curDots);
            stopAnim($(this).index(curDots) + 1);
            return false;
        });
	}
    function startSlide(theBox, theSpeed) {
        var $theSlideBox = '#' + theBox + ' ul';
        var $theSpeed = theSpeed
        $($theSlideBox).cycle({
            delay: -3500,
            speed: 500,
            sync: 1,
            timeout: $theSpeed
        });
    };
    
    function stopSlide(theBox) {
        var $theSlideBox = '#' + theBox + ' ul';
        $($theSlideBox).cycle('destroy');
    };
    
    function stopAnim(item) {
        var curItem = item;
        $('#main-banner ul li').removeClass('active last-active');
        $('#main-banner .main-banner-dots a').removeClass('active last-active');
        $('#main-banner ul li:nth-child(' + curItem + ')').addClass('active');
        $('#main-banner .main-banner-dots a:nth-child(' + curItem + ')').addClass('active');
    };
	
	/* *******************************************************************************
    * Attach variabels to site links href value
    ******************************************************************************* */
	// Get the selected URL variable from the created URL object: return a string value  
	function getURLSource(obj){
		var urlString = "";
		if(typeof obj != 'undefined'){
			for(key in obj){
				if(key == urlSource) {
					urlString += "usource:" + obj[key];
				}
			}
			return urlString;
		}else {
			return "";
		}
	}
	//Append the download links with the selected URL variable
	function updateDownloadLinks() {
		if(urlVariable !=""){
			for(key in mansionBrands) {
				mansionBrands[key].homepage += urlVariable;
				mansionBrands[key].download += urlVariable;
			}
		}
	}
	
	/* *******************************************************************************
	* Read a page's GET URL variables and return them as an associative array.     
	******************************************************************************* */
	function getUrlVars()
	{
		var vars = [], hash;
		if(window.location.href.indexOf("?") != -1){
			var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
			for(var i = 0; i < hashes.length; i++)
			{
				hash = hashes[i].split('=');
				vars.push(hash[0]);
				vars[hash[0]] = hash[1];
			}
			if (typeof vars[0] != 'undefined') {
				return vars;
			} else {
				return {};	
			}
		}else {
			return {};	
		}
	}
	
	/* *******************************************************************************
	* Start download and redirect to brand homepage                                                        
	******************************************************************************* */
	function startDownload(selectedLink){
		var linkClass = $(selectedLink).attr('class');
		for(key in mansionBrands) {
			if(linkClass.match(mansionBrands[key].classAtt)){
				window.location = mansionBrands[key].homepage;
				window.open(mansionBrands[key].download,"DownloadWindow","width=250, height=10");
			}
		}
	}
	
	/* *******************************************************************************
	* Xsell popup window                                                          
	******************************************************************************* */
	var isLink = false;
	function on_unload() {
		if (isLink) {
			return false;
		} else {
			var msg = 'Would you like to visit another casino?';
	
			if (confirm(msg)) {
				var visitWin = window.open('http://www.mansion.com/xsell/', "visitWin");
				if (visitWin == null) {
					document.location.href = 'http://www.mansion.com/xsell/';
				}
			}
	
			return true;
		}
	}
	function showXsell(){
		if(!userLeftWindow) {
			xsellTimer = setTimeout('on_unload()',1500);
			userLeftWindow = true;
		}
	}
	
	//Date wrapper logic
	var Days=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];var Months=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
	function addLeadingZero(value) {
    if (value < 10) {
        return '0' + value;
    } else {
        return value;
    }
	}
	function getAMPM(value) {
		return (value >= 12) ? "PM" : "AM";
	}
	function cutHoursToAMPM(value) {
		return (value == 12 || value == 0) ? 12 : value % 12;
	}
	function updateDateSpan() {
		//var dateSpan = document.getElementById('dateContainer');
		var $dateSpan = $('.date_container');
		
		/*if ($dateSpan) {*/
			var date = new Date();
			$dateSpan.empty().append(Days[date.getUTCDay()] + ", " +
								 Months[date.getUTCMonth()] + " " +
								 addLeadingZero(date.getUTCDate()) + ", " +
								 addLeadingZero(date.getUTCFullYear()) + " - " +
								 cutHoursToAMPM(date.getUTCHours()) + ":" +
								 addLeadingZero(date.getUTCMinutes()) + " " + getAMPM(date.getUTCHours()) + " GMT");
		/*}*/
		setTimeout("updateDateSpan();", 1000);
	}
