﻿var dompath = (document.location.href.indexOf("staging") != -1) ? "lonestarhdgame-staging.internationaltrucks.com/" : "lonestarhdgame.internationaltrucks.com/";

var LoneStarHDGame = new function LoneStarHDGameObj() {
    var _this = this;
    this.closed = true;
    this.getH = function() { if (typeof (window.innerHeight) == 'number') { return window.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { return document.documentElement.clientHeight; } else if (document.body && document.body.clientHeight) { return document.body.clientHeight; } return 0; };
    this.getW = function() { if (typeof (window.innerWidth) == 'number') { return window.innerWidth; } else if (document.documentElement && document.documentElement.clientWidth) { return document.documentElement.clientWidth; } else if (document.body && document.body.clientWidth) { return document.body.clientWidth; } return 0; };
    this.getT = function() { return (((_this.getH() - 495) / 2) + $("body").scrollTop()) > 110 ? ((_this.getH() - 495) / 2) + $("body").scrollTop() : 110; };
    this.getL = function() { return ((_this.getW() - 800) / 2); };
    this.adjust = function() {
        if (!$.support.cssFloat)
            $("#loneStarHDGameBox").css({ top: _this.getT(), left: _this.getL() });
        else
            $("#loneStarHDGameBox").animate({ top: _this.getT(), left: _this.getL() }, 100);
    };
    this.open = function(highscores) {
        if (_this.closed) {
            _this.closed = false;

            $(window).bind("resize", LoneStarHDGame.adjust);
            $("body").css({ overflow: 'hidden' });
            $("body").append('<div id="configWashout">&nbsp;</div>');
            $("body").append('<div id="loneStarHDGameBox">'
						+ '<div style="text-align:right;padding:3px;"><a href="javascript:LoneStarHDGame.close()">Close</a></div>'
						+ '<iframe src="http://' + dompath + '/game.html?highscores=' + highscores + '&dompath=' + escape(dompath) + '" width="800" height="470" frameborder="0" scrolling="no"></iframe>'
						+ '</div>');
            $("#configWashout, #loneStarHDGameBox").css({ position: "absolute", top: "0", left: "0", opacity: "0", filter: "alpha(opacity=0)" });
            $("#configWashout").css({ backgroundColor: "#000000", width: "970px", height: $("#all").height() + "px", zIndex: "100" });
            $("#loneStarHDGameBox").css({ border: "2px solid #ffffff", top: _this.getT() + "px", left: _this.getL() + "px", width: "800px", height: "495px", zIndex: "200", textAlign: "center", backgroundColor: "white", fontFamily: "arial", fontSize: "12px", color: "black" });

            $("#configWashout").fadeTo(500, .6, function() {
                $("#loneStarHDGameBox").fadeTo(500, 1);
            });


        }
    };
    this.close = function() {
        $("#loneStarHDGameBox").fadeTo(500, 0, function() {
        $("#loneStarHDGameBox").fadeTo(500, 0, function() { _this.closed = true; $("#configWashout").remove(); $("#loneStarHDGameBox").remove(); $(window).unbind("resize", LoneStarHDGame.adjust); $("body").css({ overflow: 'auto' }); });
        });
    };
}




$(function() {
    var img = $('<img usemap="#loneStarHDGameMap" src="http://' + dompath + 'assets/loneHD_game.jpg" style="border:none" />');
    var map = $('<map name="loneStarHDGameMap"><area shape="rect" coords="505,225,590,256" href="javascript:LoneStarHDGame.open(false)" alt="Play" /><area shape="rect" coords="505,260,660,280" href="javascript:LoneStarHDGame.open(true)" alt="Highscores" /></map>');
    $("#loneStarHDGame").after(img).after(map);
	
	if(getQueryVariable('game'))
		LoneStarHDGame.open(false);		
});