function myGameObject(){
    this.selectedClass = 'seleted';
    this.currentId = 1;
    this.contentPre = 'my_game_';
    this.navPre = 'my_g_nav_';
}
myGameObject.prototype.$ = function(id){
    return typeof(id)=='string'?document.getElementById(id):id;
}
myGameObject.prototype.changeNav = function(id){
    if ( id == this.currentId ){
        return;
    }
    var preC = this.$(this.contentPre + this.currentId);
    var preN = this.$(this.navPre + this.currentId);
    var curC = this.$(this.contentPre + id);
    var curN = this.$(this.navPre + id);
    
    // hide
    preC.style.display = 'none';
    preN.className = '';
    
    //show
    curC.style.display = 'block';
    curN.className = this.selectedClass;
    this.currentId = id;
}
var myGame = new myGameObject();

function gameToogle(id){
    this.object = this.$(id);
    this.prox=null;
	this.proy=null;
	this.proxc=null;
	this.proyc=null;
	this.timer = null;
	
	this.interval = 10; // 毫秒数
	
	this.width = 1000;
	this.height = 86;
}
gameToogle.prototype.$ = function(id){
    return typeof(id)=='string'?document.getElementById(id):id;
}
gameToogle.prototype.show = function(){/*--打开--*/
    var obj= this;
    if ( obj.object.style.display == 'none' ){
        clearInterval(obj.prox);
        clearInterval(obj.proy);
        clearInterval(obj.proxc);
        clearInterval(obj.proyc);
        var o = obj.object;
        o.style.display = "block";
        Cookies.set('nav_state', 1);
        $('my_game_toogle').className = "seleted";
//                o.style.width = "1px";
        o.style.height = "1px"; 
        
        obj.prox = setInterval(function(){obj.openx()},obj.interval);
    }
}
gameToogle.prototype.openx = function(){
    var obj = this;
    var o = obj.object;
    var cx = parseInt(o.style.width);
	if(cx < obj.width){
		o.style.width = (cx + Math.ceil((obj.width-cx)/5)) +"px";
	}else{
		clearInterval(obj.prox);
		obj.proy = setInterval(function(){obj.openy()},obj.interval);
	}
}
gameToogle.prototype.openy = function(){
    var obj = this;
    var o =obj.object;
    
    var cy = parseInt(o.style.height);
    if(cy < obj.height){
        o.style.height = (cy + Math.ceil((obj.height-cy)/5)) +"px";
       
    }else{
        clearInterval(obj.proy);
    }
 }
 gameToogle.prototype.close = function(){
    var obj= this;
    clearInterval(obj.prox);
    clearInterval(obj.proy);
    clearInterval(obj.proxc);
    clearInterval(obj.proyc);
    Cookies.set('nav_state', 0);
    var o = obj.object;
    if(o.style.display != "none")
    {
        obj.proyc = setInterval(function(){obj.closey()},obj.interval);	
        
    }		
 }
 gameToogle.prototype.closex = function(){
     var obj = this;
     var o = obj.object;
    var cx = parseInt(o.style.width);
	if(cx > 0){
		o.style.width = (cx - Math.ceil(cx/5)) +"px";
	}else{
		clearInterval(obj.proxc);
		o.style.display = "none";
		$('my_game_toogle').className = "";
	}
 }
 gameToogle.prototype.closey = function(){
    var obj = this;
    var o = obj.object;
    var cy = parseInt(o.offsetHeight);
    if(cy > 0){
        o.style.height = (cy - Math.ceil(cy/5)) +"px";
    }else{
        clearInterval(obj.proyc);				
        obj.proxc = setInterval(function(){obj.closex()},obj.interval);
    }
 }
 var gToogle = new gameToogle('myGames');
 function toggleGame(){
     if ( arguments.length == 0 ){
         var obj = gToogle.object;
         if ( obj.style.display == 'none' ){
             gToogle.show();
         }else{
             gToogle.close();
         }
     }else{
         var t = arguments[0];
         if ( t == 'show' ){
             gToogle.show();
         }else if(t == 'close'){
             gToogle.close();
         }
     }
 }
//             (function(){
//                 gToogle.timer = setTimeout(function(){gToogle.close();}, 5000);
//                 // 注册事件
//                 var my_t = document.getElementById('my_game_toogle');
//                 var my_game = document.getElementById('myGames');
//                 if ( window.addEventListener ){
//                     my_t.addEventListener('mouseover', function(){if(gToogle.timer){clearTimeout(gToogle.timer);}},false);
//                     my_game.addEventListener('mouseover', function(){if(gToogle.timer){clearTimeout(gToogle.timer);}},false);
//                     my_t.addEventListener('mouseout', function(){if(gToogle.timer){clearTimeout(gToogle.timer);}},false);
//                     my_game.addEventListener('mouseout', function(){if(gToogle.timer){clearTimeout(gToogle.timer);}},false);
//                 }else if( window.attachEvent){
//                     my_t.attachEvent('onmouseover', function(){if(gToogle.timer){clearTimeout(gToogle.timer);}});
//                     my_game.attachEvent('onmouseover', function(){if(gToogle.timer){clearTimeout(gToogle.timer);}});
//                     my_t.attachEvent('onmouseout', function(){if(gToogle.timer){clearTimeout(gToogle.timer);}});
//                     my_game.attachEvent('onmouseout', function(){if(gToogle.timer){clearTimeout(gToogle.timer);}});
//                 }else{
//                     
//                 }
//             })();