/** @no_class */

function ventanaFoto (URL, ancho_F, alto_F)
{ 
	alto_V = alto_F + 130;
	ancho_V = ancho_F + 100;
	
	var alto=screen.height
	var ancho=screen.width

	var v_top=(alto/2-alto_V/2)
	var v_left=(ancho/2-ancho_V/2)

	var propiedades=" width = " + ancho_V + " , height = " + alto_V + " , top = " + v_top + " , left = " + v_left

   window.open(URL , "mensaje" , propiedades + " , scrollbars=YES, titlebar=NO") 
}


$(document).ready(function(){
	// Dialog			
	$('#navFotos').dialog({
		autoOpen: false,
		closeOnScape: true,
 		show: 'slide',
		modal: true,
		width: 550,
		height: 550,
		bgiframe: true
	});

	$('#codigoEnviarAamigo').dialog({
		autoOpen: false,
		closeOnScape: true,
 		show: 'slide',
		modal: true,
		width: 550,
		height: 400,
		bgiframe: true
	});

	$('#navFotos').bgiframe();	

	$("div#botonesLateral a").mouseover(function ()
	{
		$(this).removeClass();
		$(this).addClass("botLateralMandaHover");
	});
	
	$("div#botonesLateral a").mouseout(function ()
	{
		$idBot = $(this).attr("rel");
		$(this).removeClass();
		$(this).addClass("botLateralManda" + $idBot);
	});
});

function desplegarDiv()
{
	$('#navFotos').dialog('open');
}

function cerrarDiv()
{
	$('#navFotos').dialog('close');
	$('#contenidoNavFotos').html('');
}

function desplegarEnviar()
{
	$('#codigoEnviarAamigo').dialog('open');
}
function desplegarEnviarPres()
{
	$('#codigoEnviarAamigo').dialog( "option", "height", 570 );
	$('#codigoEnviarAamigo').dialog('open');
}


function cerrarEnviar()
{
	$('#codigoEnviarAamigo').dialog('close');
}


function slideDownDiv(div)
{
	$(div).slideDown();
}
function slideUpDiv(div)
{
	$(div).slideUp();
}

function fadeInDiv(div)
{
	$(div).fadeOut(100);
	$(div).fadeIn(1700);
}

jQuery('html').addClass('oculto');


(function () {
    $.fn.infiniteCarousel = function () {
        function repeat(str, n) {
            return new Array( n + 1 ).join(str);
        }
        
        return this.each(function () {
            // magic!
            var $wrapper = $('> div', this).css('overflow', 'hidden'),
                $slider = $wrapper.find('> ul').width(9999),
                $items = $slider.find('> li'),
                $single = $items.filter(':first')
                
                singleWidth = $single.outerWidth(),
                visible = Math.ceil($wrapper.innerWidth() / singleWidth),
                currentPage = 1,
                pages = Math.ceil($items.length / visible);
                
            /* TASKS */
            
            // 1. pad the pages with empty element if required
            if ($items.length % visible != 0) {
                // pad
                $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
                $items = $slider.find('> li');
            }
            
            // 2. create the carousel padding on left and right (cloned)
            $items.filter(':first').before($items.slice(-visible).clone().addClass('cloned'));
            $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
            $items = $slider.find('> li');
            
            // 3. reset scroll
            $wrapper.scrollLeft(singleWidth * visible);
            
            // 4. paging function
            function gotoPage(page) {
                var dir = page < currentPage ? -1 : 1,
                    n = Math.abs(currentPage - page),
                    left = singleWidth * dir * visible * n;
                
                $wrapper.filter(':not(:animated)').animate({
                    scrollLeft : '+=' + left
                }, 500, function () {
                    // if page == last page - then reset position
                    if (page > pages) {
                        $wrapper.scrollLeft(singleWidth * visible);
                        page = 1;
                    } else if (page == 0) {
                        page = pages;
                        $wrapper.scrollLeft(singleWidth * visible * pages);
                    }
                    
                    currentPage = page;
                });
            }
            
            $(this).bind('goto', function (event, page) {
                gotoPage(page);
            });
            
            $(this).bind('next', function () {
                gotoPage(currentPage + 1);
            });
        });
    };
})(jQuery);

$(document).ready(function () {
    var autoscrolling = true;
    
	jQuery('html').removeClass('oculto');
	
	tiempo = $('.infiniteCarousel').attr("id");
	tiempo = tiempo.substring(4) * 1000;
	
	$('.infiniteCarousel').infiniteCarousel().mouseover(function () {
        autoscrolling = false;
    }).mouseout(function () {
        autoscrolling = true;
    });
    
    setInterval(function () {
        if (autoscrolling) {
            $('.infiniteCarousel').trigger('next');
        }
    }, tiempo);
	
});
