﻿// Funcion de inicializacion de los Scripts del sitios Web
$(document).ready(function() {
    ServisScriptsInitialize();
});

function ServisScriptsInitialize() {
    
    AddHomeProjectFilterBehavior();    
    AddCarouselBehavior();
    AddEmploymentBehavior();
}

// Añade el comportamiento de las capas que
// se muestran en la home del sitio
function AddHomeProjectFilterBehavior() {
    $(".div_corner").hover(function() {
        $(this).css("cursor", "pointer");
        $(this).parent().find(".div_filter").slideUp(1000, function() {
            var url = $(this).parent().find(".div_corner").find(".lnk").attr("href");

            $(this).parent().find(".div_corner").click(function() {
                location.href = url;
            });

            $(this).parent().find(".div_corner").mouseout(function() {
                $(this).parent().find(".div_filter").slideDown(1000);
                $(this).css("cursor", "default");
            });
        });
    });
}

// Añade el comportamiento para que cuando se pulsa sobre el link
// de Empleo se muestre la capa con la informacion sobre empleo
function AddEmploymentBehavior() {
    var pos = $("#employment_link").offset();
    $("#employment_content").css("left", pos.left -100 + "px");

    $("#employment_link").click(function() {
        $("#employment_content").show();
        $("#imgCloseE").click(function() {
            $("#employment_content").hide();
        });
    });
}


// Añade el script para inicializar el carousel y los
// elementos dependientes
function AddCarouselBehavior() {

    if ($(".carousel")) {
        if ($(".carousel ul li").length > 0) {

            if ($(".carousel ul li").length <= 5) {
                document.getElementById("btnPrevious").style.visibility = "hidden";
                document.getElementById("btnNext").style.visibility = "hidden";
            } else {
                document.getElementById("btnPrevious").style.visibility = "visible";
                document.getElementById("btnNext").style.visibility = "visible";

                $(".carousel").jCarouselLite({
                    btnNext: ".imgNext",
                    btnPrev: ".imgPrev",
                    scroll: 1,
                    circular: false,
                    visible: 5
                });

                $(".carousel").css("width", "473px");
            }
        

        
            $(".carousel ul li img").each(function() {
                $(this).click(function() {                
                    $(".photo_proyect img").attr("src", $(this).attr("src"));
                });
            });           
        }
    }
    
    
   
    /*if ($(".carousel")) {
        if ($(".carousel ul li").length > 0) {
            $(".caraousel").scrollable({ items: '.caraousel_list', horizontal: true, size: 3 });

            $(".carousel ul li img").each(function() {
                $(this).click(function() {                
                    $(".photo_proyect img").attr("src", $(this).attr("src"));
                });
            });

            $(".imgPrev").click(function() {
                alert();
                $(".caraousel").scrollable("prevPage", "slow");
            });

            $(".imgNext").click(function() {
            alert();
                $(".caraousel").scrollable("nextPage", "slow");
            });            
        }        
    }*/ 
    
}

// Seencarga de manejar la visibilidad del filtro verde
// de la galeria de proyectos
function ManageProyectVisualFilter(excludedId) {
    $("#" + excludedId).css("display", "none");
    
    if ($("#project_gallery_cont .pgallery_item_f").length > 0) {
        $("#project_gallery_cont .pgallery_item_f").each(function() {            
            if ($(this).attr("id") != excludedId) {                
                $(this).css("display", "block");
            }
        });
    }
}

function ManageDivs(toHide, toShow) {
    $("#" + toHide).hide();
    $("#" + toShow).show();
}

function ShowDiv(divId) {
    $("#" + divId).show();
}

function ShowAddress(codCiudad, imgoff, imgon) {
    if ($("#divfiltermap .divaddress").length > 0) {
        $("#divfiltermap .divaddress").each(function() {
            $(this).hide();
        });
    }

    if ($("#divmap .divpointmap .imgcity").length > 0) {
        $("#divmap .divpointmap .imgcity").each(function() {
            switch ($(this)[0].id) {
                case "imgV":
                    $(this).attr("src", "/images/point_off2_ie6.png");
                    break;
                case "imgB":
                    $(this).attr("src", "/images/point_off3_ie6.png");
                    break;
                default:
                    $(this).attr("src", "/images/point_off_ie6.png");
            }
        });
    }

    $("#divfiltermap").css("display", "block");
    $("#div" + codCiudad).css("display", "block");
    $("#img" + codCiudad).attr("src", "/images/" + imgon);

    $("#lnkgooglemaps").attr("href", hashGoogleMaps.get(codCiudad));
    $("#lnkgooglemaps2").attr("href", hashGoogleMaps.get(codCiudad));
}

// Añade el comportamiento par que en la ventana de servicios se cambie
// de clase css cada contenido de tipo ".content_services"
function InitializeServicesHover() {
    if ($("#services .content_services").length > 0) {
        $("#services .content_services").each(function() {
            $(this).hover(
                function() { $(this).addClass("content_services_h") },
                function() { $(this).removeClass("content_services_h") }
            );
        });
    }

    if ($("#services .content_servicesIE6").length > 0) {
        $("#services .content_servicesIE6").each(function() {
            $(this).hover(
                function() { $(this).addClass("content_services_h") },
                function() { $(this).removeClass("content_services_h") }
            );
        });
    }
}

function InitializeCompanyBehavior() {
    $("#com_back .left div").each(function() {
        $(this).click(function() {
            $("#com_back .right div").each(function() {
                $(this).hide();
            });

            $("#com_back .left div").each(function() {
                $(this).css("color", "gray");
            });

            $(this).css("color", "#058205");
            $("#dv" + $(this).attr("index")).show();
        });
    });
}

function ActivateMenuOption(id) {
    $(".topmenu ul li#" + id).addClass("topmenu_selected");
}


function InitializeSliderBehavior() {
    if ($("#slider_img").length > 0) {

        var last;
        $("#slider_img").draggable({
            axis: 'y',
            containment: 'parent',
            scrollSensitivity: 70,
            drag: function(event, ui) {
                //debugger;
                var factor = (ui.offset.top - last) * 1.25;
                var act = $("#env_textcolumn_left .text_container").attr("scrollTop");
                $("#env_textcolumn_left .text_container").attr("scrollTop", act + factor);

//                if (ui.offset.top > last) {
//                    
//                }
//                else {
//                    $("#env_textcolumn_left .text_container").attr("scrollTop", act - factor);
//                }
                last = ui.offset.top;
            }
        });
    }
}