$(document).ready(function(){
// ˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇConfiguracion General ˇˇˇ
    maketaSeccion();
    $(window).resize(function(){
        maketaSeccion();
    });
    $time = $("input[name=tiempo]").val()
    
    if ( $time == 1 )
    {
        setTimeout("comienzaGlobs()",10000);
    }
    else
    {
        setTimeout("comienzaGlobs()",30000);
    }
    
    $(window).resize(function(){
        animacionS3();
    });
// ˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇConfiguracion TOOLTIPS BANNERS ˇˇˇ
    $("div[class*=ico]").mouseenter(function(){
        $(this).stop().append('<div class="tooltipBanner">'+$(this).attr("id")+'</div>');
    }).mouseleave(function(){
        $(this).stop().find(".tooltipBanner").remove();
    });
// ˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇConfiguracion del FLASH DEL HOME ˇˇˇ    
    cargaFlash();
// ˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇConfiguracion Color MEnu ˇˇˇ
    lineaMenu("color");    
// Seccion 1 ... derecha
    $("#slideSec1Der").click(function(){
        sec = $("#estoy").text('color');
        $("#MenuAgencia").addClass("seleccionaA");
        animacionS2();
        $("#pasad").animate({marginLeft:0},100);
        lineaMenu(38);
        lineaMenu("color");
    });

// Seccion 2 ... derecha
    $(".slideSec2Der").hover(function(){
        $(".slideSec2Der .textoSec2").css("color","#E9193A");
        lineaMenu("vuelve");
    },function(){
        $(".slideSec2Der .textoSec2").css("color","#000000");
    });
    
    $(".slideSec2Der").stop().click(function(){
        lineaMenu("limpia");
        posi = parseInt($("#pasad").css("margin-left"));
        
        //alert(posi);
        if ( posi == 0 )
        {
            $("#MenuCuentas").addClass("seleccionaCu");
            lineaMenu(109);
            lineaMenu("vuelve");
        }
        if( posi <= -1668 )
        {
            $(".simulaWindow:first").animate({marginLeft:0},400,function(){}); // Mueve seccion 2 a seccion 1.
            $(".lineaRoj").animate({marginLeft:4000},400,function(){});
            sec = $("#estoy").text('home');
            lineaMenu("color");
            lineaMenu("vuelve");
        }
        else
        {
            $("#pasad").animate({"marginLeft":'+=-656px'},1000,function(){});
            posL = parseInt($(".seguiMenu").css("margin-left"));
            if ( posL == 109 )
            {
                lineaMenu('limpia');
                $("#MenuPremios").addClass("seleccionaP");
                lineaMenu(174);
                lineaMenu("vuelve");
            }
            else if ( posL == 174 )
            {
                lineaMenu('limpia');
                $("#MenuContactos").addClass("seleccionaCo");
                lineaMenu(238);
                lineaMenu("vuelve");
            }
        }
    });

// Seccion 2 ... izquierda
    $(".slideSec2Izq").hover(function(){
        $(".slideSec2Izq .textoSec2").css("color","#E9193A");
        lineaMenu("vuelve");
    },function(){
        $(".slideSec2Izq .textoSec2").css("color","#000000");
    });
    $(".slideSec2Izq").stop().click(function(){
        posi = parseInt($("#pasad").css("margin-left"));
        if( posi >= 0 )
        {
            $(".simulaWindow:first").animate({marginLeft:0},400,function(){}); // Mueve seccion 2 a seccion 1.
            $(".lineaRoj").animate({marginLeft:4000},400,function(){});
            sec = $("#estoy").text('home');
            lineaMenu("color");
            lineaMenu("limpia");
            lineaMenu("vuelve");
        }
        else
        {
            $("#pasad").animate({"marginLeft":'+=656px'},1000,function(){});
            posL = parseInt($(".seguiMenu").css("margin-left"));
            if ( posL == 238 )
            {
                lineaMenu('limpia');
                $("#MenuPremios").addClass("seleccionaP");
                lineaMenu(174);
                lineaMenu("vuelve");
            }
            else if ( posL == 174 )
            {
                lineaMenu('limpia');
                $("#MenuCuentas").addClass("seleccionaCu");
                lineaMenu(109);
                lineaMenu("vuelve");
            }
            else if ( posL == 109 )
            {
                lineaMenu('limpia');
                $("#MenuAgencia").addClass("seleccionaA");
                lineaMenu(38);
                lineaMenu("vuelve");
            }
        }
    });
// ˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇConfiguracion MENU ˇˇˇ
    // SOBRE
    $("#MenuAgencia").hover(function(){
        $(this).addClass("mdsAC");
        $(this).removeClass("mdsA");
        lineaMenu(38);
    },function(){
        $(this).addClass("mdsA");
        $(this).removeClass("mdsAC");
        lineaMenu("vuelve");
    });
    
    $("#MenuCuentas").hover(function(){
        $(this).addClass("mdsCuC");
        $(this).removeClass("mdsCu");
        lineaMenu(109);
    },function(){
        $(this).addClass("mdsCu");
        $(this).removeClass("mdsCuC");
        lineaMenu("vuelve");
    });
    
    $("#MenuPremios").hover(function(){
        $(this).addClass("mdsPC");
        $(this).removeClass("mdsP");
        lineaMenu(174);
    },function(){
        $(this).addClass("mdsP");
        $(this).removeClass("mdsPC");
        lineaMenu("vuelve");
    });
    
    $("#MenuContactos").hover(function(){
        $(this).addClass("mdsCoC");
        $(this).removeClass("mdsCo");
        lineaMenu(238);
    },function(){
        $(this).addClass("mdsCo");
        $(this).removeClass("mdsCoC");
        lineaMenu("vuelve");
    });
    
    // CLICK
    $("#MenuAgencia").click(function(){
        lineaMenu("limpia")
        $(this).addClass("seleccionaA");
        $("#pasad").animate({"marginLeft":'0px'},1000,function(){});
        chequeaHome();
    });
    
    $("#MenuCuentas").click(function(){
        lineaMenu("limpia")
        $(this).addClass("seleccionaCu");
        $("#pasad").animate({"marginLeft":'-656px'},1000,function(){});
        chequeaHome();
    });
    
    $("#MenuPremios").click(function(){
        lineaMenu("limpia")
        $(this).addClass("seleccionaP");
        $("#pasad").animate({"marginLeft":'-1312px'},1000,function(){});
        chequeaHome();
    });
    
    $("#MenuContactos").click(function(){
        lineaMenu("limpia")
        $(this).addClass("seleccionaCo");
        $("#pasad").animate({"marginLeft":'-1968px'},1000,function(){});
        chequeaHome();
    });
    
    // Efecto al pasar el ratoncin
    $(".contCuentas div, .contPremios div").fadeTo(600,0.6);
    $(".contCuentas div, .contPremios div").hover(function(){
        $(this).stop().fadeTo(600,1);
    },function(){
        $(this).stop().fadeTo(600,0.6);
    });
    
});

function lineaMenu(h)
{
    if(h != "vuelve" && h != "limpia" && h != "color")
    {
        $(".seguiMenu").stop().animate({marginLeft:h},300);
    }
    else if(h == "vuelve")
    {
        vuelvea = $("div[class*=selecciona]").attr('id');
        if(vuelvea == "MenuAgencia")
        {
            $(".seguiMenu").stop().animate({marginLeft:38},300);
            $(".slideSec2Izq .textoSec2").html("home");
            $(".slideSec2Der .textoSec2").html("cuentas");
        }
        else if(vuelvea == "MenuCuentas")
        {
            $(".seguiMenu").stop().animate({marginLeft:109},300);
            $(".slideSec2Izq .textoSec2").html("la agencia");
            $(".slideSec2Der .textoSec2").html("premios");
        }
        else if(vuelvea == "MenuPremios")
        {
            $(".seguiMenu").stop().animate({marginLeft:174},300);
            $(".slideSec2Izq .textoSec2").html("cuentas");
            $(".slideSec2Der .textoSec2").html("contactos");
        }
        if(vuelvea == "MenuContactos")
        {
            $(".seguiMenu").stop().animate({marginLeft:238},300);
            $(".slideSec2Izq .textoSec2").html("premios");
            $(".slideSec2Der .textoSec2").html("home");
        }
    }
    else if(h == "limpia")
    {
        $("#MenuAgencia").removeClass("seleccionaA");
        $("#MenuCuentas").removeClass("seleccionaCu");
        $("#MenuPremios").removeClass("seleccionaP");
        $("#MenuContactos").removeClass("seleccionaCo");
    }
    else if(h == "color")
    {
        sec = $("#estoy").text();
        if(sec == "home")
        {
            $(".seguiMenu").css("background-color","#1b1919");
        }
        else
        {
            $(".seguiMenu").css("background-color","#e9193a");
        }
    }
}
function maketaSeccion()
{
    /* SLIDE DERECHA ! */   
    tamVentana = parseInt($(window).width())+17;  // Tama. de la ventan
    tamContenedor = parseInt($(".contenedor").width()); // Tama. contenedor
    tamVentanaAncho = parseInt($(window).height()) /2;
    tamContenedorAncho = parseInt($(".contenedor").height())/2;
    
    mitadPantalla = Math.round(tamVentana / 2); // Mitad de pantalla
    mitadContenedor = Math.round(tamContenedor / 2); // Mitad de contenedor

    margenSobrante = mitadPantalla-mitadContenedor; // Guardo el margen que va a tener el contenedor para usarlo despues en el conector.
    $(".contenedor, .footer div").css({"margin-left":margenSobrante}); //centra Contenedor | mitad de pantalla - mitad de contenedor |

    //alert($(".contenedor").css("margin-left"));
    
    $(".lineaRoj").css({'margin-left':tamVentana});
    $(".seccionHome,.seccionMenu,.menu,.simulaWindow,").width(tamVentana);
    $(".cs").width(tamVentana*2);
}

function animacionS2(sec)
{
    
    margenSobrante = parseInt($(".contenedor").css("margin-left")); // Vuelve a calcular el margin left.
    //alert(margenSobrante);
    // ANIMACION SEGUNDA PARTE
    $(".simulaWindow:first").animate({marginLeft:-1366},400); // Mueve seccion 1 a seccion 2.
        
    
    $("#conect").css({"margin-left":-margenSobrante,"background-position": "-"+ (3000 - (margenSobrante +112) )+"px 0"});
    // Mueve linea 
    $(".lineaRoj").animate({marginLeft:0},900,function(){
        // Posiciona linea conectora
        $("#conect").animate({"width": margenSobrante + 112},1000,function(){        
                $(".slogan").fadeIn(300,function(){
                    $(".conectorChacoo").animate({"width":192},800,function(){
                        $(".mTwitter").animate({marginTop:51},1800,'easeOutBounce',function(){});
                        setTimeout('$(".mFacebook").animate({marginTop:57},1700,\'easeOutBounce\',function(){});',300);
                        setTimeout('$(".mBlog").animate({marginTop:57},1800,\'easeOutBounce\',function(){});',400);
                        setTimeout('$(".mGoogle").animate({marginTop:57},1800,\'easeOutBounce\',function(){});',500);
                    });
                });
        });// Fin Posiciona linea conectora
    }); // Fin linea roja
}

function animacionS3(sec)
{
    if( $("#estoy").html() == "color" )
    {
        margenSobrante = parseInt($(".contenedor").css("margin-left")); // Vuelve a calcular el margin left.
        //alert(margenSobrante);
        // ANIMACION SEGUNDA PARTE
        $(".simulaWindow:first").animate({marginLeft:-1366},400); // Mueve seccion 1 a seccion 2.
            
        
        $("#conect").css({"margin-left":-margenSobrante,"background-position": "-"+ (3000 - (margenSobrante +112) )+"px 0"});
        // Mueve linea 
        $(".lineaRoj").animate({marginLeft:0},1,function(){
            // Posiciona linea conectora
            $("#conect").animate({"width": margenSobrante + 112},10,function(){        
                    $(".slogan").fadeIn(300,function(){
                        $(".conectorChacoo").animate({"width":192},800,function(){
                            $(".mTwitter").animate({marginTop:51},1800,'easeOutBounce',function(){});
                            setTimeout('$(".mFacebook").animate({marginTop:57},1700,\'easeOutBounce\',function(){});',300);
                            setTimeout('$(".mBlog").animate({marginTop:57},1800,\'easeOutBounce\',function(){});',400);
                            setTimeout('$(".mGoogle").animate({marginTop:57},1800,\'easeOutBounce\',function(){});',500);
                        });
                    });
            });// Fin Posiciona linea conectora
        }); // Fin linea roja
    }
}
function comienzaGlobs()
{
    // ˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇConfiguracion TOOLTIPS HOME ˇˇˇ
//
//$(".persig").each(function(a){
//    toolt ='<div class="floatLeft datosTip oculto" style="margin-left:'+ (parseInt($(this).width())+9 )+'px !important;margin-top:-64px !important;">\
//    <div class="positionAbsolute pikitoDato"></div>\
//    <div class="tituloDAto floatLeft futuraLight typeface-js">'+$(this).find(".persRedL").html()+'</div>\
//    <div class="clearBoth"></div>\
//    <div class="cantDAto floatLeft futuraLight typeface-js">'+$(this).find(".persTotalL").html()+'</div>\
//    <div class="clearBoth"></div>\
//    <div class="floatRight usuDato futuraLight typeface-js"> usuarios </div>\
//    <div class="clearBoth"></div>\
//    <div class="floatLeft">\
//        <div class="paisDato floatLeft futuraLight typeface-js"> Argentina </div>\
//        <div class="clearBoth"></div>\
//        <div class="paisDato floatLeft futuraLight typeface-js"> Chile </div>\
//        <div class="clearBoth"></div>\
//        <div class="paisDato floatLeft futuraLight typeface-js"> Uruguay </div>\
//    </div>\
//    <div class="floatLeft">\
//        <div class="paisNDato floatLeft futuraLight typeface-js">'+$(this).find(".persArgentinaL").html()+'</div>\
//        <div class="clearBoth"></div>\
//        <div class="paisNDato floatLeft futuraLight typeface-js">'+$(this).find(".persChileL").html()+'</div>\
//        <div class="clearBoth"></div>\
//        <div class="paisNDato floatLeft futuraLight typeface-js">'+$(this).find(".persUruguayL").html()+'</div>\
//    </div>\
//</div>';
//    $(this).append(toolt);
//});

$(".persig").mouseover(function(){
        $(this).find(".datosTip").stop().show();
    }).mouseout(function(){
        $(this).find(".datosTip").stop().hide();
    });
}
function chequeaHome()
{
    sec = $("#estoy").text();
    if(sec == "home")
    {
        $(".seguiMenu").css("background-color","#1b1919");
        animacionS2();
        $(".seguiMenu").css("background-color","#e9193a");
    }
}

function cargaFlash()
{
    $('#cargaFlash').flash('index.swf');
    //$('#otroBack').flash('destellos.swf');
}
