var Loader = {
    stopBanners : false,
    waitTime : 0,
    totalWaitTime : 100,

    waitUntilLoaded: function() {
        this.waitTime = Loader.waitTime + 1;
        var loaded = parseInt(Loader.waitTime/Loader.totalWaitTime*100)

        $("#game_banner_percent").text(loaded).show();
        $("#game_banner_progress").css("width", loaded+"%");

        if(this.stopBanners)
        {
            return;
        }
        else if(loaded >= 100 || Loader.waitTime >= Loader.totalWaitTime)
        {
            this.skipBanners();
            return;
        }
        else
        {
            setTimeout('Loader.waitUntilLoaded()',100);
        }

    },

 
    skipBanners: function() {
        Loader.stopBanners = true;
        $("#game_banner").html("");
        $("#game_banner").hide();
        
        if(navigator.appName.indexOf("Microsoft Internet")==-1){
            $("#zoom_bar").show();
        }
          $("#gameHolder").css('visibility', 'visible');
    },

    loadFlashFile: function(gameurl, type){
        var objName = 'gameobj';
        var embedType = "type='application/x-shockwave-flash'";
        if(type == 'dcr')
        {
            embedType = "type='application/x-director' pluginspage='http://www.macromedia.com/shockwave/download/'";
        }
        
        var gameHTML = '<embed src="'+gameurl+'" '+
        embedType +
        ' name="'+objName+'" id="'+objName+'" allowfullscreen="true"  width="930" height="700" style="margin-top: 0px; margin-left: auto; margin-right; auto;"  allownetworking="internal" playerversion="11"></embed>'

        
        $("#gameHolder").css('visibility', 'hidden');
        $("#gameHolder").html(gameHTML);

        $("#zoom_bar").hide();
        Loader.waitUntilLoaded();
    }

}

var Zooomer = {
    max : 202,
    size: 25,
    gameWidth: 930,
    gameHeight: 700,
    maxGameWidth : 0,
    ratio: 0,
    start: 0,
    active : false,
    actualPos: 0,

    init: function() {
        Zooomer.ratio = Zooomer.gameHeight/Zooomer.gameWidth;
        Zooomer.maxGameWidth = parseInt($(document).width())-150;
        Zooomer.actualPos = parseInt((Zooomer.max-Zooomer.size)*Zooomer.gameWidth/Zooomer.maxGameWidth);
        $("#zooomer").css('margin-left', Zooomer.actualPos+'px');
        $("#zooomer").bind('mousedown', Zooomer.mouseDown);
        $(document).bind('mouseup', Zooomer.mouseUp);
        $(document).bind('mousemove', Zooomer.mouseMove);
        
    },

    mouseDown: function(e) {
        Zooomer.active = true;
        Zooomer.start = document.all ? window.event.clientX : e.pageX ;
    },

    mouseUp: function(e) {
        if(Zooomer.active)
        {
            Zooomer.active = false;
        }
    },

    mouseMove: function(e) {
        if(Zooomer.active)
        {
            var x = document.all ? window.event.clientX : e.pageX ;
            
            var newPos = Zooomer.actualPos-(Zooomer.start-x);
            if(newPos<0) newPos = 0;
            if(newPos>Zooomer.max-Zooomer.size) newPos = Zooomer.max-Zooomer.size;

            Zooomer.gameWidth = parseInt(Zooomer.maxGameWidth * newPos/(Zooomer.max-Zooomer.size));
            //console.log("zoomer gameWidth: "+ Zooomer.gameWidth);
            Zooomer.gameHeight = parseInt(Zooomer.ratio * Zooomer.gameWidth);
            Zooomer.actualPos = newPos;
            Zooomer.start = x;
            $('#zooomer').css('margin-left', Zooomer.actualPos+'px');

            $('#gameobj').css('width', Zooomer.gameWidth);
            $('#gameobj').css('height', Zooomer.gameHeight);
            
            $('#gameobj').css('margin-left', parseInt((680-Zooomer.gameWidth)/2)+'px');
        }
    }
}



