//var dir="http://www.remedia-solutions.com/clientes/0049_rodak/public_html/nuevo"
//Direccion base de toda la raiz
var dir="http://www.rodak.com.mx"

var posx=0;
var tiempo1;
var nue=0;
var retro=0;
var tim;
var notas;
var kip=0;

function gup( name ){ //Obtener valores get de la url
	var url = window.location.href;
		cad="";
		a="";
		for(ki=1;ki<=url.length;ki++){
			a=url.charAt(url.length-ki);			
			if(a=="/"){
				break;
			}
			cad=a+cad;
		}
	return cad;
}
//-------------------------------------------------
function shadow(wit,hei,vent){
	//calcular media de la ventana	
	ancho=wit;
	$(".ventana").css('left','50%');
	$(".ventana").css('margin','40px 0px 0px -'+(wit/2)+'px');
	$(".cont").css('margin','40px 0px 0px '+(wit/2)+'px');
	$("#fond-shadow").fadeTo(400,0.8,function(){
		$(".cont").css('display','block');
		$(".ventana").animate({width:wit,height:hei},300,function(){												   
			$(".ventana").html('<iframe width="100%" scrolling="no" height="100%" frameborder="0" marginheight="0" marginwidth="0" src="'+vent+'"></iframe>');
		});
	  });	
}
//-------------------------------------------------
function mueveCaja(){
	if(nue<=posx){
		nue+=(posx-nue)/6;	
		if(posx-nue<0.001){clearInterval(tiempo1);}
	}
	if(posx<nue){
		nue-=(nue-posx)/6;	
		if(nue-posx<0.001){clearInterval(tiempo1);}
	}
	$(".cuad").css('left',nue);	
}
//Si el documento esta cargado
$(document).ready(function(){
	$("#fond-shadow").css('opacity','0');
	$("#fond-shadow,.cont").click(function(){
		$(".ventana").html('<iframe width="100%" scrolling="no" height="100%" frameborder="0" marginheight="0" marginwidth="0" src="" allowtransparency="allowtransparency"></iframe>');
		$(".ventana").animate({width:10,height:10},200,function(){
			$(".ventana").css('display','none')
			$(".cont").css('display','none');
			$("#fond-shadow").fadeTo(200,0,function(){$("#fond-shadow").css('display','none')});
		});
	});
	$(".ventana").css('background-color','transparent');
	if(gup('seccion')=='nosotros'){$(".cuad").css('left','333px');nue=333;}
	if(gup('seccion')=='productos'){$(".cuad").css('left','415px');nue=415;}
	if(gup('seccion')=='contacto'){$(".cuad").css('left','502px');nue=502;}
	if(gup('seccion')=='ubicacion'){$(".cuad").css('left','582px');nue=582;}
	$(".cuad").fadeTo(400,1);
	/*clearInterval(tiempo1);
	tiempo1=setInterval(mueveCaja,40);*/
	if((gup('seccion')=='')||((gup('seccion')=='inicio'))){$(".cuad").css('display','none');}
	
	// Clic en logo
	$("#logo img").click(function(){$(".cuad").fadeTo(400,0,function(){document.location=dir+"";});});
	$(".texProductos:eq(0)").css('display','block');
	
	$(".aver").click(function(){
		$.post('http://www.remedia-solutions.com/clientes/0049_rodak/public_html/nuevo/enviando2.php',
			{ nombre: document.getElementById("nombre").value,	
			  correo: document.getElementById("correo").value,
			  tel: document.getElementById("tel").value,
			  empre: document.getElementById("empre").value,
			  comenta: document.getElementById("comenta").value	
			},
			function(datos) {
				//tratar datos resividos
				$(".respuesta").html(datos);
				$('.respuesta').css('display','block');
				if(datos=="Enviado"){
					 document.getElementById("nombre").value=""	
					 document.getElementById("correo").value=""	
					 document.getElementById("tel").value=""	
					 document.getElementById("empre").value=""	
					 document.getElementById("comenta").value=""					  
				}
				setTimeout("$('.respuesta').css('display','none');",2000);
  		});		
	});
	/**********************************
		Codigo de menu
		***********************************/
				
		$(".texMenu").each(function(i){
			  $(this).mouseenter(function(e){
					clearInterval(tiempo1);					  
			  		if(i==0){posx=333;}
					if(i==1){posx=415;}
					if(i==2){posx=502;}
					if(i==3){posx=582;}
					tiempo1=setInterval(mueveCaja,40);
			  });
			  $(this).click(function(evento){
					$(".cuad").fadeTo(400,0,function(){
						if(i==0){document.location=dir+"/nosotros"}//Marcas
						if(i==1){document.location=dir+"/productos"}//Prensa
						if(i==2){document.location=dir+"/contacto"}//contacto
						if(i==3){document.location=dir+"/ubicacion"}//twitter
					});
					evento.preventDefault();
			  });
		});
	/************************************
		Codigo de inicio
		**************************************/		
		$(".sonaMenu").mouseenter(function(){
			$(".cuad").fadeTo(400,1);
		});
		$("#conten").mouseenter(function(){
			if((gup('seccion')=='')||((gup('seccion')=='inicio'))){$(".cuad").fadeTo(400,0);}		
		clearInterval(tiempo1);
		if(gup('seccion')=='nosotros'){posx=333;}
		if(gup('seccion')=='productos'){posx=415;}
		if(gup('seccion')=='contacto'){posx=502;}
		if(gup('seccion')=='ubicacion'){posx=582;}		
		tiempo1=setInterval(mueveCaja,40);
		});
		
		////////////
		$(".opm").each(function(i){
				/*$(this).mouseenter(function(){
					$(".opm:eq("+i+")").css('background-color','#f1f2f3');						
				});
				$(this).mouseout(function(){
					$(".opm:eq("+i+")").css('background-color','#E4E7E8');						
				});*/
				$(this).click(function(){
					$(".texProductos").css('display','none');
					$(".opm").css('background-color','#E4E7E8');
					$(".opm:eq("+i+")").css('background-color','#ccc');
					$(".texProductos:eq("+(i+1)+")").css('display','block');					
				});		  
		});
		$(".bot1").mouseenter(function(){
			clearInterval(vali);			
		});
		$(".bot1:eq(0)").click(function(){//Atras
			if(kip>0){kip--;$("#slideshow2 IMG:eq("+(24-kip)+")").css('opacity','1.0');}							
		});
		$(".bot1:eq(1)").click(function(){//Adelante
			if(kip<24){$("#slideshow2 IMG:eq("+(24-kip)+")").css('opacity','0');kip++;}
		});
		$(".bot1").mouseout(function(){
			vali=setInterval( "slideSwitch2()", 2500 );
		});		
		
		////////////////////////////////////////
		
		
});
function cargo(){
	$('.carga').fadeTo(300,0,function(){
		$('.carga').css('display','none')
		 setInterval( "slideSwitch()", 3000 );
		 vali=setInterval( "slideSwitch2()", 2500 );		 		 
	})
}
window.onload=function(){//Cuando carge el documento entero     
	 cargo();
}
