var Gallery_Current = 1;

$(document).ready(function() {
    
	$.timer({name:"Gallery_Timer", interval: 3}, function(){
		if (Gallery_Current+1 > Gallery_Max) {
			Gallery_Show(1, 'slow');
		} else {
			Gallery_Show(Gallery_Current+1, 'slow')
		}
	});
    
    $('#flash_gallery').mouseover(function(){
		$.stopTimer('Gallery_Timer');
	});
    $('#flash_gallery').mouseout(function(){
		$.runTimer('Gallery_Timer');
	});

    $('#flash_gallery ul.title_gallery li a').hover(
        function(){
            num = parseInt($(this).parent().attr('id').substr(2));

            if (!isNaN(num)) {
                Gallery_Show(num, 'fast');
                $.stopTimer('Gallery_Timer');
            }
        },
        function(){
            //$.runTimer('Gallery_Timer');
        }
    );

    $('#flash_gallery ul.title_gallery li a').click(function(){return false;})

    $('ul.img_gallery .frame').fancybox({
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});

	/*
	$('#flash_gallery ul.title_gallery li').mouseover(function(){
		
		num = parseInt($(this).attr('id').substr(2));
        alert(num);
		if (!isNaN(num)) {
			Gallery_Show(num, 'fast');
			$.stopTimer('Gallery_Timer');
		}
	});
	$('#flash_gallery ul.title_gallery li').mouseout(function(){
		$.runTimer('Gallery_Timer');
	});
    */
	
});


function Gallery_Show(n, speed)
{
	if (Gallery_Current != n) {
		$('#flash_gallery ul.title_gallery li').removeClass('selected');
		$('#tg'+n).addClass('selected');
		$('#ig'+Gallery_Current).hide();
		$('#ig'+n).show();
	} else {
		$('#tg'+n).addClass('selected');
	}
	Gallery_Current = n;
}
