/*810*/
Object.floatval = function(mixed_var) {
    return (parseFloat(mixed_var) || 0);
};
Object.objLenght = function(obj) {
    var size = 0, key;
    for (key in obj) {
        if (obj.hasOwnProperty(key)) size++;
    }
    return size;
};
Object.indexOf = function(array,obj) {
    var size = 0, key;
    for (key in array) {
        size++;
        if (key == obj) return size;
    }

};
$(document).ready(function(){



    // --- [MAIN SLIDER BEGINS] ---
    var slider_total = $(".element").length;
    var slider_current = 0;
    var slider_step = parseInt( $(".element").width() );
    $(".arrowcontainer .leftarrow a , .arrowcontainer .rightarrow a").live("click",function(){
        if( $(this).parent().is(".leftarrow") ){
            if( slider_current > 0){
                slider_current--;
            }else{
                slider_current = slider_total-1;
            }
        }else{
             if( slider_current < slider_total-1){
                slider_current++;
            }else{
                slider_current = 0;
            }
        }
        $(".elements").stop().animate({marginLeft:-slider_current * slider_step},400);
        return false;
    });
    // --- [MAIN SLIDER ENDS] ---

    // --- [MAIN TABS BEGINS] ---
    $.selectTab = function(index){
        $("#main-tabs li").each(function(){
            if( $(this).index() != index ){
                $(this).removeClass( "active" );
            }else{
                $(this).addClass( "active" );
            }
        });
        $("#main-tabs-slogan li").each(function(){
            if( $(this).index() != index ){
                $(this).removeClass( "active" );
            }else{
                $(this).addClass( "active" ).fadeIn();
            }
        });
        $(".tab-content-children").each(function(){
            if( $(this).index() != index ){
                $(this).removeClass( "active" );
            }else{
                $(this).addClass( "active" ).fadeIn();
            }
        });
    }
    $("ul#main-tabs li a").live("click",function(){
        $.selectTab( $(this).parent().index() );
        return false;
        //tab-content-children
    });
    $.selectTab(0);

    // --- [MAIN TABS ENDS] ---

    // --- [COMUNIDAD+ TABS BEGINS] ---
    $.selectTabCom = function(index){
        $("#comtabs div").each(function(){
            if( $(this).index() != index ){
                $(this).removeClass( "active" );
            }else{
                $(this).addClass( "active" );
            }
        });
        $(".inner-content-child").each(function(){
            if( $(this).index() != index ){
                $(this).removeClass( "active" );
            }else{
                $(this).addClass( "active" ).fadeIn();
            }
        });
    }
    $("#comtabs div").each(function(){
        $(this).click(function(){
            $.selectTabCom( $(this).index() );
            return false;
            //tab-content-children
        });
    });
    $.selectTabCom(0);

    // --- [COMUNIDAD+ TABS ENDS] ---

    if( $("#main-banner-tech").length > 0){
            $("#main-banner-tech .span6").fadeIn();
            $("#main-banner-tech .span6 h2, #main-banner-tech .span6 h3, #main-banner-tech .span6 p").fadeIn().each(function(){
        $("#main-banner-tech .span9").fadeIn(function(i){
                $(this).fadeIn();
            });
        });
        
    }

    if( $("#main-banner-pro").length > 0){
            $("#main-banner-pro div").fadeIn();
            $("#main-banner-pro .span6").fadeIn();
            $("#main-banner-pro .span6 h2, #main-banner-pro .span6 p, .prodbuttonfeat").fadeIn().each(function(){
        $("#main-banner-pro .span9").fadeIn(function(i){
                $(this).fadeIn();
            });
        });
    }

    var online_li_h = 38;
    $.openOnlineServices = function( index ){

        $("#online-services-list .item").each(function(  ){
            var lista =  $(this).next().children("ul");
            var lista_cont =  $(this).next();
            var i1 = $(this).index();
            var i2 = lista.children("li").length;

            if( i1 != index ){
                $(this).removeClass("active");
                if( lista_cont.is(":visible") ){
                    lista_cont.stop().show().slideUp();
                }
            }else{
                $(this).addClass("active");
                lista_cont.stop().show().css({height:(online_li_h * i2 ) +"px", display:"block"}).hide().slideDown();
            }
        });
    }
    if( $("#online-services-list .item").length > 0){
        $("#online-services-list .item").live( "click", function(){
            $.openOnlineServices( $(this).index() );
        });
        $.openOnlineServices( $("#online-services-list .item.active").index() );
    }
    $.slideHelpContent = function( ht ){
        var n = parseInt( ht.split("#")[1] );
        if( isNaN( n ) || n == undefined || n == 0 ){
            n = 0;
        }else{
            n--;
        }
        $("#help-container .wrapper").stop().delay(200,function(){
             $("#help-container .wrapper").stop().animate({ marginTop : -n * 605 },450);
        });

        $(".serv-item").each(function(i){
            $(this).fadeIn();
        });
        $("a.serv-current").each(function( i ){
            if( n != i ){
                $(this).removeClass("subactive");
            }else{
                $(this).addClass("subactive");
            }
        });
        window.location.hash="#"+(n+1);
    }
    if( $("#help-container").length > 0){
        $.slideHelpContent( window.location.hash );
        $("a.serv-current").live("click", function( e ){

            $.slideHelpContent( $(this).attr("href") );
            return false;
        });
    }

    $.section_load = function( i, i2 ){
        $("#content-show .faq-container").html("").css({display:"none"}).load("faq-"+(i+1)+".html", function(){
            $("#content-show .faq-container").fadeIn();
            $.subsectio_show( i2 );
        });
    }
    $.subsectio_show = function( i ){
        $("#content-show .faq-container .pregunta:visible").hide();
        $("#content-show .faq-container .pregunta:eq("+i+")").hide().fadeIn(300);
    }
    if( $("#online-services-list.faqmenu").length > 0 ){
        var section_current, section_new, section_subindex;
        section_current = -1;

        $(".faqmenu .sub a").live("click",function( e ){
            e.preventDefault();
            section_new = Math.round( $("#online-services-list.faqmenu .item.active").index() * 0.5 );
            section_subindex = $(this).parent().index();
            if( section_current != section_new ){
                section_current = section_new;
                $.section_load( section_new, section_subindex );
            }else{
                $.subsectio_show( section_subindex );
            }
        });
        var lista = $(".faqmenu#online-services-list .item.active").next().children("ul");
        lista.children("li:eq(0)").children("a").trigger("click");
    }

    if( $("#destacados").length > 0 ){

        $("#destacado1").popover({
              offset: -25,
              placement: 'below'
        });
        $("#destacado2").popover({
              offset: -25,
              placement: 'below'
        });
        $("#destacado3").popover({
              offset: -25,
              placement: 'below'
        });
        $("#destacado4").popover({
              offset: -25,
              placement: 'below'
        });
      }
    
    if ($('div.comunidadWrapper').length>0)
        $('div.comunidadWrapper').tabSlideOut({
            tabHandle: '.handle',                              //class of the element that will be your tab
           
            pathToTabImage: '../img/comunidad_tab.jpg',
                      //path to the image for the tab *required*
            imageHeight: '144px',                               //height of tab image *required*
            imageWidth: '45px',                               //width of tab image *required*
            tabLocation: 'right',                               //side of screen where tab lives, top, right, bottom, or left
            speed: 300,                                        //speed of animation
            action: 'click',                                   //options: 'click' or 'hover', action to trigger animation
            topPos: '81px',                                   //position from the top
            fixedPosition: true                               //options: true makes it stick(fixed position) on scroll
        });
        if ($('div.comunidadWrapperIni').length > 0)
            $('div.comunidadWrapperIni').tabSlideOut({
                tabHandle: '.handle',                              //class of the element that will be your tab
                pathToTabImage: 'img/comunidad_tab.jpg',          //path to the image for the tab *required*
                imageHeight: '144px',                               //height of tab image *required*
                imageWidth: '45px',                               //width of tab image *required*
                tabLocation: 'right',                               //side of screen where tab lives, top, right, bottom, or left
                speed: 300,                                        //speed of animation
                action: 'click',                                   //options: 'click' or 'hover', action to trigger animation
                topPos: '81px',                                   //position from the top
                fixedPosition: true                               //options: true makes it stick(fixed position) on scroll
            });
/*  Funciones Paquetes  */
	$("#yooPlusVT").hide();
	$("#yooPlusIT").hide();
    $("#btnYooPlusVI").click(function(){
		$("#yooPlus2P .info").hide();
		$("#yooPlusVI").fadeIn();
	});
    $("#btnYooPlusVT").click(function(){
		$("#yooPlus2P .info").hide();
		$("#yooPlusVT").fadeIn();
	});
    $("#btnYooPlusIT").click(function(){
		$("#yooPlus2P .info").hide();
		$("#yooPlusIT").fadeIn();
	});
	$("#yooVT").hide();
	$("#yooIT").hide();
    $("#btnYooVI").click(function(){
		$("#yoo2P .info").hide();
		$("#yooVI").fadeIn();
	});
    $("#btnYooVT").click(function(){
		$("#yoo2P .info").hide();
		$("#yooVT").fadeIn();
	});
    $("#btnYooIT").click(function(){
		$("#yoo2P .info").hide();
		$("#yooIT").fadeIn();
	});
/*  Terminan Paquetes  */
/*Inicia Módulos*/
$("#Mod2").hide();
$("#Mod3").hide();
$("#Mod4").hide();
$("#Mod5").hide();
$("#Mod6").hide();
$("#btnMod1").click(function () {
    $("#Modulos .info").hide();
    $("#Mod1").fadeIn();
});
$("#btnMod2").click(function () {
    $("#Modulos .info").hide();
    $("#Mod2").fadeIn();
});
$("#btnMod3").click(function () {
    $("#Modulos .info").hide();
    $("#Mod3").fadeIn();
});
$("#btnMod4").click(function () {
    $("#Modulos .info").hide();
    $("#Mod4").fadeIn();
});
$("#btnMod5").click(function () {
    $("#Modulos .info").hide();
    $("#Mod5").fadeIn();
});
$("#btnMod6").click(function () {
    $("#Modulos .info").hide();
    $("#Mod6").fadeIn();
});
$("#Mod11").hide();
$("#Mod12").hide();
$("#btnMod10").click(function () {
    $("#ModulosA .info").hide();
    $("#Mod10").fadeIn();
});
$("#btnMod11").click(function () {
    $("#ModulosA .info").hide();
    $("#Mod11").fadeIn();
});
$("#btnMod12").click(function () {
    $("#ModulosA .info").hide();
    $("#Mod12").fadeIn();
});
});
