/*function mainmenu(){
    $(" #menu1 ul ").css({
        display: "none"
    });
    $(" #menu1 li").hover(function(){
        $(this).find('ul:first:hidden').css({
            visibility: "visible",
            display: "none"
        }).slideDown(800);
    }, function(){
    		$(this).find('ul:first').slideUp(800);
    });
}*/

function mainmenu(){
    $(" #menu1 ul ").css({
        display: "none"
    });
    $(" #menu1 li").mouseenter(function(){
	        $(this).find('ul:first:hidden').css({
	            visibility: "visible",
	            display: "none"
	        }).slideDown(800);
    });
    $(" #menu1 li ").mouseleave(function(){
    	var elobjeto =  $(this).find('ul:first');
    	var laposiciones = elobjeto.css("marginLeft");
    	 elobjeto.animate({marginLeft:laposiciones},1500,function(){
    		 elobjeto.slideUp(800);
    	 });
    });
}

function reintentar(url){
            $('#contenedor').fadeOut(500, function() {
            	$(this).load(url + ' #texto', function(){
                $(this).fadeIn(1000);
            	});
            });
}
function ingreso () {
	$('#contenedor').fadeOut(500, function() {
		$(this).load('/login.php', {
            user: $('#user').val(),
            password: $('#pass').val()
        }, function(){
            $(this).fadeIn(1000);
        });
	});
}
function salir() {
	$('#contenedor').fadeOut(500, function() {
		$(this).load('/salir.php', function(){
            $(this).fadeIn(1000);
        });
	});
}
var elintervalo = 0;
$(document).ready(function (){
    mainmenu();
	var banderita = 0;
	url = window.location;
	/*$("#loading1").css("height","0px");*/
	$("#loading2").css("width","0px");
	/*$('#loading1').animate({height:'360px'},1000);*/
	$('#mas-img').animate({left:'798px'},1500);
	$('#loading2').animate({width:'800px'},1500);
	if(url != "http://www.grupodeo.com.mx/index.php"){
		window.open("http://www.grupodeo.com.mx/index.php","_self");
	}
	if(url == "http://www.grupodeo.com.mx/index.php" || url == "http://www.grupodeo.com.mx/" || url == "http://www.grupodeo.com.mx" || url == "http://www.grupodeo.com.mx/deo/inicio.html" || url == "http://grupodeo.com.mx/deo/inicio.html" || url == "http://grupodeo.com.mx" || url == "http://www.grupodeo.com.mx/" || url == "http://www.grupodeo.com.mx/index.php"){
		/*$('#texto').flash({
		    src: '/UserFiles/flash/introdeo.swf',
		    width: 750,
		    height: 400,
		    wmode: 'transparent'
		});*/
			animacionintro();
		/*$('#texto').hide().fadeIn(1000);*/
	}
    $('#textoscroll').jScrollPane({scrollbarWidth : 1});
    $('#menu2 a').click(function(){
    	clearInterval(elintervalo);
		var bandera = 0;
    	var liga = $(this).attr("href");
		if(banderita == 100){
			clearTimeout(mosaico);
			banderita = 0;
		}
		if (liga != "javascript:void('');") {
    	$('#mas-img').fadeOut(500); $("#loading2").fadeOut(500, function(){
    		//alert("Hola");
    		/*$("#loading1").css("height","0px");*/
    		$("#loading2").css("width","0px");
            	$('#texto').fadeOut(500, function(){
            		//$('#contenedor').hide(500, function(){
            			$(this).load(liga + ' #texto', function(){ 
            				$('#texto').hide();
            				if(liga == "/deo/galeria.html"){
            					$('#texto').css('padding','0px');
            				} else if (liga == "/deo/inicio.html") { 
            					$('#texto').css('padding','0px');
            					/*$('#texto').flash({
            					    src: '/UserFiles/flash/introdeo.swf',
            					    width: 750,
            					    height: 400,
            					    wmode: 'transparent'
            					});
            					*/
            					animacionintro();
            					$('#texto').hide();
            				} else {
            					$('#texto').css('padding','5px 10px 5px 10px');
            				}
            				//$('#contenedor').show(1000, function(){
            					/*$('#loading1').animate({height:'360px'},1000);*/
            					$('#mas-img').show().css("left","0px");
            					$('#mas-img').animate({left:'798px'},1500);
            					$('#loading2').animate({width:'800px'},1500, function(){
            						//$('#mas-img').fadeOut(500);
            						$('#texto').fadeIn(500, function(){
										if(liga == "/deo/galeria.html"){
											if (bandera == 0) {
												lagaleria();
												bandera++;
											}
										}
									}); 
            						$('#textoscroll').jScrollPane({scrollbarWidth : 1});
            					});
            				//});
            			});
            	//	});
                	
                });
            });
    	}
        return false;
    });
});
function enviar_formulario () {
	var Nombre = $('#nombre').val();
	var Correo = $('#correo').val();
	var Telefono = $('#telefono').val();
	var Comentarios = $('#servicios').val();

	
	if(Nombre == "") {
		alert("El campo Nombre es obligatorio.");
		return false;
	}
	if(Correo == "") {
		alert("El campo Correo es obligatorio.");
		return false;
	}
	
	$("#loading2, #mas-img").fadeOut(500, function(){
		/*$("#loading1").css("height","0px");*/
		$("#loading2").css("width","0px");
        $('#texto').fadeOut(500, function(){$('#contenedor').hide(500, function(){$(this).load('/formulario.php #texto', {'Nombre' : Nombre, 'Correo' : Correo, 'Telefono' : Telefono, 'Comentarios' : Comentarios}, function () {$('#textocontenido').hide();
        $('#contenedor').show(1000, function(){/*$('#loading1').animate({height:'360px'},1000);*/$('#mas-img').show().css("left","0px");
		$('#mas-img').animate({left:'798px'},1500); $('#loading2').animate({width:'800px'},1500, function(){$('#textocontenido').fadeIn(500);});});});});
    	
        });
	});
	
}
function lagaleria () {
	banderita = 100;
	var numrand = Math.floor(Math.random()*15) + 1;
	var lafoto = "foto" + numrand;
	var lasfotos = $("#lasfotitos").val();
	var fotosarray = lasfotos.split(",");
	var cantfotos = fotosarray.length;
	var numrandfotos = Math.floor(Math.random()*cantfotos);
	var azar = Math.random()*1;
	if(azar > .35){
		var lafotoes = fotosarray[numrandfotos] + '.jpg';
	} else {
		var lafotoes = "negra.png";
	}
	$("#" + lafoto + " img").fadeOut(1000, function() { $(this).attr("src","/images/productos/chicas/" + lafotoes).fadeIn(1000)});
	var mosaico = setTimeout('lagaleria()',1500);
}

function muestrafoto(lafotoamostrar){
	var urlfoto = $("#" + lafotoamostrar + " img").attr("src");
	var urlfotoexp = urlfoto.split('/');
	var fotomuestra = urlfotoexp[4];
	var fotoamostrar = "/images/productos/grandes/" + fotomuestra;
	var titulo = "";
	if(fotomuestra != "negra.jpg"){
		$.get("/titulo.php?id=" + fotomuestra, function(data){ titulo = data; abre_foto(titulo,fotoamostrar);});
	}
}

function abre_foto(titulo,imagen){
    Shadowbox.open({
        player:     'img',
        language:   "es",
        title:      titulo,
        content:    imagen,
        options: {
        handleOversize: 'drag'
        }
    });
};
Shadowbox.init({
	players: ["img", "html"]});
/******************* FUNCION DE ANIMACION INTRO *******************************************/
function sleep(milliseconds) {
	  var start = new Date().getTime();
	  for (var i = 0; i < 1e7; i++) {
	    if ((new Date().getTime() - start) > milliseconds){
	      break;
	    }
	  }
	}
function animacionintro () {
	var seccion = new Array(8);
	seccion[3] = "CALIDAD";
	seccion[0] = "COMPROMISO";
	seccion[5] = "COMUNICACI&Oacute;N";
	seccion[4] = "CONFIANZA";
	seccion[1] = "EXPERIENCIA";
	seccion[2] = "RESPONSABILIDAD";
	seccion[6] = "SERVICIO PERSONALIZADO";
	seccion[7] = "TRABAJO EN EQUIPO";
	var espera = 3000;
	var eltexto = '<div id="slideshow">';
	for(i=0;i<seccion.length;i++){
		if(i==0){
			eltexto = eltexto + '<div class="eltexto active"><span>' + seccion[i] + '</span></div>';
			eltexto = eltexto + '<div><img src="/images/intro/' + i + '-1.jpg"></div>';
			eltexto = eltexto + '<div><img src="/images/intro/' + i + '-2.jpg"></div>';
		} else {
			eltexto = eltexto + '<div class="eltexto"><span>' + seccion[i] + '</span></div>';
			eltexto = eltexto + '<div><img src="/images/intro/' + i + '-1.jpg"></div>';
			eltexto = eltexto + '<div><img src="/images/intro/' + i + '-2.jpg"></div>';
		}
	}
	eltexto = eltexto + '</div>';
	$('#texto').html(eltexto).hide();
	$('#texto').fadeIn(500);
	var posx=Math.floor(Math.random()*550);
    var posy=Math.floor(Math.random()*320);
    var nuevaposx = posx + 100;
	$('#slideshow div.eltexto span').css({opacity:1.0,marginLeft:posx + "px", marginTop:posy + "px"});
	$('#slideshow div.eltexto span').animate({marginLeft:nuevaposx + "px",opacity:0}, 3000);
	$(function() {
	    elintervalo = setInterval( "slideSwitch()", 4000 );
	});
}
function slideSwitch() {
    var $active = $('#slideshow div.active');

    if ( $active.length == 0 ) $active = $('#slideshow div:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow div:first');
 
    $active.addClass('last-active');

    var checatexto = $next.attr('class');
    var posx=Math.floor(Math.random()*550);
    var posy=Math.floor(Math.random()*320);
    var nuevaposx = posx + 100;
    if(checatexto == "eltexto"){
    	$('#slideshow div.eltexto span').css({opacity:1.0,marginLeft:posx + "px", marginTop:posy + "px"});
    	$('#slideshow div.eltexto span').animate({marginLeft:nuevaposx + "px",opacity:0}, 3000);
    	$next.css({opacity: 0.0})
        	.addClass('active')
        	.animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
    } else {
    	$next.css({opacity: 0.0})
    		.addClass('active')
    		.animate({opacity: 1.0}, 1000, function() {
    		$active.removeClass('active last-active');
    	});
    }
}
/*******Funcion para mostrar google map**********************/
function vermapa() {
	var contenidomapa = '<iframe width="540" scrolling="no" height="365" frameborder="0" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/ms?ie=UTF8&amp;hl=es&amp;msa=0&amp;msid=109139271300571817387.000478d698f8a5f98c9fd&amp;ll=20.683822,-103.369074&amp;spn=0.012045,0.019312&amp;z=15&amp;output=embed"></iframe>';
	$('#mapa').fadeOut(1000, function () {
		$(this).html(contenidomapa).fadeIn(1000);
	});
}
