
/**
 * Interaktivni cenik
 */
function Prices()
{

	var self = this;
	this.params = {};
	this.room = 0;



	this.init = function(params) {
		this.params = params;
		this.updatePrice();
		this.bindRoomClick();
		this.bindGridClick();
	}
	
	
	
	this.bindRoomClick = function(el) {
		$('#prices .rooms a').bind('click', function(a) {
			self.room = $(this).attr('rel');
			self.updatePrice();
			$('li', $(this).parents('ul.rooms')).removeClass('active');
			$(this).parent('li').addClass('active');
		});
	}
	
	
	
	this.bindGridClick = function() {
		$('#prices-grid area').click(function() {
			var a = $(this).attr('class');
			var selected;
			for (season in self.params.seasons) {
				for (i in self.params.seasons[season]) {
					if (a == self.params.seasons[season][i]) {
						selected = season;
						break;
					}
				}
				if (selected) break;
			}
			if (selected) {
				self.params.actualSeason = selected;
				oldSrc = $('#prices .grid-img img').attr('src');
				newSrc = self.params.seasonImg[selected];
				$('#prices .grid-img').css('backgroundImage', 'url(' + self.params.imgDirPath + newSrc + ')');
				$('#prices .grid-img img').fadeOut(150, function() {
					$(this).attr('src', self.params.imgDirPath + newSrc).show();
				});
				self.updatePrice();
			}
		});
	}



	this.renderSlideControl = function() {
		$('#photoslide .slide').each(function(i) {
			$('#photoslide .control').append('<a href="#">' + (i + 1) + '</a>');
		});
		this.updateControl();
	}


	
	this.updateControl = function() {
		$('#photoslide .control a').each(function(i) {
			(step == (i + 1)) ? $(this).addClass('active') : $(this).removeClass('active');
		});
	}


	
	this.updatePrice = function() {
		$('#prices .amount').html('<small>Kč </small>' + this.params.prices[this.params.actualSeason][this.room] + ',&ndash;');
	}

}



/**
 * Photoslide
 */
function Photoslide()
{

	var self = this;
	this.step = 1;
	this.slideTimer;
	


	this.init = function() {
		this.build();
		this.renderControl();
		this.slideTimer = window.setInterval(function() { self.slide(); }, 8 * 1000);
		this.bindControlClick();
	}


	
	this.bindControlClick = function() {
		$('.control a').click(function() {
			clearInterval(self.slideTimer);
			self.slide($(this).text());
		});
	}



	this.slide = function(onStep) {
		slideCount = $('#photoslide .slide').length;
		if (!onStep) {
			onStep = this.step + 1;
		}
		if (onStep == this.step) {
			return;
		}
		if (onStep > slideCount) {
			onStep = 1;
		}
		offset = (this.step - onStep) * 720;
		if ((offset = offset.toString()) > 0) {
			offset = '+' + offset;
		}
		$('#photoslide .slide').animate({
			"left": offset.toString().substr(0, 1) + "=" + offset.toString().substr(1) + "px" // napr. -=720px
		}, 500, 'swing');
		this.step = onStep;
		this.updateControl();
	}
	
	
	
	this.build = function() {
		$('#photoslide .slide').each(function(i) {
			if (i > 0) {
				$(this).css('left', (i * 720) + 'px');
			}
		});
		$('#photoslide .slide').css('top', '0');
	}


	
	this.renderControl = function() {
		$('#photoslide .slide').each(function(i) {
			$('#photoslide .control').append('<a href="#">' + (i + 1) + '</a>');
		});
		this.updateControl();
	}


	
	this.updateControl = function() {
		$('#photoslide .control a').each(function(i) {
			(self.step == (i + 1)) ? $(this).addClass('active') : $(this).removeClass('active');
		});
	}

}



/**
 * Features
 */
function Features()
{
	
	var self = this;
	
	
	
	this.init = function() {
		$('#features .tabs a').click(function() {
			ul = $(this).parent('li').parent('ul');
			prevId = $('a.active', ul).parent('li').attr('class');
			id = $(this).parent('li').attr('class');
			$('#features #' + prevId).hide();
			$('#features #' + id).show();
			$('a', ul).removeClass('active');
			$(this).addClass('active');
			$(this).trigger('blur');
			return false;
		});
	}
}



/**
 * Mapa
 */
function GoogleMap()
{
	
	var self = this;
	this.maximized = false;
	this.map;



	this.init = function() {
		if (!GBrowserIsCompatible()) return;
		container = $('#google-map');
		
		$('#google-map .resize-bar').click(function() {
			if (!container.hasClass('maximized')) {
				self.createMap();
				container.animate({
					width: '730px'
				}, 200, 'swing', function() {
					$(this).addClass('maximized');
				});
			} else {
				container.animate({
					width: '240px'
				}, 200, 'swing', function() {
					$(this).removeClass('maximized');
				});
			}
		});
	}	
	
	
	
	this.createMap = function() {
		if (!self.map) {
			self.map = new GMap2(document.getElementById('map'));
			self.map.addControl(new GSmallMapControl());
			self.map.addControl(new GMapTypeControl());
			self.map.setCenter(new GLatLng(50.228842, 12.874153), 15);
			self.map.enableDoubleClickZoom();
			self.map.enableContinuousZoom();
			self.map.enableScrollWheelZoom();
			self.map.addOverlay(self.createMarker(
				new GLatLng(50.228872, 12.874123),
				new GIcon(G_DEFAULT_ICON),
				'Pension Romania<br /><strong>Zahradní 948/49</strong><br />360 01 Karlovy Vary<br />+420 <strong>353 222 822</strong>'
			));
		}
	}
	
	
	
	this.createMarker = function(point, icon, infoHtml) {
		var marker = new GMarker(point, { icon: icon });
		if (infoHtml) {
			GEvent.addListener(marker, 'click', function() {
				marker.openInfoWindowHtml(infoHtml);
			});
		}
		return marker;
	}

}
