
function tooltip(event,ancho,texto){
    var e = event || window.event;


    if (document.all){
        x_pos = window.event.clientX + document.body.scrollLeft;
        y_pos = window.event.clientY + document.body.scrollTop;

    }
    else{
        x_pos = e.pageX+5 ;
        y_pos = e.pageY+5 ;
    }

    
    if(x_pos+ancho+40 > window.innerWidth){
        document.getElementById("tip").style.left="";
        document.getElementById("tip").style.left=(x_pos-ancho-40)+"px";
    }else{
        document.getElementById("tip").style.left=x_pos+"px";
    }
    
    document.getElementById("tip").style.width=ancho+"px";
    
    document.getElementById("tip").style.top=y_pos+"px";
    document.getElementById("tip").style.display="block";
    document.getElementById("tip").innerHTML=texto;
    

}
function tooltipout(){
    document.getElementById("tip").style.left="0px";
    document.getElementById("tip").style.top="0px";
    document.getElementById("tip").style.display="none";
    

}

$(document).ready(function(){
    
    

    $(".fondoConTrabajo").click(function(){
        //Si hay alguna activa las cierro
        if( $(".trabajoactivo").length ){
            $(".trabajoactivo").slideUp('slow');
            $(".trabajoactivo").removeClass("trabajoactivo");
            $(".conBorde").css("border","solid 0px #b0b0b0");
            $(".conBorde").removeClass("conBorde");
        }
        $(".trabajosPrimera").addClass("trabajoactivo");
        $(".trabajoactivo").slideDown('slow');
        $(this).css("border","solid 1px #b0b0b0");
        $(this).addClass("conBorde");
    });

    $(".trabajoIcono").click(function(){
        //Si hay alguna activa las cierro
        if( $(".subtrabajoactivo").length ){
            $(".subtrabajoactivo").slideUp('slow');
            $(".subtrabajoactivo").removeClass("trabajoactivo");
        }
        $(".subTrabajosPrimera").addClass("trabajoactivo");
        $(".trabajoactivo").slideDown('slow');
    });

    cambio = function (paso){
        calculoIzq = 0;
        texto = 1;
        anteriorTexto = 4;
        if($("#sliderImagenes").css("left")=="-2820px"){
            if(paso==1){
                calculoIzq = 0;
                texto=1;
                anteriorTexto = 4;
            } else{
                calculoIzq = 1880;
                texto=3;
                anteriorTexto = 4;
            }
        }else if($("#sliderImagenes").css("left")=="-1880px"){
            if(paso==1){
                calculoIzq = 2820;
                texto=4;
                anteriorTexto = 3;
            } else{
                calculoIzq = 940;
                texto=2;
                anteriorTexto = 3;
            }
        }else if($("#sliderImagenes").css("left")=="-940px"){
            if(paso==1){
                calculoIzq = 1880;
                texto=3;
                anteriorTexto = 2;
            } else{
                calculoIzq = 0;
                texto=1;
                anteriorTexto = 2;
            }
        }else{
            if(paso==1){
                calculoIzq = 940;
                texto=2;
                anteriorTexto = 1;
            }else{
                calculoIzq = 2820;
                texto=4;
                anteriorTexto = 1;
            }
        }

        $("#sliderImagenes").animate({
            left: -calculoIzq
        }, 500 );
        $("#sliderTexto"+anteriorTexto).fadeOut('slow');
        $("#sliderTexto"+texto).fadeIn('slow');
    }
    rotar = function (){
        play = setInterval(function(){
            cambio(1);
        }, 4000);
    }
    rotar();
    
    
    

    $("#SliderFlechaDerecha").click(function(){
        clearInterval(play);
        cambio(1);
        rotar();
        return false;
    });
    $("#SliderFlechaIzquierda").click(function(){
        clearInterval(play);
        cambio(2);
        rotar();
        return false;
    });




});

$(function() {
    $(window).scroll(function() {
        if($(this).scrollTop() != 0) {
            $('#toTopMenu').fadeIn();
        } else {
            $('#toTopMenu').fadeOut();
        }
    });

    $('#toTopBoton').click(function() {
        $('body,html').animate({
            scrollTop:0
        },800);
    });
    $('#irInicio').click(function() {
        $('body,html').animate({
            scrollTop:0
        },800);
    });
	
    $('#subir').click(function() {
        $('body,html').animate({
            scrollTop:0
        },800);
    });




});

//(function ($) {
//    $.fn.cross = function (options) {
//        return this.each(function (i) {
//            // cache the copy of jQuery(this) - the start image
//            var $$ = $(this);
//
//            // get the target from the backgroundImage + regexp
//            var target = $$.css('backgroundImage').replace(/^url|[\(\)'"]/g, '');
//
//            // nice long chain: wrap img element in span
//            $$.wrap('<span style="position: relative;"></span>')
//            // change selector to parent - i.e. newly created span
//            .parent()
//            // prepend a new image inside the span
//            .prepend('<img>')
//            // change the selector to the newly created image
//            .find(':first-child')
//            // set the image to the target
//            .attr('src', target);
//
//            // the CSS styling of the start image needs to be handled
//            // differently for different browsers
//            if ($.browser.msie || $.browser.mozilla) {
//                $$.css({
//                    'position' : 'absolute',
//                    'left' : 0,
//                    'background' : '',
//                    'top' : this.offsetTop
//                });
//            } else if ($.browser.opera && $.browser.version < 9.5) {
//                // Browser sniffing is bad - however opera < 9.5 has a render bug
//                // so this is required to get around it we can't apply the 'top' : 0
//                // separately because Mozilla strips the style set originally somehow...
//                $$.css({
//                    'position' : 'absolute',
//                    'left' : 0,
//                    'background' : '',
//                    'top' : "0"
//                });
//            } else { // Safari
//                $$.css({
//                    'position' : 'absolute',
//                    'left' : 0,
//                    'background' : ''
//
//
//                });
//            }
//
//            // similar effect as single image technique, except using .animate
//            // which will handle the fading up from the right opacity for us
//            $$.hover(function () {
//                $$.stop().animate({
//                    opacity: 0
//                }, 250);
//            }, function () {
//                $$.stop().animate({
//                    opacity: 1
//                }, 250);
//            });
//        });
//    };
//
//})(jQuery);
//
//// note that this uses the .bind('load') on the window object, rather than $(document).ready()
//// because .ready() fires before the images have loaded, but we need to fire *after* because
//// our code relies on the dimensions of the images already in place.
//$(window).bind('load', function () {
//    $('img.fade').cross();
//});

var Header = {
    // Let's write in JSON to make it more modular
    addFade : function(selector){
        $("<span class=\"fake-hover\"></span>").css("display",
            "none").prependTo($(selector));
        // Safari dislikes hide() for some reason
        $(selector+" a").bind("mouseenter",function(){
            $(selector+" .fake-hover").fadeIn("slow");
        });
        $(selector+" a").bind("mouseleave",function(){
            $(selector+" .fake-hover").fadeOut("slow");
        });
    }
};
$(function(){
    Header.addFade("#header");
});

$(function(){
    Header.addFade("#headerBlanca");
});

$(function(){
    Header.addFade("#headerNegra");
});

function objetoAjax(){
    var xmlhttp=false;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

function enviarFormulario(url, formid){
    var Formulario = document.getElementById(formid);
    if( Formulario.nombre.value!='...Escriba aqui su nombre' && Formulario.email.value!='...Escriba aqui su mail' && Formulario.mensaje.value!='...Escriba aqui su mensaje' && Formulario.captcha.value!=''){
        document.getElementById("botonEnviar").value = "Espere";
        peticion = objetoAjax();
        var cadenaFormulario = ""
        var sepCampos
        sepCampos = ""
        for (var i=0; i <= Formulario.elements.length-1;i++) {
            cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURI(Formulario.elements[i].value);
            sepCampos="&";
        }
        peticion.open("POST", url, true);
        peticion.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
        peticion.onreadystatechange = function () {
            if (peticion.readyState == 4) {
                document.getElementById('mensajes').innerHTML =  peticion.responseText;
                if(peticion.responseText=="Muchas gracias, en breve nos pondremos en contacto."){
                    document.getElementById('captcha').value = "";
                    $("#labelCaptcha>img").attr("src","/captcha/captcha.php?color=blanca&"+new Date());
                }
            }
            document.getElementById("botonEnviar").value = "Enviar";
            document.getElementById('captcha').value = "";
            $("#labelCaptcha>img").attr("src","/captcha/captcha.php?color=blanca&"+new Date());
        }
        peticion.send(cadenaFormulario);
    }else{

        if(Formulario.nombre.value=='...Escriba aqui su nombre'){
            document.getElementById('mensajes').innerHTML = "Por favor rellene su nombre.";
            document.getElementById('captcha').value = "";
            $("#labelCaptcha>img").attr("src","/captcha/captcha.php?color=blanca&"+new Date());
            document.getElementById('nombre').focus();
        }
        else if(Formulario.email.value=='...Escriba aqui su mail'){
            document.getElementById('mensajes').innerHTML = "Por favor rellene su mail.";
            document.getElementById('captcha').value = "";
            $("#labelCaptcha>img").attr("src","/captcha/captcha.php?color=blanca&"+new Date());
            document.getElementById('email').focus();
        }
        else if(Formulario.mensaje.value=='...Escriba aqui su mensaje'){
            document.getElementById('mensajes').innerHTML = "Por favor rellene su mensaje.";
            document.getElementById('captcha').value = "";
            $("#labelCaptcha>img").attr("src","/captcha/captcha.php?color=blanca&"+new Date());
            document.getElementById('mensaje').focus();
        }
        else if(Formulario.captcha.value==''){
            document.getElementById('mensajes').innerHTML = "Por favor rellene el código captcha.";
            document.getElementById('captcha').value = "";
            $("#labelCaptcha>img").attr("src","/captcha/captcha.php?color=blanca&"+new Date());
            document.getElementById('captcha').focus();
        }

    }
}
var ncArray = ["Cofitugou","Bordados Biuty","Distribuciones Grayna","Cortinas Las Nieves","Lacasadepandora. Interiorismo","Calzados Puri's","Gallagher's Irish Tavern","Productos Beltrán","Lineacentro Wellfitness Club","Discoteca SALA AVANTI","Grupo de Empresas Venturacanarias","Elite Baños y Cerámicas","Llamameloco. Bicicletas","Unita Tecnologías de la Información","SB Skate&Snowboard"];
var nfArray = ["cofitugou","biuty","grayna","lasnieves","lacasadepandora","puris","gallaghers","beltran","lineacentro","avanti","venturacanarias","eliteceramicas","llamameloco","unita","sbsnowboard"];

function abrirCerrarTrabajo(area,tipo,archivo){
    if( $(".trabajoIndividualActive").length ){
        $(".trabajoIndividualActive").removeClass("trabajoIndividualActive");

        $(".areaAbierta").slideUp("slow",function(){
            $(".areaAbierta").html("");
            $(".areaAbierta").removeClass("areaAbierta");
            $("#trabajoGrande"+tipo+area).load("/trabajos/"+tipo+"/"+archivo+".php?simple=true");
            $("#trabajoGrande"+tipo+area).slideDown("slow");
            $("#trabajoGrande"+tipo+area).addClass("areaAbierta");
            $("#"+archivo+tipo).addClass("trabajoIndividualActive");
            $.scrollTo("#"+archivo+tipo,800);


        });
    }else{
        $("#trabajoGrande"+tipo+area).load("/trabajos/"+tipo+"/"+archivo+".php?simple=true");
        $("#trabajoGrande"+tipo+area).slideDown("slow",function(){
            $.scrollTo("#"+archivo+tipo,800);
        });
        $("#trabajoGrande"+tipo+area).addClass("areaAbierta");
        $("#"+archivo+tipo).addClass("trabajoIndividualActive");
    }
}
function cerrarTrabajo(zona){
    $(".trabajoIndividualActive").removeClass("trabajoIndividualActive");

    $(".areaAbierta").slideUp("slow",function(){
        $(".areaAbierta").html("");
        $(".areaAbierta").removeClass("areaAbierta");
        $.scrollTo("#"+zona,800);
    });
}
function pasarAl(numelementos,numelemento){
    posicion = -607 * (numelemento-1);
    if($(".numactivo").length==1){
        $(".numactivo").removeClass("numactivo");
    }
    $("#num"+numelemento).addClass("numactivo");
    $("#lienzoMiniSlider"+numelementos).animate({
        left: posicion+"px"
    },"slow",function(){

        });

}

function pasarDer(numelementos){
    $(".miniSliderFlechaIzquierda").css("display","none");
    $(".miniSliderFlechaDerecha").css("display","none");
    var leftinicio = 0;
    var leftmaximo = 607 * (numelementos-1);
    var leftactual = parseInt( ($("#lienzoMiniSlider"+numelementos).css("left")).replace("px", "") );
    var lefmaximostring = -leftmaximo;



    if(leftactual > lefmaximostring ){
        $("#lienzoMiniSlider"+numelementos).animate({
            left: '-=607'
        },"slow",function(){
            $(".miniSliderFlechaIzquierda").css("display","block");
            $(".miniSliderFlechaDerecha").css("display","block");
            var destino =  (parseInt($("#lienzoMiniSlider"+numelementos).css("left"))/-607);
            destino++;
            if( destino > numelementos){
                destino = 1;
            }
            if($(".numactivo").length==1){
                $(".numactivo").removeClass("numactivo");
            }
            $("#num"+destino).addClass("numactivo");

        });
    }else{
        $("#lienzoMiniSlider"+numelementos).animate({
            left: leftinicio
        },"slow",function(){
            $(".miniSliderFlechaIzquierda").css("display","block");
            $(".miniSliderFlechaDerecha").css("display","block");
            var destino =  (parseInt($("#lienzoMiniSlider"+numelementos).css("left"))/-607);
            destino++;
            if( destino > numelementos){
                destino = 1;
            }
            if($(".numactivo").length==1){
                $(".numactivo").removeClass("numactivo");
            }
            $("#num"+destino).addClass("numactivo");
        });

    }

}

function pasarIzq(numelementos){
    $(".miniSliderFlechaIzquierda").css("display","none");
    $(".miniSliderFlechaDerecha").css("display","none");
    var leftinicio = -607 * (numelementos-1);
    var leftmaximo = 0;
    var leftactual = parseInt( ($("#lienzoMiniSlider"+numelementos).css("left")).replace("px", "") );
    var lefmaximostring = leftmaximo;

    if(leftactual < lefmaximostring ){
        $("#lienzoMiniSlider"+numelementos).animate({
            left: '+=607'
        },"slow",function(){
            $(".miniSliderFlechaIzquierda").css("display","block");
            $(".miniSliderFlechaDerecha").css("display","block");
            var destino =  (parseInt($("#lienzoMiniSlider"+numelementos).css("left"))/-607)+1;

            if( destino < 1){
                destino = numelementos;
            }
            if($(".numactivo").length==1){
                $(".numactivo").removeClass("numactivo");
            }
            $("#num"+destino).addClass("numactivo");

        });
    }else{
        $("#lienzoMiniSlider"+numelementos).animate({
            left: leftinicio
        },"slow",function(){
            $(".miniSliderFlechaIzquierda").css("display","block");
            $(".miniSliderFlechaDerecha").css("display","block");
            var destino =  (parseInt($("#lienzoMiniSlider"+numelementos).css("left"))/-607)+1;

            if( destino < 1){
                destino = numelementos;
            }
            if($(".numactivo").length==1){
                $(".numactivo").removeClass("numactivo");
            }
            $("#num"+destino).addClass("numactivo");
        });

    }

}
function cerraTodasTipo2(seccion){
    if( seccion != 'webWrap'){
        if($(".webWrapCerrada").length==0){
            $("#webWrap").slideUp("slow");
            $("#webWrap").addClass("webWrapCerrada");
            $("#webWrapFlecha").css("background","url(/imagenes/flechaAbajo.png)");
        }
    }
    if( seccion != 'identidadWrap'){
        if($(".identidadWrapCerrada").length==0){
            $("#identidadWrap").slideUp("slow");
            $("#identidadWrap").addClass("identidadWrapCerrada");
            $("#identidadWrapFlecha").css("background","url(/imagenes/flechaAbajo.png)");
        }
    }
    if( seccion != 'disenoWrap'){
        if($(".disenoWrapCerrada").length==0){
            $("#disenoWrap").slideUp("slow");
            $("#disenoWrap").addClass("disenoWrapCerrada");
            $("#disenoWrapFlecha").css("background","url(/imagenes/flechaAbajo.png)");
        }
    }
    if( seccion != 'namingWrap'){
        if($(".namingWrapCerrada").length==0){
            $("#namingWrap").slideUp("slow");
            $("#namingWrap").addClass("namingWrapCerrada");
            $("#namingWrapFlecha").css("background","url(/imagenes/flechaAbajo.png)");
        }
    }
    if( seccion != 'campanaWrap'){
        if($(".campanaWrapCerrada").length==0){
            $("#campanaWrap").slideUp("slow");
            $("#campanaWrap").addClass("campanaWrapCerrada");
            $("#campanaWrapFlecha").css("background","url(/imagenes/flechaAbajo.png)");
        }
    }

}

function abrirCerrar(seccion,tipo,color){
    color = color || 1;
    var vectorSecciones = new Array();
    vectorSecciones['sliderWrap'] = 'slider';
    vectorSecciones['quienesSomosTexto'] = 'quienesSomos';
    vectorSecciones['serviciosSeccionTexto'] = 'serviciosSeccion';
    vectorSecciones['trabajosWrap'] = 'trabajosSeccion';
    vectorSecciones['contactanos'] = 'contactoSeccion';
    vectorSecciones['clientesTodos'] = 'clientesSeccion';

    if($("."+seccion+"Cerrada").length){
        var seccionaux = seccion.replace("Wrap","");
        if( seccionaux=='web' || seccionaux=='identidad' || seccionaux=='naming' || seccionaux=='campana' || seccionaux=='diseno' ){
            if($("#"+seccion).html() == ""){
                $("#"+seccion).load("/trabajos/"+seccionaux+"/"+seccionaux+".php?simple=true",function(){
                    $("#"+seccion).slideDown("slow");
                });
            }
            else
                $("#"+seccion).slideDown("slow");
        }else
            $("#"+seccion).slideDown("slow");
        
        $("#"+seccion).removeClass(seccion+"Cerrada");

        if(tipo==1){
            if(color==2)
                $("#"+seccion+"Flecha").css("background","url(/imagenes/xNegra.png)");
            else
                $("#"+seccion+"Flecha").css("background","url(/imagenes/x.png)");
            seccionPadre = vectorSecciones[seccion];
            $("#"+seccionPadre).css("margin-bottom","70px");
        }
        else if(tipo==2){
            if(color==2)
                $("#"+seccion+"Flecha").css("background","url(/imagenes/flechaArribaNegra.png)");
            else
                $("#"+seccion+"Flecha").css("background","url(/imagenes/flechaArriba.png)");
            $.scrollTo("#cab"+seccion,800);
        }
    }else{
        $("#"+seccion).slideUp("slow");
        $("#"+seccion).addClass(seccion+"Cerrada");
        if(tipo==1){
            if(color==2)
                $("#"+seccion+"Flecha").css("background","url(/imagenes/masNegra.png)");
            else
                $("#"+seccion+"Flecha").css("background","url(/imagenes/mas.png)");
            seccionPadre = vectorSecciones[seccion];
            $("#"+seccionPadre).css("margin-bottom","30px");
        }else if(tipo==2){
            if(color==2)
                $("#"+seccion+"Flecha").css("background","url(/imagenes/flechaAbajoNegra.png)");
            else
                $("#"+seccion+"Flecha").css("background","url(/imagenes/flechaAbajo.png)");
            if( seccion=='namingWrap' | seccion=='identidadWrap' | seccion=='webWrap' | seccion=='disenoWrap' | seccion=='campanaWrap' ){
                $.scrollTo("#trabajosCabecera",800);
            }else if( seccion=='empresaWrap' | seccion=='personalWrap' | seccion=='direccionWrap'){
                $.scrollTo("#quienesCabecera",800);
            }
            
        }
    }
}

function mostrarCliente(cliente,ejecutar){
    var nosaltar = true;
    ejecutar = ejecutar || 0;
    if($(".resaltado").length){
        var num = 0;
        if(($(".resaltado").attr("id")).length ==3){
            num = ($(".resaltado").attr("id")).substr(1, 2);
        }else{
            num = ($(".resaltado").attr("id")).substr(1, 1);
        }
        
        if( num == cliente)
            nosaltar = false;
    }
    if(nosaltar){
        if($(".resaltado").length){
            $(".resaltado>.fadeClientes").css("top","");
            $(".resaltado").removeClass("resaltado");
        }

        $("#c"+cliente+">.fadeClientes").css("top","-78px");
        $("#c"+cliente).addClass("resaltado");
        $("#imagenCliente").fadeOut(function(){

            $('#imagenCliente')
            .removeAttr('src')
            .attr('src','/imagenes/clientes/'+nfArray[cliente]+'Big.jpg')
            .fadeIn();
            if(ejecutar){
                $(".miniSliderFlechaDerechaClientes").css("display","inline");
                $(".miniSliderFlechaIzquierdaClientes").css("display","inline");
            }
        });
        $("#clientesCajaDerechaTextos").html(ncArray[cliente]);
    }

}
function iniciales(){
    $("#c0>.fadeClientes").css("top","-78px");
    $("#c0").addClass("resaltado");

}

$(document).ready(function(){
    $(".miniSliderFlechaDerechaClientes").click(function(){
        $(".miniSliderFlechaDerechaClientes").css("display","none");
        $(".miniSliderFlechaIzquierdaClientes").css("display","none");
        var num = 0;
        if(($(".resaltado").attr("id")).length ==3){
            num = ($(".resaltado").attr("id")).substr(1, 2);
        }else{
            num = ($(".resaltado").attr("id")).substr(1, 1);
        }
        num++;
        if(num>14)
            num=0;
        mostrarCliente(num, 1);

    });

    $(".miniSliderFlechaIzquierdaClientes").click(function(){
        $(".miniSliderFlechaDerechaClientes").css("display","none");
        $(".miniSliderFlechaIzquierdaClientes").css("display","none");
        var num = 0;
        if(($(".resaltado").attr("id")).length ==3){
            num = ($(".resaltado").attr("id")).substr(1, 2);
        }else{
            num = ($(".resaltado").attr("id")).substr(1, 1);
        }
        num--;
        if(num<0)
            num=14;
        mostrarCliente(num,1);
    });


});
function irA(seccion){
    $.scrollTo("#"+seccion,800);
}




