 // JavaScript Document


window.onload =function (){

	mainMenu();
	crearMenu();
	

}
var actived=false;

function mainMenu(){
	var option=$$("#menu ul li");

	option.each(function (opc){
		  
			opc.onmouseover = function(){

				var navRoot=this.childNodes;
				new PeriodicalExecuter(function (clear){
												
													if(!actived) {
														
														 for(var i =0 ; i<navRoot.length; i++){
															node = navRoot[i];
																if (node.nodeName=="UL") {
																	node.className=node.className.replace("over", "");
																} 
														 }
													clear.stop();
													actived=false;  
													}else{
														var ended=false;
														for(var i =0 ; i<navRoot.length; i++){
															node = navRoot[i];
																if (node.nodeName=="UL") {
																	if(node.className==""){
																		ended=true;
																	}
																} 
														 }
														 if(ended){
															 clear.stop();
															 actived=false;
														 }
													}

												 }, 2);
				
				for(var i =0 ; i<navRoot.length; i++){
					node = navRoot[i];
					if (node.nodeName=="UL") {
							node.className="over";
							node.onmouseover=function() {
								actived=true;
								this.className="over";
							}
						  	node.onmouseout=function() {
						  		this.className=this.className.replace("over", "");
								actived=false;
								
						 	}
							
							
					  }
					
				}
				
				
				
			}

	});
	
}

startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace
	(" over", "");
   }
   }
  }
 }
}

function crearMenu(){
	var opciones= $$(" #submenu ul li a");

	opciones.each(function (opcion){
		opcion.onclick = function(){
			mostrarSeccion(opcion.rel);
				return false;
		}
		
		
	})
	
}

function mostrarSeccion(opcion){

	
		switch (opcion){
		
			case 'galleria-elementos':
				getImages('elementos');
						
				break;
			case 'galleria-novo':
						getImages('novo');
				break;
			case 'galleria-nuhaus':
						getImages('nuhaus');
				break;
			case 'galleria-conchablanca':
						getImages('conchablanca');
				break;
		default:
		
		$("title").innerHTML='<h1 >'+opcion+'</h1>';
			new Ajax.Request(opcion+".php",{
						method:"GET",
						onSuccess: function (transport){
									$("sub-content").innerHTML=transport.responseText;
									
								}
								
						});
			break;
	}

	
}
//---------------galleria
function getImages($gallery){
	
	new Ajax.Request("../../controller/galleria.php",{
						method:"POST",
						parameters:{ gallery: $gallery},
						onSuccess: function (transport){
									
									$values = eval(transport.responseText);

									 var viewer = new PhotoViewer();
										$values.each(function(image){
															  viewer.add('../../imagenes/'+$gallery+'/'+image)});
										viewer.show(0);
											
								}
								
						});
	
}

