function Site(){
	//nom du menu courant
	this._menu=null;
	//nom de la tab courante
	this._selectedTab = null;
	//noms des tabs affichees
	this._tabs = [];
	//urls des pages du menu/tab courant
	this._pagesURL = [];
	//numero de la page affichee
	this._pagesURLindex = 0;
	
	this._lastAction = "";
	this._picsURL=[];
	
	this.menuClic = function(menuItem){
		this._lastAction = "menuClic";
		if (menuItem != this._menu){
			dojo.xhrPost({
           		url: 'actions/getText.php5',
           		load: dojo.hitch(this,this._handleServerResponse),
           		content:{menu:menuItem}
        	});
        	this._menu = menuItem;
        	this._pagesURLindex = 0;
		}
	}
	
	this.tabClic = function(tabItem){
		this._lastAction = "tabClic";
		this._pagesURLindex = 0;
		if (tabItem != this._selectedTab){
			dojo.xhrPost({
           		url: 'actions/getText.php5',
           		load: dojo.hitch(this,this._handleServerResponse),
           		content:{menu:this._menu,tab:tabItem}
        	});
        	this._selectedTab = tabItem;
		}
	}
		
	this.next = function(){
		if (dojo.style("next","opacity")>0)
			this._change_page(1);
	}

	this.previous = function(){
		if (dojo.style("previous","opacity")>0)
			this._change_page(-1);
	}
	
	this._change_page = function (value){
		this._pagesURLindex+=value;
		this._lastAction="clic";
		dojo.xhrPost({
           		url: 'actions/getText.php5',
           		load: dojo.hitch(this,this._changeText),
           		content:{url:this._pagesURL[this._pagesURLindex],pn:(this._pagesURLindex+1)}
        	});
        	//dojo.byId("pages").innerHTML = "<p>"+(this._pagesURLindex+1)+"/"+this._pagesURL.length+"</p>";
	}
	
	this._hide_button = function (button,duration){
		dojo.style("button","cursor","default");
		dojo.fadeOut({ 
	    				node: button,
	    				duration : duration 
	    			    }).play();
	}
	
	this._show_button = function(button,duration){
		dojo.style("button","cursor","pointer");
		dojo.fadeIn({ 
	    				node: button,
	    				duration : duration 
	    			    }).play();
	} 
	
	this._handleServerResponse = function (response){
		var response = eval('(' + response + ')');
		this._pagesURL = response.text;
		this._picsURL = response.pic;
		if ((this._lastAction=="menuClic")){
			if (this._tabs.length>0){
				this._closeTabs();
				if(response.tabs.length>0){
					delay = function (){
						this._openTabs(response.tabs);
					};
					window.setTimeout(dojo.hitch(this,delay),1200);					
				}
			}
			else {
				this._openTabs(response.tabs);
			}
		}
		dojo.xhrPost({
           		url: 'actions/getText.php5',
           		load: dojo.hitch(this,this._changeText),
           		content:{url:response.text[this._pagesURLindex]},
           		sync:true
        });
	}

	this._changeText = function(newText){
		var node = "text";
		var duration = 500;
		var buttons = "buttons";
		var previous = "previous";
		var next = "next";
		var pages = "pages";
		var pictures ="";
		
		//if (this._pagesURL.length>1)		
		//	dojo.byId(pages).innerHTML = "<p>"+(this._pagesURLindex+1)+"/"+this._pagesURL.length+"</p>";
		
		//derniere page, on affiche ls photos si y en a
		if  (this._pagesURLindex == this._pagesURL.length-1){
			if (this._picsURL.length>0){
				
				var group = ""+this._menu+this._selectedTab;

				pictures += '<br/><center><a href="'+this._picsURL[0].replace("/homez.183/stoopidb/www/","http://stoopidbox.com/")+'"'+
                                        'class="displayImage"'+
                                        'dojoType="dojox.image.Lightbox"'+
                                        'group="'+group+'">'+                                        
                                        'Voir les photos'+
                                        '</a></center>';
				
								
				var i=1;
				for (i=1;i<this._picsURL.length;i++){
					pictures += '<a href="'+this._picsURL[i].replace("/homez.183/stoopidb/www/","http://stoopidbox.com/")+'"'+
                                        'dojoType="dojox.image.Lightbox"'+
                                        'group="'+group+'"'+
                                        'style="display:none;"'+
                                        'title="'+i+'">'+
                                        this._picsURL[i]+
                                        '</a>';
				}
			}
		}
		

  		var anim = dojo.fadeOut({ 
	    				node: node,
	    				duration : duration 
	    			    });	    

		dojo.connect(anim,"onEnd",function(){
			dojo.byId(node).innerHTML = newText+'<BR/>'+pictures;
			dojo.parser.parse(node);
			dojo.fadeIn({ node:node, duration:duration }).play();
	    });	    
		anim.play();

		if(this._pagesURLindex>0){
			dojo.style(previous,"cursor","pointer");
			dojo.fadeIn({ 
	    				node: previous,
	    				duration : duration 
	    			    }).play();
	    		/*dojo.fadeIn({ 
	    				node: pages,
	    				duration : duration 
	    			    }).play();
			*/
		}		
		else{
			dojo.style(previous,"cursor","default");
			dojo.fadeOut({ 
	    				node: previous,
	    				duration : duration 
	    			    }).play();
		}
						
		if(this._pagesURLindex<(this._pagesURL.length-1)){
			dojo.style(next,"cursor","pointer");
			dojo.fadeIn({ 
	    				node: next,
	    				duration : duration 
	    			    }).play();
	    		/*dojo.fadeIn({ 
	    				node: pages,
	    				duration : duration 
	    			    }).play();
			*/
		}				
		else{
			dojo.style(next,"cursor","default");
			dojo.fadeOut({ 
	    				node: next,
	    				duration : duration 
	    			    }).play();
		}
		if(this._pagesURL.length ==1)
			dojo.fadeOut({ 
	    				node: buttons,
	    				duration : duration 
	    			    }).play();
	    else {
	    	dojo.fadeIn({ 
	    				node: buttons,
	    				duration : duration 
	    			    }).play();
	    	/*dojo.fadeIn({ 
	    				node: pages,
	    				duration : duration 
	    			    }).play();
	        */
	    }
	    
	    //dojo.parser.parse(node);
	    
	}
	
	this._createTabs = function(tabs){
		var content = "";
		var i = 0;
		for( i = 0; i<tabs.length;i++) {
			var tab = tabs[i];
			content+='<div class="tab" id="'+tab+'" onclick=site.tabClic("'+tab+'")><div class="tabText" id="'+tab+'Text">'+tab.replace(/_/g,' ')+'</div></div>';	
		}
		dojo.byId("tabs").innerHTML= content;
	}
	
	this._openTabs = function(tabs){				
		this._createTabs(tabs);
		this._tabs = tabs;
		
		var i = 0;
		for( i = 0; i<tabs.length;i++) {
			var tab = tabs[i];
			var fadeOut = dojo.fadeOut({node:tab+"Text",duration:100});
			fadeOut.play();
		}
			
	    var anim = 
    		dojo.animateProperty({
  				node:"tabs",
  				duration : 500,
  				properties: {
    				width: { end:150, unit:"px" }
  				}
  			});
  		anim.play();  	
  	
		var i = 0;
		for( i = 0; i<tabs.length;i++) {
			var tab = tabs[i];
    		var etirement = 
    			dojo.animateProperty({
  					node:tab,
	  				duration : 500,
  					easing: dojo.fx.easing.quadOut,
  					properties: {
      					width: { end:130, unit:"px" },
      					borderWidth: {end:1, unit:"px"}
	  				}
  				});
  					
  			var fadeIn = dojo.fadeIn({ node:tab+"Text", duration:600 });
	  		dojo.fx.chain([etirement, fadeIn]).play();
	  		dojo.style(tab,"cursor","pointer");
 		}				
	}
	
	this._closeTabs = function(){
	    if (this._tabs != []){
		    
		    var anim = 
    			dojo.animateProperty({
  						node:"tabs",
  						duration : 500,
  						properties: {
    							     width: { end:0, unit:"px" }
  							    }
    					     });
  		
  			var i = 0;
			for( i = 0; i<this._tabs.length;i++) {
				var tab = this._tabs[i];
        		var retrecicement = 
        			dojo.animateProperty({
  							node:tab,
  							duration : 500,
  							easing: dojo.fx.easing.quadIn,
  							properties: {
      							width: { end:0, unit:"px" },
      							borderWidth: {end:0, unit:"px"}
  							}
  					});
  				dojo.style(tab+"Text","cursor","default");
  				var fadeOut = dojo.fadeOut({ node:tab+"Text", duration:600 });
  				dojo.fx.chain([fadeOut, retrecicement ]).play();
    		}
    		anim.play();    		
    		this._tabs = [];
	    }
	}
		
}

