var effect_durance = 500;
var timer_scroll;

var thumb_current;

var current = 0;

// Gallery Slideshow + Photo Switcher
$(document).ready(function() {
	var gallery =		$('#hotel_gallery');
	var photo =			gallery.find('img.photo');
	var thumbs_panel =	gallery.find('div.thumbnails');
	var thumbs_window =	gallery.find('div.thumbnails_window');
	var thumbs =		gallery.find('a.thumbnail');
	
	// Image Changer
	thumbs.click(function() {
		var thumb = $(this);
		var preloader = new Image();
		var source = thumb.find('img').attr('src').replace(/thumbnail/, 'large');
		
		thumbs.removeClass('active');
		thumb.addClass('active');
		
		preloader.onload = function() {
			photo.fadeIn(effect_durance);
		}
		
		photo.fadeOut(effect_durance, function() {
			photo.attr('src', source);
			preloader.src = source;
		});
		
		return false;
	});
	
	// Scroller
	gallery.find('a.scroll_down').hover(function() {
		startScroll('up');
	}, function() {
		stopScroll();
	});
	
	gallery.find('a.scroll_up').hover(function() {
		startScroll('down');
	}, function() {
		stopScroll();
	});
	
	function startScroll(direction) {
		ih=document.getElementById('hotel_gallery').getElementsByTagName('div')[2].offsetHeight;
		oh=document.getElementById('hotel_gallery').getElementsByTagName('div')[1].offsetHeight;
		timer = setInterval("scrollThumbs('" + direction + "', 4)", 50);
	}
});


function scrollThumbs(direction, step) {
	if(direction == 'up') {
		if(current<((ih-6)*(-1))+oh){
			clearInterval(timer);
			step = 0;
		}
		step *= -1;
	} else {
		if(current >= 0) {
			step = 0;
		}
	}
	
	position = current + step;
	
	//animate($('#slider').get(0), 'style.left', 'px', current, slide_to, 10, 1, 0, false);
	$('#hotel_gallery').find('div.thumbnails').css('top', position);
	
	current = position;
}

function stopScroll() {
	clearInterval(timer);
}