function hotels(id) {
	var maps = [];
	var act_ind = null;
	var act = null;
	var hover = false;

	$('#'+id).find('li').each(function(i){
		var link = $(this).children('a');
		var img = new Image();
		img.src = '/portal/res/img/'+link.attr('class')+'.gif';
		$(img).hide();
		$(this).parent().parent().append(img);
		maps.push(img);
		
		if($(this).hasClass('act')) {
			act_ind = i;
			act = this;
			$(maps[i]).show();
		}
		
		$(this).bind({
			mouseover: function() {
				hover = true;
				$(maps[i]).stop().fadeTo(300, 1);
				if(act != null && this != act){
					$(act).removeClass('act');
					$(maps[act_ind]).stop().fadeTo(300, 0);
				}
			},
			mouseout: function() {
				hover = false;
				$(maps[i]).stop().fadeTo(300, 0);
				if(act != null){
					$(act).addClass('act');
					$(maps[act_ind]).stop().fadeTo(300, 1);
				}
			}
		});
	})
}

function tabs(id, n) {
	var act = null;
	var act_tab = null;
	var tabber = document.createElement('ul');
	$(tabber).addClass('tabber');
	$('#'+id).prepend(tabber);
	$('#'+id + ' > .tab').each(function(i){
		var content = this;
		$(content).hide();
		$(content).children('.header').hide();
		var tab = document.createElement('li');
		var tab_in = document.createElement('span');
		$(tab_in).text($(this).children('.header').text());
		$(tab).append(tab_in);
		$(tabber).append(tab);
		if(i == n){
			act = this;
			act_tab = tab;
		}
		$(tab).bind('click', function(){
			$(act_tab).removeClass('act');
			$(tab).addClass('act');
			act_tab = this;
			$(act).hide();
			$(content).show();
			act = content;
		});
	});
	$(act_tab).addClass('act');
	$(act).show();
}

function carousel(id, time) {
	var n = 0;
	var element = $('#'+id + ' > ul');
	var count = element.children('li').size();
	if(count <= 1)
		return;
	element.css('overflow', 'hidden');
	var width = element.width();
	
	var timer;

	var next = document.createElement('span');
	$(next).addClass('next');
	var prev = document.createElement('span');
	$(prev).addClass('prev');
	$('#'+id).append(next);
	$('#'+id).append(prev);
	element.children('li').each(function(){
		$(this).css({position: 'absolute', top: 0, left: width});
	})
	element.children('li').eq(n).css('left', '0');
	
	function next_el(){
		element.children('li').eq(n).stop().animate({left: -width}, 350);
		n = (n+1)%count;
		element.children('li').eq(n).css({position: 'absolute', top: 0, left: width}).stop().animate({left: '0'}, 350);
	}
	function prev_el(){
		element.children('li').eq(n).stop().animate({left: width}, 350);
		n = (n-1)%count;
		element.children('li').eq(n).css({position: 'absolute', top: 0, left: -width}).stop().animate({left: '0'}, 350);
	}
	function rotate(){
		clearTimeout(timer);
		next_el();
		timer = setTimeout(rotate, time);
	}
	timer = setTimeout(rotate, time);
	
	$(next).bind('click', function(){
		clearTimeout(timer);
		next_el();
		timer = setTimeout(rotate, time);
	});
	
	$(prev).bind('click', function(){
		clearTimeout(timer);
		prev_el();
		timer = setTimeout(rotate, time);
	});	
}

function slideshow(id, time) {
	var n = 0;
	var element = $('#'+id + ' > ul');
	var count = element.children('li').size();
	var fullscreen = new Image();
	$(fullscreen).attr('id', 'img_full');
	$(fullscreen).hide();
	$('body').append(fullscreen);
	var timer;

	var controller = document.createElement('div');
	$(controller).addClass('controller')
	var next = document.createElement('span');
	$(next).addClass('next');
	var prev = document.createElement('span');
	$(prev).addClass('prev');
	var full = document.createElement('span');
	$(full).addClass('full');
	var desc = document.createElement('span');
	$('#'+id).append(controller);
	if(count > 1) {
		$(controller).append(prev);
		$(controller).append(next);
	}
	$(controller).append(full);
	$(controller).append(desc);
	
	function show(i, j){
		clearTimeout(timer);
		$(desc).text(jQuery.trim(element.children('li').eq(i).text()));
		element.children('li').eq(j).css('z-index', 1);
		element.children('li').eq(i).css('z-index', 2).fadeTo(500, 1, function(){
			element.children('li').eq(j).hide();
		});
	}
	$(element).children('li').css('z-index', 1).hide();
	element.children('li').eq(n).show();
	show(n);
	$(full).bind('click', function(){
		fullscreen.src = element.children('li').eq(n).children('img').attr('src');
		$(fullscreen).fadeTo(300, 1);
	});
	$(fullscreen).bind('click', function(){
		$(fullscreen).fadeTo(300, 0, function(){
			$(this).hide();
		});
	});
	if(count <= 1) {
		return;
	}
	function rotate(){
		clearTimeout(timer);
		var old = n;
		n = (n+1)%count;
		show(n, old);
		timer = setTimeout(rotate, time);
	}
	timer = setTimeout(rotate, time);
	
	$(next).bind('click', function(){
		clearTimeout(timer);
		var old = n;
		n = (n+1)%count;
		show(n, old);
		timer = setTimeout(rotate, time);
	});
	
	$(prev).bind('click', function(){
		clearTimeout(timer);
		var old = n;
		n = (n-1)%count;
		show(n, old);
		timer = setTimeout(rotate, time);
	});
}

function main_slideshow(id, time) {
	var n = 0;
	var element = $('#'+id + ' > ul');
	var count = element.children('li').size();
	if(count < 1)
		return;
	var fullscreen = new Image();
	$(fullscreen).attr('id', 'img_full');
	$(fullscreen).hide();
	$('body').append(fullscreen);
	var timer;

	var info = document.createElement('div');
	
	$(info).addClass('info');
	
	$('#top').append(info);
	
	function show(i, j){
		clearTimeout(timer);
		$(info).html(jQuery.trim(element.find('li>div').eq(i).html()));
		element.children('li').eq(j).css('z-index', 1);
		element.children('li').eq(i).css('z-index', 2).fadeTo(500, 1, function(){
			element.children('li').eq(j).hide();
		});
		Cufon.refresh();
	}
	$(element).children('li').css('z-index', 1).hide();
	element.children('li').eq(n).show();
	show(n);
	function rotate(){
		clearTimeout(timer);
		var old = n;
		n = (n+1)%count;
		show(n, old);
		timer = setTimeout(rotate, time);
	}
	if(count <= 1)
		return;
	timer = setTimeout(rotate, time);
	

}

function autoclear(element){
	$(element).each(function(){
		$(element).bind('focus', function(event){
			if(!this.clicked){
				if(!this.defaultTxt)
					this.defaultTxt = $(this).val();
				this.clicked = true;
				$(this).val('');
				$(this).addClass('filled');
			}
		});
		$(element).bind('blur', function(event){
			if($(this).val().length == 0){
				$(this).val(this.defaultTxt);
				this.clicked = false;
				$(this).removeClass('filled');
			}
		});
	});
}

function autosubmit(element){
	$(element).find('select').change(function(){
		$(element).submit();
	});
	$(element).find('input').change(function(){
		$(element).submit();
	});
	$(element).find('textarea').change(function(){
		$(element).submit();
	});
}

function random(elements){
	var str = $.cookie('random_' + elements);
	var arr;
	if(str != null) {
		arr = str.split(',');
	}
	if(str == null || arr.length == $(elements).size()){
		arr = new Array();
	}
	var isn = false;
	var eq;
	while(!isn){
		isn = true;
		eq = Math.floor(Math.random()*$(elements).size());
		for(var i = 0; i < arr.length; ++i){
			if(arr[i] == eq){
				isn = false;
			}
		}
	}
	$(elements).hide();
	$(elements).eq(eq).show();
	arr.push(eq);
	$.cookie('random_' + elements, arr.toString());
}


jQuery(document).ready(function($) {
	$('body').removeClass('nojs');
	$('#top_menu > li').each(function(){
		$(this).bind('mouseenter mouseleave', function(event) {
			$(this).children('div').slideToggle(400);
		});
	});
	$('#top_menu > #res').unbind('mouseenter mouseleave');
	$('#top_menu > #res').bind('click', function(event) {
		$(this).children('div').slideToggle(400);
	});
	$('#top_menu > li > div').bind('click', function(event) {
		event.stopPropagation();
	});
	$('#newsletter').bind('click', function(event) {
		$('#newsletter > form').slideToggle(400);
	});
	$('#newsletter > form').bind('click', function(event) {
		event.stopPropagation();
	});
	
	$('#check_availability').bind('click',function(){
		$("html, body").animate({ scrollTop: 0 }, "slow");
		
		if(!$('#top_menu > #res>div').is(':visible')){
			setTimeout(function () {
				$('#top_menu > #res').trigger('click');
			}, 500);};
		
	});
});
