$(document).ready(function()
{
    //EVENTOS
    $(".gallery_map_link").click(function()
    {
        var index = $(this).attr("index");
        $("#gallery_full").anythingSlider(index);
        $(".gallery_full").css("visibility", "visible");
        $("#gallery_full_overlay").css("visibility", "visible");
        
    });
    
    $("#navigation_close").click(function()
    {
        $(".gallery_full").css("visibility", "hidden");
        $("#gallery_full_overlay").css("visibility", "hidden");
    });
    
    $("#navigation_prev").click(function()
    {
        $("#gallery_full").data('AnythingSlider').goBack()
    });
    
    $("#navigation_next").click(function()
    {
        $("#gallery_full").data('AnythingSlider').goForward()
    });
    
    $(".scroll_up").click(function()
    {
        $(".event_content_wrapper").stop().scrollTo('-=100', 500);
    });
    
    $(".scroll_down").click(function()
    {
        $(".event_content_wrapper").stop().scrollTo('+=100', 500);
    });    
    
    $(".scroll").hide();
    if($(".event_content_p").height() > $(".event_content_wrapper").height())
    {
        $(".scroll").show();
    }
    

    if($("#gallery_full").children().size() > 0 != "")
    {
        $("#gallery_full").anythingSlider({
            buildArrows         : false,
            buildNavigation     : false,
            autoPlay            : false
        });        
    }

    $.supersized({
        slideshow               :   1,		//Slideshow on/off
        autoplay		:   1,		//Slideshow starts playing automatically
        start_slide             :   1,		//Start slide (0 is random)
        random		        :   0,		//Randomize slide order (Ignores start slide)
        slide_interval          :   3000,	//Length between transitions
        transition              :   1, 		//0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
        transition_speed	:   5000,	//Speed of transition
        new_window		:   1,		//Image links open in new window/tab
        pause_hover             :   0,		//Pause slideshow on hover
        keyboard_nav            :   1,		//Keyboard navigation on/off
        performance		:   1,		//0-Normal, 1-Hybrid speed/quality, 2-Optimizes image quality, 3-Optimizes transition speed // (Only works for Firefox/IE, not Webkit)
        image_protect	        :   1,		//Disables image dragging and right click with Javascript
        image_path		:   'img/', //Default image path

        //Size & Position
        min_width		:   0,		//Min width allowed (in pixels)
        min_height		:   0,		//Min height allowed (in pixels)
        vertical_center         :   0,		//Vertically center background
        horizontal_center       :   0,		//Horizontally center background
        fit_portrait            :   1,		//Portrait images will not exceed browser height
        fit_landscape	        :   0,		//Landscape images will not exceed browser width
        
        //Components
        navigation              :   0,		//Slideshow controls on/off
        thumbnail_navigation    :   0,		//Thumbnail navigation
        slide_counter           :   0,		//Display slide numbers
        slide_captions          :   0,		//Slide caption (Pull from "title" in slides array)
        slides : bgImage              
    });       


    //pageWidth = document.body.clientWidth;
    //pageHeight = document.body.clientHeight;
    pageWidth = $(document).width();
    pageHeight = $(document).height();

    if(seccion == "past_productions_detail")
    {
        pageWidth = $(window).width();
        pageHeight = $(window).height();
    }

    $("#ciudades").height(pageHeight);
    
    CityScroll();
    
    if($(".pp_content").length > 0)
    {
        var pp_content_top = $(".pp_content").offset().top;
        var pp_content_height = $(".pp_content").height();
        var new_pp_content_top = pp_content_top + pp_content_height + 25;
        
        //$(".navigation_pp").offset({top: (new_pp_content_top) });
        $(".navigation_pp").css("visibility","visible");    
    }
    
    
    /////////////////////
    //paginado
    ancho_lista = $(".list_container ul:first").width();
    total_listas = $(".list_container ul").length;
    
    $(".main_container .list_container").height($(".list_container ul:first").height());
    $(".list_container ul").each(function(i)
    {
        var left = i * ancho_lista + 50;
        $(this).offset({left: left});
    });
    
    $("#prev").click(function()
    {
        if(lista_x - listas_x_caja < 1)
        {
            lista_x = 2;
            return;
        }                
        VerPagina(lista_x - listas_x_caja);
        lista_x--;
    });
    
    $("#next").click(function()
    {
        VerPagina(lista_x);
        lista_x++;
        
        if(lista_x > total_listas)
        {
            lista_x = total_listas;
            return;
        }                
    });            
    
    CalcularPaginado();
    AjustarFlotantes();
    
    $(window).resize(function()
    {
        //pageWidth = document.body.clientWidth;
        //pageHeight = document.body.clientHeight;
        pageWidth = $(document).width();
        pageHeight = $(document).height();
        
        if(seccion == "past_productions_detail")
        {
            pageWidth = $(window).width();
            pageHeight = $(window).height();
        }        
    
        CalcularPaginado();
        AjustarFlotantes();
    })            
    //////////////////
});

function CalcularPaginado()
{
    if($(".list_container").length == 0) return;

    ancho_caja = $(".seccion").width();
    listas_x_caja = Math.floor(ancho_caja / ancho_lista);
    
    $(".main_container").width(ancho_caja)
    $(".list_container").width(listas_x_caja * ancho_lista)
    
    paginas = Math.ceil(total_listas / listas_x_caja);
    
    
    lista_x = listas_x_caja + Math.ceil(paginas / listas_x_caja);

    if(total_listas == paginas) lista_x = 2;

    if(paginas == 1)
    {
        $(".navigation").hide();
    }
    else
    {
        $(".navigation").show();
    }
}

function VerPagina(pagina)
{
    pagina = pagina - 1; //indice base 0
    $(".list_container").scrollTo("ul:eq(" + pagina + ")", {axis:'x', duration: 0});
}

function AjustarFlotantes()
{
    //alert(pageHeight);
    if(pageHeight < 670) //645
    {
        $("#menu").offset({top:670});
    }
    else
    {
        $("#menu").offset({top:(pageHeight - 50)});
    }
    
    if(pageWidth < 1100)
    {
        $("#vip").offset({left:735});
    }
    else
    {
        $("#vip").css("left","");
    }      
}

function CityScroll()
{
    $("#imgCiudades").offset({top: pageHeight}).show().animate({top: -10}, 4000).delay(30000).animate({top: -pageHeight}, 4000);
    setTimeout("CityScroll()", 39000);
}
