$(function() {
	$('.thumbnail').click(function(){
		show($(this).attr('id'));
	});
});

if(auto == true){
	$.doTimeout( 'timeout', 4000, function(){
		show_next_tag();
		next();
	});
}

function show(id){
	prev = current;
	current = id;
	
	/*$.scrollTo(85,{duration:500});*/
	
	if($("#banner"+id).length){
		show_next_image();
	} else {
		load_new_image();
	}
}

function next(){
	prev = current;
	if(current == (gallery.length - 1)){
		current = 0;
	} else {
		current++;	
	}
	
	if($("#banner"+current).length){
		show_next_image();	
	} else {
		load_new_image();
	}
}

function show_next_tag(){
	if(currenttag == (tags.length - 1)){
		currenttag = 0;
	} else {
		currenttag++;	
	}
							
	$('#tag-lines').fadeOut(1000,function(){
		$('#tag-lines').html(tags[currenttag]);
		$('#tag-lines').fadeIn(1000);	
	});
}

function show_next_image(){	
	$('#banner-inner img').stop().css('z-index','1');
	$('#banner'+(current)).css('z-index','2');					
	$('#banner'+(current)).fadeIn(2000,function(){
		$('#banner'+(prev)).hide();	
	});
	if(auto == true){		
		$.doTimeout( 'timeout', 4000, function(){
			show_next_tag();
			next();
		});
	}
}

function load_new_image(){	
	var img = new Image();
	
	$(img).load(function () {  
		$(this).hide();
		$('#banner-inner').append(this);
		$('#banner-inner img').stop().css('z-index','1');
		$(this).attr('id', 'banner'+current).css('z-index','2');
		$(this).attr('id', 'banner'+current);
		$(this).fadeIn(2000,function(){
			$('#banner'+(current-1)).hide();	
		});
		if(auto == true){		
			$.doTimeout( 'timeout', 4000, function(){
				show_next_tag();
				next();
			});
		}
	}).attr('src', gallery[current]);
}

$('#rooms').change(function(){
	var rooms = $(this).val();
		
	for (i=1;i<=3;i++){
		if(i<=rooms){
			$('#quick-search #room'+i).show();
		} else {
			$('#quick-search #room'+i).hide();
		}
	}
});
