var Site = new Class({
	book: null,
	dp: null,
	loader: null,
	gmap: null,
	recently_viewed: null,
	rv_div: null,
	search_hotels: null,
	popup_ad_displayed: null,
	initialize: function()
	{
		this.book = new Booking;
		this.dp = new DatePicker();
		this.loader = new Loader();
		this.gmap = new GMap();
		this.recently_viewed = [];
		this.search_hotels = [];
		this.popup_ad_displayed = false;
	},
	zoom_image: function(pos, is_obm)
	{
		// get img data
		var img = null;
		var src = null;
		var domain = '';
		if (is_obm)
		{
			img = $('obm_img_' + pos);
			src = img.get('src').replace(/t_/, 'p_');
		}
		else
		{
			img = $('img' + pos);
			src = img.get('src').replace('hotels/100/', 'hotels/org/');
			domain = 'http://' + this.domain;
		}
		// total image count
		hotel_total_images = $$('img.gimg').length;
		// make bg and loading notice
		var bg = new Element('div');
		var s = window.getScrollSize();
		bg.setStyles({'width': s.x + 'px', 'height': s.y + 'px', 'opacity': .8, 'background-color': '#fff', 'z-index': 99});
		$(document.body).grab(bg);
		bg.position();
		var p = new Element('p', {'text': 'loading image...'});
		p.setStyles({'text-align': 'center', 'color': '#333', 'font-size': '12px', 'z-index': 102});
		$(document.body).grab(p);
		p.position();
		//
		if (is_obm)
		{
			var image = new Asset.image(domain + src, {onload: function(){
				p.destroy();
				//
				var div = new Element('div', {'class': 'popimg'});
				var span = new Element('span');
				var a_a = new Element('a', {'href': '#close', 'text': 'close'});
				a_a.addEvent('click', function(){div.dispose();bg.dispose();});
				var a_b = new Element('a', {'href': '#close'});
				a_b.addEvent('click', function(){div.dispose();bg.dispose();});
				//
				span.grab(a_a);
				div.grab(span);
				a_b.grab(image);
				div.grab(a_b);
				$(document.body).grab(div);
				div.position({'position': 'center'});
			}});
			return;
		}
		//
		var image = new Asset.image(domain + src, {onload: function(){
			p.destroy();
			//
			var div = new Element('div', {'class': 'popimg'});
			var span = new Element('span');
			var a_a = new Element('a', {'href': '#close', 'text': 'close'});
			a_a.addEvent('click', function(){div.dispose();bg.dispose();});
			var a_b = new Element('a', {'href': '#close'});
			a_b.addEvent('click', function(){div.dispose();bg.dispose();});
			//
			var ap = new Element('a', {'href': '#previous', 'class': 'previous'});
			var an = new Element('a', {'href': '#next', 'class': 'next'});
			//
			span.grab(a_a);
			div.grab(span);
			div.grab(ap);
			div.grab(an);
			a_b.grab(image);
			div.grab(a_b);
			$(document.body).grab(div);
			div.position({'position': 'center'});
			//
			ap.position({'relativeTo': div, 'position': 'topLeft', 'edge': 'topLeft', 'offset': {'x': 0, 'y': 80}});
			an.position({'relativeTo': div, 'position': 'topRight', 'edge': 'topRight', 'offset': {'x': 0, 'y': 80}});
			ap.setStyle('opacity', .5);
			an.setStyle('opacity', .5);
			//
			ap.addEvent('mouseover', function(){this.setStyle('opacity', 1);});
			an.addEvent('mouseover', function(){this.setStyle('opacity', 1);});
			ap.addEvent('mouseout', function(){this.setStyle('opacity', .5);});
			an.addEvent('mouseout', function(){this.setStyle('opacity', .5);});
			//
			ap.addEvent('click', function(){
				if (pos <= 1) return;
				var pi = new Asset.image(domain + $('img' + (--pos)).get('src').replace('hotels/100/', 'hotels/org/'), {onload: function(){
					a_b.empty();
					a_b.grab(pi);
					//image.src = pi.src;
				}});
			});
			an.addEvent('click', function(){
				if (pos >= hotel_total_images) return;
				var ni = new Asset.image(domain + $('img' + (++pos)).get('src').replace('hotels/100/', 'hotels/org/'), {onload: function(){
					a_b.empty();
					a_b.grab(ni);
					//image.src = ni.src;
				}});
			}.bind(this));
		}});
	},
	show_recently_viewed: function(obj)
	{
		if (this.recently_viewed.length == 0) return;
		if (this.rv_div != null) return;
		this.rv_div = new Element('div', {'class': 'recent-box'});
		this.rv_div.grab(new Element('a', {'href': '#rvb-close', 'class': 'close', 'html': 'Close'}).addEvent('click', function(){
			this.rv_div.dispose();
			this.rv_div = null;
		}.bind(this)));
		var str = '<table cellspacing="5" cellpadding="5" border="0"><tr>';
		var limit = 4;
		for (var i = 0; i < this.recently_viewed.length; i++)
		{
			str += '<td><a href="' + this.urldecode(this.recently_viewed[i][3]) + '"><img src="' + this.urldecode(this.recently_viewed[i][4]) + '" alt="" />' + this.urldecode(this.recently_viewed[i][1]) + ' <span>(' + this.urldecode(this.recently_viewed[i][2]) + ')</span></a></td>';
			if ((i / limit) == 1)
				str += '</tr><tr>';
		}
		str += '</tr></table>';
		this.rv_div.grab(new Element('span', {'html': str}));
		$('toolbar').grab(this.rv_div);
		this.rv_div.position({'relativeTo': obj, 'position': 'bottomRight', 'edge': 'topCenter', 'offset': {'x': 0, 'y': 2}});
	},
	show_micro_hotel_page: function(id, is_obm)
	{
		var pos = this.in_array(id, 0, this.search_hotels);
		if (pos == -1)
		{
			this.loader.show(null, true, null);
			var json = new Request.JSON({url: '/hotels/view-micro/' + id + '/', method: 'get', onSuccess: function(j, t){
				if (j.errno != 0)
				{
					site.loader.show(j.error, false, null);
				}
				else
				{
					//site.loader.hide(true);
					this.make_micro_hotel_page(j.hotel);
					this.search_hotels.push([id, j.hotel]);
				}
			}.bind(this)}).send();
		}
		else
		{
			this.make_micro_hotel_page(this.search_hotels[pos][1]);
		}
	},
	make_micro_hotel_page: function(hotel)
	{
		var fimg = '';
		if (hotel.images.length > 0) fimg = hotel.images[0];
		var imgs = '';
		for (var i = 1; i < hotel.images.length; i++)
		{
			imgs += '<a href="#img' + i + '" onclick="site.swap_image_micro_page(' + i + ');return false;"><img src="' + hotel.images[i] + '" alt="" id="img' + i + '" /></a>';
		}
		var str = '<div class="micro-page"><table cellpadding="0" cellspacing="0" border="0" class="hotel-main-data">\
    	<tr>\
        	<td><img src="' + fimg + '" alt="" id="image" /></td>\
            <td>\
            <div class="md">\
            	<span class="hotel-name">' + hotel.name + '</span> \
            </div>\
            <span style="font-size: 14px;">' + hotel.location + '</span>\
            <div class="text">' + unescape(hotel.text) + '</div>\
            </td>\
        </tr>\
    </table>\
    <div class="gallery">\
    	<p><i>Click images for larger view</i></p>\
    	' + imgs + '\
    </div><div style="text-align: center;margin-top: 10px;"><input type="button" name="bookh" value="Show me more" class="button btn_show_more" onclick="window.location=\'' + hotel.url + '\';" /></div></div>';
		site.loader.show(str, false, null);
		//site.loader.set_position();
	},
	swap_image_micro_page: function(pos)
	{
		$('image').setProperty('src', $('img' + pos).src);
	},
	show_popup_ad: function()
	{
		if (this.popup_ad_displayed == true) return;
		// load images
		var img = new Asset.image('/images/offers/san-antonio-4-3.jpg', {onload: function(){
			//
			var bg = new Element('div');
			var div = new Element('div', {'class': 'popup-hotel-ad'});
			//
			var ac = new Element('a', {'href': '#close', 'html': 'Continue to site'});
			ac.addEvent('click', function(){div.dispose();bg.dispose();});
			//
			var span = new Element('span');
			var a = new Element('a', {'href': '/san-antonio-hotel.htm'});
			a.grab(img);
			span.grab(a);
			div.grab(ac);
			div.grab(span);
			//
			bg.inject($('container'));
			div.inject($('container'));
			var s = window.getScrollSize();
			bg.setStyles({'position': 'absolute', 'width': s.x + 'px', 'height': s.y + 'px', 'top': '0', 'left': '0', 'opacity': .8, 'background-color': '#000', 'z-index': 9998});
			div.position();
		}});
	},
	do_hotel_fb_share: function(url, hname)
	{
		FB.ui({method: 'feed', message: 'Anyone else who would love to be there right now?', link: url, picture: $('img1').src, name: 'Santorini Hotels: ' + hname, description: 'Indulge Now by Santorini Hotels'});
	},
	show_search_more_options: function(a)
	{
		var el = $('more-options');
		if (el.getStyle('display') == 'none')
		{
			el.setStyle('display', 'block');
			a.set('text', 'Less options');
		}
		else
		{
			el.setStyle('display', 'none');
			a.set('text', 'More options');
		}
		a.blur();
	},
	change_pay_amount: function()
	{
		var sp = $('pay_amount');
		var inp = $('pay_amount_inp');
		var a = $('pay_amount_a');
		if (inp.value != '')
		{
			inp.setStyle('display', 'inline');
			sp.setStyle('display', 'none');
		}
	},
	in_array: function(val, j, arr)
	{
		pos = -1;
		for (var i = 0; i < arr.length; i++)
		{
			if (arr[i][j] == val)
			{
				pos = i;
				break;
			}
		}
		return pos;
	},
	make_recently_viewed_quick_list: function()
	{
		var str = '';
		var pos = 0;
		if (this.recently_viewed.length > 3) pos = this.recently_viewed.length - 3;
		for (var i = pos; i < this.recently_viewed.length; i++) str += '<a href="' + this.urldecode(this.recently_viewed[i][3]) + '">' + this.urldecode(this.recently_viewed[i][1]) + '</a>';
		$('rvql').set('html', str);
	},
	swap_section: function(a)
	{
		$$('a.open').each(function(el, i){el.set('class', 'closed');});
		//a.set('class', 'open');
		a.setAttribute('class', 'open');
		a.blur();
		//var section = a.get('href').replace('#', '');
		var section = a.getAttribute('href').replace('#', '');
		$$('div.hnavjs').each(function(el, i){
			if (el.id == 'nav-' + section)
				el.setStyle('display', 'block');
			else
				el.setStyle('display', 'none');
		});
	},
	set_currency: function()
	{
		document.frm_currencies.submit();
	},
	show_room_tip: function(id, a)
	{
		var el = $(id);
		if (el.getStyle('display') == 'none')
		{
			el.setStyle('display', 'block');
			a.innerHTML = '[Close]';
		}
		else
		{
			el.setStyle('display', 'none');
			a.innerHTML = '[More]';
		}
	},
	show_cp: function(hid){
		var win = window.open('/availability/?cmd=children_policy&hid=' + hid, '', 'menubar=no,width=650,height=300,toolbar=no,scrollbars=no');
	},
	show_bpg: function()
	{
		var win = window.open('/availability/?cmd=best_price_guaranteed', '', 'menubar=no,width=420,height=500,toolbar=no,scrollbars=yes');
	},
	urlencode: function(str)
	{
		return (str == '') ? '' : encodeURIComponent(str);
	},
	urldecode: function(str)
	{
		return (str == '') ? '' : decodeURIComponent(str);
	}
});
var Booking = new Class({
	cid: null,
	cod: null,
	adults: null,
	childs: null,
	exec: null,
	hotel_id: null,
	secure_url: null,
	currency: null,
	initialize: function()
	{
		this.exec = false;
	},
	exec_availability: function()
	{
		if (this.exec) this.get_availability();
	},
	get_availability: function()
	{
		var la = $('obm_adults');
		var lc = $('obm_childs');
		var lcval = 0;
		if (lc != null) lcval = lc.options[lc.options.selectedIndex].value;
		if (site.dp.ciel.value == '' || site.dp.coel.value == '')
		{
			alert('Please choose dates first.');
			return;
		}
		if ((site.dp.cal_a.selectedDate.getTime() / 1000) < site.book.hotel_open_date)
		{
			var hod = new Date(site.book.hotel_open_date * 1000);
			alert('Please choose your check-in and check-out dates. \nHotel is closed on current selected dates.\n\nTip: Hotel opens on ' + hod.toDateString());
			return;
		}
		$('avail').innerHTML = '<div id="loader"><p>Please wait, requesting availability...</p><img src="/images/ajax-loader.gif" alt="" /></div>';
		$('avail').style.display = 'block';
		var json = new Request.JSON({url: '/availability/?cmd=check', onSuccess: function(res_obj, res_str){
			if (res_obj.err != 'OK')
			{
				alert(res_obj.error_msg);
				return;
			}
			else
			{
				//alert(res_str);
				//return;
				if (typeof(res_obj.dat.msg) != 'undefined')
				{
					str = '<div id="obmm_error"><p>' + res_obj.dat.msg + '</p></div>';
				}
				else
				{
					if (res_obj.dat.rooms.length == 0)
					{
						str = '<div id="obmm_error"><p>There are no rooms available for the dates you have selected</p></div>';
					}
					else
					{
						var rids = '';
						var opt = '';
						var str = '<form name="form1" id="form1" action="' + this.secure_url + 'availability/?cmd=reserve" method="post">';
						str += '<table cellspacing="4" cellpadding="4" border="0" width="100%"><thead><tr><th>Room type</th><th>Max</th><th>Rate for ' + res_obj.dat.total_days + ' nights</th><th>Nr. rooms</th><th>Reservation</th></tr></thead><tbody>';
						// build html!
						$each(res_obj.dat.rooms, function(room, i){
							var img = '', imgs = '';
							if (room.images.length != 0)
							{
								img = '<img src="' + room.images[0] + '" alt="" style="margin-right: 10px;" />';
								imgs = '<div class="imgs"><p class="inf">Click images to enlarge</p>';
								for (var i = 0; i < room.images.length; i++)
								{
									imgs += '<a href="#simg-' + i + '" onclick="site.zoom_image(' + i + ', true);"><img id="obm_img_' + i + '" src="' + room.images[i] + '" alt="" /></a>';
								}
								imgs += '</div>';
							}
							// cost and discount
							var total_nights_cost = room.availability.currency_user + ' ' + room.availability.total_nights_rate;
							if (room.availability.total_nights_rate != room.availability.rate_no_discount)
							{
								total_nights_cost = '<span class="without-discount">' + room.availability.currency_user + ' ' + room.availability.rate_no_discount + '</span>' + room.availability.currency_user + ' ' + room.availability.total_nights_rate;
							}
							str += '<tr>\
							<td class="aroom">\
							<div class="wrap">\
							<div class="rimg">' + img + '</div>\
							<div class="rinf">\
								<span class="n">' + room.name + '</span>\
								<span class="rr">Rates are per room</span>\
								<span class="ndesc">' + room.desc + '</span>\
								<a href="#mi" class="mi" onclick="site.show_room_tip(\'mi_r_' + room.id + '\',this);">[More]</a>\
							</div>\
							</div>\
							<div class="rtip" id="mi_r_' + room.id + '">\
									' + imgs + '\
									<div class="dat">\
										<p class="p"><b>Facilities:</b> ' + room.facilities + '</p>\
										<p class="p"><b>Breakfast:</b> ' + room.breakfast + '</p>\
									</div>\
								</div>\
							</td>\
							<td class="max"><img src="/images/winnie_' + room.availability.max_persons + '.gif" alt="' + room.availability.max_persons + ' persons maximum" /></td>\
							<td class="rt">' + total_nights_cost + '</td>\
							<td class="rm">';
							opt = '';
							for (var i = 1; i <= room.availability.rooms_available; i++)
							{
								opt += '<option value="' + i + '_' + (room.availability.total_nights_rate * i)  + '_' + (room.availability.total_nights_rate_hotel * i) + '">' + i + ' (' + room.availability.currency_user + ' ' + (room.availability.total_nights_rate * i) + ')</option>';
							}
							str += '<select name="sr_' + room.id + '" id="sr_' + room.id + '"><option value="0">0</option>' + opt + '</select><span class="rl">' + room.availability.rooms_available + ' room(s) left!</span></td>\
							<td class="rv"><input type="button" name="btn_book_' + i + '" value="book this" class="button btn_book_this" onclick="site.book.do_reservation(' + room.id + ', ' + res_obj.dat.adults + ');" />';
							rids = '';
							$each(room.availability.ids, function(id, i){
									rids += id + '_';
							})
							if (rids != '') rids = rids.substr(0, rids.length - 1);
							str += '<input type="hidden" name="sr_' + room.id + '_ids" id="sr_' + room.id + '_ids" value="' + rids + '" />';
							str += '<span class="guaranteed"><a href="#bpg" onclick="site.show_bpg();">Best Price Guaranteed</a></span></td></tr>';
						})
						str += '</tbody></table>';
						str += '<input type="hidden" name="hid" value="' + res_obj.dat.hotel_id + '" />';
						str += '<input type="hidden" name="rsv_cid" value="' + res_obj.dat.cid + '" />';
						str += '<input type="hidden" name="rsv_cod" value="' + res_obj.dat.cod + '" />';
						str += '<input type="hidden" name="adults" id="_omb_adults" value="' + res_obj.dat.adults + '" />';
						str += '<input type="hidden" name="childs" value="' + res_obj.dat.childs + '" />';
						str += '<input type="hidden" name="nights" value="' + res_obj.dat.total_days + '" />';
						str += '<input type="hidden" name="nor" id="nor" value="" />';
						str += '<input type="hidden" name="step" value="1" />';
						str += '<input type="hidden" name="rid" id="rid" value="" />';
						str += '<input type="hidden" name="rids" id="rids" value="" />';
						str += '<input type="hidden" name="cost_user" id="cost_user" value="" />';
						str += '<input type="hidden" name="cost_hotel" id="cost_hotel" value="" />';
						str += '</form>';
					}
				}
				$('avail').innerHTML = str;
				$('avail').style.display = 'block';
			}
		}.bind(this)}).send('hid=' + this.hotel_id + '&cid=' + site.dp.cal_a.selectedDate.format('%Y-%m-%d') + '&cod=' + site.dp.cal_b.selectedDate.format('%Y-%m-%d') + '&adults=' + la.options[la.options.selectedIndex].value + '&childs=' + lcval);
	},
	do_reservation: function(rid, adults)
	{
		var el = $('sr_' + rid);
		var dat = el.options[el.options.selectedIndex].value;
		var arr = dat.split('_');
		if (arr.length == 3)
		{
			$('rid').value = rid;
			$('rids').value = $('sr_' + rid + '_ids').value;
			$('nor').value = arr[0];
			$('cost_user').value = arr[1];
			$('cost_hotel').value = arr[2];
			if (arr[0] > 1) $('_omb_adults').value = adults * arr[0];
			document.form1.submit();
		}
		else
		{
			alert('Please choose number of rooms.');
		}
	},
	auto_start: function(hid)
	{
		//site.swap_section($('a-book'));
		window.location = '#availability_check';
		this.get_availability(hid);
	},
	load_search_results: function()
	{
		var el = $('obm_search');
		var count_el = $('count');
		if (results_.length == 0)
		{
			count_el.set('html', 'Found 0 Hotels');
			return;
		}
		var str = '';
		var total = 0;
		for (var i = 0; i < results_.length; i++)
		{
			var price = results_[i].currency + results_[i].price;
			if (results_[i].discount_price != 0) price = '<span class="offer">&euro;' + results_[i].price + '</span>&euro;'+ results_[i].discount_price;
			var btn = '<input name="btn_book" value="book online" onclick="window.location=\'' + results_[i].url + '\';" class="btn_s_book" type="button" />';
			if (results_[i].obm != 1) btn = '<input name="btn_book" value="request" onclick="window.location=\'' + results_[i].url + '\';" class="btn_s_request" type="button" />';
			//
			var css = 's_e';
			switch (results_[i].rating)
			{
				case 1: css = 's_a';
					break;
				case 2: css = 's_b';
					break;
				case 3: css = 's_c';
					break;
				case 6: css = 's_d';
					break;
			}
			//
			// onclick="site.show_micro_hotel_page(' + results_[i].id + ', 1);"
			str += '<div class="results-hotel">\
                    	<div class="image">\
                        	<a href="' + results_[i].url + '"><img src="/images/hotels/100/' + results_[i].alt_name + '/01.jpg" alt="" /></a>\
                        </div>\
                        <div class="info">\
                        	<div class="hn">\
                            	<a href="' + results_[i].url + '">' + results_[i].name + '</a>\
                                <span class="stars ' + css + '"></span>\
                                <span class="location">' + results_[i].location + '</span>\
							</div>\
                            <p>' + results_[i].text + '</p>\
                            <a href="' + results_[i].url + '" onclick="site.show_micro_hotel_page(' + results_[i].id + ', 1);return false;">Quick view</a>\
                        </div>\
                        <div class="booking">\
                        	<span class="pri"><span>rate per night</span> ' + price + '</span>\
                            ' + btn + '\
                        </div>\
                    </div>';
			total++;
		}
		el.set('html', str);
		count_el.set('html', 'Found ' + total + ' Hotels');
	},
	sort_search_results: function(by, a)
	{
		if (results_.length == 0) return;
		//
		if (typeof(this.sort_el) != 'undefined')
		{
			this.sort_el.setAttribute('class', 'off');
			this.sort_el.innerHTML = this.old_a_text;
		}
		a.setAttribute('class', 'on');
		this.old_a_text = a.innerHTML
		this.sort_el = a;
		//
		if (typeof(this.asc_) == 'undefined') this.asc_ = true;
		/*if (typeof(this.sort_field_) != 'undefined')
		{
			if (this.sort_field_ == by) this.desc_ = (this.desc_) ? false : true;
		}*/
		this.asc_ = (this.asc_) ? false : true;
		this.sort_field_ = by;
		//
		switch(by)
		{
			case 'name':
				results_.sort(this.sort_by('name', this.asc_, function(a){return a.toUpperCase();}));
				(!this.asc_) ? a.innerHTML = a.innerHTML + '&nbsp;&nbsp;[A...Z]' : a.innerHTML = a.innerHTML + '&nbsp;&nbsp;[Z...A]';
				break;
			case 'stars':
				results_.sort(this.sort_by('rating', this.asc_, parseInt));
				(this.asc_) ? a.innerHTML = a.innerHTML + '&nbsp;&nbsp;[2...5]' : a.innerHTML = a.innerHTML + '&nbsp;&nbsp;[5...2]';
				break;
			case 'price':
				results_.sort(this.sort_by('price', this.asc_, parseInt));
				(!this.asc_) ? a.innerHTML = a.innerHTML + '&nbsp;&nbsp;[Low...High]' : a.innerHTML = a.innerHTML + '&nbsp;&nbsp;[High...Low]';
				break;
			case 'location':
				results_.sort(this.sort_by('location', this.asc_, function(a){return a.toUpperCase();}));
				(!this.asc_) ? a.innerHTML = a.innerHTML + '&nbsp;&nbsp;[A...Z]' : a.innerHTML = a.innerHTML + '&nbsp;&nbsp;[Z...A]';
				break;
		}
		this.load_search_results();
	},
	sort_by: function(by, r, p)
	{
		// http://stackoverflow.com/questions/979256/how-to-sort-a-json-array
		r = (r) ? -1 : 1;
		return function(a,b)
		{
			a = a[by];
			b = b[by];
			if (typeof(p) != 'undefined')
			{
				a = p(a);
				b = p(b);
			}
			if (a < b) return r * -1;
			if (a > b) return r * 1;
			return 0;
		}
	}
});
var DatePicker = new Class({
	cal: null,
	ciel: null,
	coel: null,
	cal_a: null,
	cal_b: null,
	initialize: function()
	{
		this.ciel = $('cid');
		this.coel = $('cod');
	},
	init_date_pickers: function()
	{
		if (this.ciel == null && this.coel == null) return;
		this.cal_a = new CalendarEightysix('cid', {'format': '%a %b %d, %Y', 'disallowUserInput': true, 'toggler': 'cii'});
		this.cal_b = new CalendarEightysix('cod', {'format': '%a %b %d, %Y', 'disallowUserInput': true, 'toggler': 'coi'});
		if ((site.book.cid != 0 && site.book.cod != 0) || (site.book.cid != null && site.book.cod != null))
		{
			var nd_a = new Date(site.book.cid * 1000);
			var nd_b = new Date(site.book.cod * 1000);
			//this.cal_a.options.minDate = new Date();
			this.cal_a.setDate(nd_a);
			//this.cal_b.options.minDate = new Date().increment('day', 1);
			this.cal_b.setDate(nd_b);
		}
		else
		{
			var nd_a = new Date().increment('day', 1);
			var nd_b = new Date().increment('day', 2);
			//this.cal_a.options.minDate = new Date();
			this.cal_a.setDate(nd_a);
			//this.cal_b.options.minDate = nd_b;
			this.cal_b.setDate(nd_b);
		}
		this.cal_a.options.pickFunction = function(d){this.adjust_dates();}.bind(this);
		this.cal_b.options.pickFunction = function(d){this.adjust_dates();}.bind(this);
		site.book.exec_availability();
	},
	check_avail: function()
	{
		var la = $('cobm_adults');
		var lc = $('cobm_childs');
		var cr = $('crange');
		var loc = $('loc');
		var type = $('type');
		if (this.ciel.value == '' || this.coel.value == '')
		{
			alert('Please choose dates first.');
			return;
		}
		window.location = '/availability/?cmd=search&cid=' + this.cal_a.selectedDate.format('%Y-%m-%d') + '&cod=' + this.cal_b.selectedDate.format('%Y-%m-%d') + '&adults=' + la.options[la.options.selectedIndex].value + '&childs=' + lc.options[lc.options.selectedIndex].value + '&crange=' + cr.options[cr.options.selectedIndex].value + '&loc=' + loc.options[loc.options.selectedIndex].value + '&type=' + type.options[type.options.selectedIndex].value;
	},
	adjust_dates: function()
	{
		if (this.cal_a == null || this.cal_b == null) return;
		var da = this.cal_a.selectedDate.getTime();
		var db = this.cal_b.selectedDate.getTime();
		var d = null;
		var five_days_diff = da + ((86400 * 5) * 1000);
		if (da >= db)
		{
			d = this.cal_a.selectedDate;
			var nd_b = d.clone().increment('day', 1);
			//dp.cal_b.options.minDate = nd_b;
			this.cal_b.setDate(nd_b);
		}
	}
});
var Loader = new Class({
	el: null,
	el_dat: null,
	el_img: null,
	el_links: null,
	visible: null,
	initialize: function()
	{
		this.el = $('ldr');
		if (this.el != null)
		{
			this.el_msg = $('ldr-msg');
			this.el_img = $('ldr-img');
			this.el_links = $('ldr-a');
			this.visible = false;
		}
	},
	set_content: function(str)
	{
		if (str == null)
			this.el_msg.setProperty('html', 'Please wait...');
		else if (str != 'NOCONTENT')
			this.el_msg.setProperty('html', str);
	},
	attach_content: function(el)
	{
		this.el_msg.grab(el);
	},
	show: function(msg, show_img, links, position)
	{
		this.set_content(msg);
		if (show_img)
		{
			this.el_img.setStyle('display', 'inline');
			this.el_links.setStyle('display', 'none');
		}
		else
		{
			this.el_img.setStyle('display', 'none');
			this.el_links.setStyle('display', 'inline');
			if (links == null)
				this.el_links.set('html', '<a href="#mb-close" onclick="site.loader.hide();">Close</a>');
			else
				this.el_links.set('html', links);
		}
		if (typeof(position) == 'undefined') this.set_position();
		if (!this.visible)
		{
			this.el.setStyle('display', 'block');
			this.visible = true;
		}
	},
	hide: function(clean)
	{
		if (this.visible)
		{
			this.el.setStyle('display', 'none');
			this.visible = false;
		}
		if (clean) this.el_msg.set('html', '');
	},
	set_position: function()
	{
		this.el.position({'position': 'center'});
	}
});
var GMap = new Class({
	gmap: null,
	gmark: null,
	div: null,
	initialize: function()
	{
	},
	show: function(hname, lat, lng)
	{
		this.setup_div();
		if (this.gmap == null)
		{
			var latlng = new google.maps.LatLng(lat, lng);
			this.gmap = new google.maps.Map($('gmap'), {zoom: 13, center: latlng, mapTypeId: google.maps.MapTypeId.SATELLITE});
			this.gmark = new google.maps.Marker({position: latlng, map: this.gmap, title: hname, icon: '/images/gmap/current_hotel_icon.png', shadow: '/images/gmap/current_hotel_shadow.png'});
		}
	},
	setup_div: function()
	{
		if (this.div == null) this.div = $('hotel_gmap');
		this.div.setStyle('display', 'block');
		var ws = window.getSize();
		var ds = this.div.getSize();
		this.div.setStyle('left', (ws.x / 2) - (ds.x / 2) + 'px');
		this.div.setStyle('top', ((ws.y / 2) - (ds.y / 2)) + window.getScroll().y + 'px');
	},
	hide: function()
	{
		this.div.setStyle('display', 'none');
	}
});
var ImageSlider = new Class({
	Implements: Options,
	current_pos: null,
	div: null,
	html: null,
	timer: null,
	initialize: function(options){
		this.setOptions(options);
		this.current_pos = 0;
		this.html = {};
		this.setup();
	},
	setup: function()
	{
		// get main element
		if ((this.div = $(this.options.div)) == null) return;
		this.div.setStyles({'width': this.options.width, 'height': this.options.height});
		// check for items
		if (this.options.items.length <= 0) return;
		//make pager
		this.create_pager();
		// make item html
		this.create_html();
		// add first
		this.move();
		// start timer
		this.start();
	},
	start: function()
	{
		var duration = this.options.duration;
		this.timer = this.move.periodical(duration, this);
	},
	move: function()
	{
		if (this.current_pos >= this.options.items.length) this.current_pos = 0;
		var image = new Asset.image(this.options.items[this.current_pos].img, {onload: function(){
			this.html.img.set('src', image.src);
			this.html.a.set('href', this.options.items[this.current_pos].url);
			this.html.span.set('text', this.options.items[this.current_pos].name);
			this.current_pos++;
		}.bind(this)});
	},
	create_pager: function()
	{
		var p = new Element('div', {'id': 'pager'});
		var a = null;
		for (var i = 0; i < this.options.items.length; i++)
		{
			a = new Element('a', {'href': '#is-' + (i + 1), 'html': i + 1});
			this.add_pager_events(a, i);
			p.grab(a);
		}
		this.div.grab(p);
		p.position({'relativeTo': this.div, 'position': 'bottomLeft', 'edge': 'bottomLeft', 'offset': {'x': 0, 'y': -5}});
	},
	add_pager_events: function(a, i)
	{
		a.addEvent('mouseover', function(){
			this.current_pos = i;
			this.move();
			if (this.timer != null)
			{
				$clear(this.timer);
				this.timer = null;
			}
		}.bind(this));
		a.addEvent('mouseout', function(){
			if (this.timer == null) this.start();
		}.bind(this));
	},
	create_html: function()
	{
		this.html.div = new Element('div', {'class': 'is-box'});
		this.html.a = new Element('a');
		this.html.img = new Element('img');
		this.html.span = new Element('span', {'class': 'is-title'});
		this.html.a.grab(this.html.img);
		this.html.a.grab(new Element('span', {'class': 'is-bg'}));
		this.html.a.grab((new Element('span', {'class': 'is-data'})).grab(this.html.span));
		this.html.div.grab(this.html.a);
		this.div.grab(this.html.div);
	}
});
var WindowBox = new Class({
	win: null,
	wrap: null,
	shd: null,
	fade: null,
	bg: null,
	initialize: function()
	{
		this.create_window();
		this.fade = new Fx.Tween(this.win, {'property': 'opacity', 'duration': 500});
	},
	create_window: function()
	{
		this.win = new Element('div', {'class': 'window'});
		this.wrap = new Element('div', {'class': 'wrap', 'html': ''});
		this.shd = new Element('div', {'class': 'shadow'});
		this.win.grab(this.wrap);
		this.win.grab(this.shd);
		$(document.body).grab(this.win);
	},
	show: function(has_bg, opts)
	{
		if (has_bg)
		{
			var ws = window.getScrollSize();
			this.bg = new Element('div');
			this.bg.setStyles({'width': ws.x, 'height': ws.y, 'background-color': '#000', 'opacity': .5});
			$(document.body).grab(this.bg);
			this.bg.position();
		}
		this.win.setStyle('display', 'block');
		this.position(opts);
	},
	hide: function(clean)
	{
		this.fade.start(1, 0).chain(function(){
			this.win.setStyle('display', 'none');this.fade.set(1);
			if (clean) this.wrap.set('html', '');
			if (this.bg != null)
			{
				this.bg.destroy();
				this.bg = null;
			}
		}.bind(this));
	},
	position: function(opts)
	{
		var sz = this.wrap.getComputedSize();
		this.win.setStyles({'width': sz.totalWidth, 'height': sz.totalHeight});
		this.shd.setStyles({'width': sz.totalWidth + 20, 'height': sz.totalHeight + 20, 'opacity': .2});
		if (typeof(opts) == 'undefined')
			this.win.position();
		else
			this.win.position(opts);
	},
	set_content: function(str)
	{
		this.wrap.set('html', str);
	},
	clear: function()
	{
		this.wrap.empty();
	},
	set_size: function(w, h)
	{
		this.wrap.setStyles({'width': w, 'height': h});
	}
});
var site = null;
window.addEvent('domready', function(){site = new Site();_load();site.dp.init_date_pickers();site.make_recently_viewed_quick_list();site.show_popup_ad();});
