$(document).ready(function() {
		$('#obsah *:first').css('marginTop', 0);

		var wraper = $('#nahlady-obal');
		var thumbs = $('#nahlady');

		$('a:last', wraper).css('margin', 0);

		thumbs.scrollTop(0);

		var maxScrollTop = wraper.height() - thumbs.height();
		var currentScrollTop = thumbs.scrollTop();

		var images = $('img', wraper);
		if (images.length <= 3) {
			$('#hore').css('background', '#974337');
			$('#dole').css('background', '#974337');
		}

		var url = $('img:first', wraper).attr('src');
		url = url.replace('thumb-', '');
		$('#fotografia img').attr('src', url);

		$('#hore').click(function() {
				var currentScrollTop = thumbs.scrollTop();
				currentScrollTop = currentScrollTop - 213;
				if (currentScrollTop % 71 != 0) {
					currentScrollTop = Math.round(currentScrollTop / 71) * 71;
				}

				thumbs.animate({scrollTop: currentScrollTop}, 'slow');
				/*
				if (currentScrollTop <= 0) {
					$('#hore').css('background', '#974337');
				}

				if (currentScrollTop < maxScrollTop) {
					$('#dole').css('background', 'url("grafika/sipky-fotogaleria.png") right top');
				}
				*/
		});

		$('#hore').hover(
			function() {
				$(this).css('backgroundPosition', 'left bottom');
			},
			function() {
				$(this).css('backgroundPosition', 'left top');}
		);

		$('#dole').click(function() {
				var currentScrollTop = thumbs.scrollTop();
				currentScrollTop = currentScrollTop + 216;
				if (currentScrollTop % 71 != 0) {
					currentScrollTop = Math.round(currentScrollTop / 71) * 71;
				}

				thumbs.animate({scrollTop: currentScrollTop}, 'slow');
				/*
				if (currentScrollTop >= maxScrollTop) {
					$('#dole').css('background', '#974337');
				}

				if (currentScrollTop > 0) {
					$('#hore').css('background', 'url("grafika/sipky-fotogaleria.png") left top');
				}
				*/
		});

		$('#dole').hover(
			function() {
				$(this).css('backgroundPosition', 'right bottom');
			},
			function() {
				$(this).css('backgroundPosition', 'right top');}
		);

		images.click(function(e) {
				var url = this.src;
				url = url.replace('thumb-', '');

				var image = new Image();
				image.src = url;
				image.width = 532;
				image.height = 258;

				$('#fotografia').prepend(image);

				$('#fotografia img:last').hide('slow', function() {
						$('#fotografia img:last').remove();
				});

				banner();

				return false;
		});

		var url = document.location.href;
		url += '?module=ph_ticker';

		$.get(url,
			function(data) {
				if (data != 'empty') {
					$('#obal-obsahu').prepend(data);

					$("ul#novinky").liScroll();
				}
			}
		);

		banner();
});

function banner() {
	$('div#fotografia img').each(function() {
			var src = $(this).attr('src');

			if (src.indexOf('maraton-sj') > -1) {
				$(this).addClass('odkaz');
				$(this).attr('title', 'Zobraziť cenník');
				$(this).click(function() {
						window.location = 'http://www.penzionhradbova.sk/sk/cennik-ubytovania-mmm-2011';
						return false;
				});
			}

			if (src.indexOf('en-maraton') > -1) {
				$(this).addClass('odkaz');
				$(this).attr('title', 'Show pricelist');
				$(this).click(function() {
						window.location = 'http://www.penzionhradbova.sk/en/price-list-ipm-2011';
						return false;
				});
			}

			if (src.indexOf('de-maraton') > -1) {
				$(this).addClass('odkaz');
				$(this).attr('title', 'Price list');
				$(this).click(function() {
						window.location = 'http://www.penzionhradbova.sk/de/preisliste-ifm-2011';
						return false;
				});
			}
	});
}

