/**
 * Golf Resort js
 * 25.11.09
 */

jQuery(function($) {
	$('#table .items, #gallery .items').hide();
	$('#table h2, #gallery h2').attr('tabindex', 0);
	$('#table h2, #gallery h2').css('cursor', 'pointer');
	
	$('#table h2, #gallery h2').toggle(
		function(){
			$(this).addClass('active').next().show('slow');

			// IE6/7 footer misplaced after showing content
			if ($.browser.msie && ($.browser.version == '7.0' || $.browser.version == '6.0')) {
				var p = $('#contact .left').offset();
				$('#footer .inner').css('position', 'absolute');
				$('#footer .inner').css({
					position: 'static',
					'margin-left': 0,
					'margin-right': 0
				});
				$('#footer').css('padding-left', p.left + 'px');
			}
		},
		function () {
			$(this).removeClass('active').next().hide('slow');
		}
	);

	$('#table h2, #gallery h2').hover(function(){
		if ($(this).hasClass('active')) {
			$(this).addClass('activeover');
		} else {
			$(this).addClass('over');
		}
	}, function(){
		$(this).removeClass('activeover');
		$(this).removeClass('over');
	});
	

	// setup imagemap labels
	var i;
	var td = [];
	$('#table tbody tr').each(function(i){
		i++;
		var content = '<div id="tr' + i + '" class="infobox"><ul>';
		var sold = 0;
		$(this).children().each(function(x) {
			x++;
			
			if (x == 2 && $(this).text() == 'prodáno') {
				sold = 1;
			}
			
			if (x == 4 && sold == 1) return false;

			if (x != 2) content += '<li><em>';
			
			switch (x) {
				case 1:
					content += 'parcela číslo:</em><span class="info"><strong>' + $(this).text() + '</strong></span>';
					break;
				case 3:
					content += 'rozloha:</em><span class="info">' + $(this).html() + '</span>';
					break;
				case 4:
					content += 'cena za m<sup>2</sup>:</em><span class="info">' + $(this).text() + '</span>';
					break;
				case 5:
					content += 'cena:</em><span class="info"><strong>' + $(this).text() + '</strong></span>';
					break;
				default:
			}
			
			if (x != 2) content += '</li>';

		});
		content += '</ul></div>';
		
		$('#imagemap').append(content);
		
		// setup numeric hovers
		$('#imagemap').prepend('<span id="area' + i + '" class="areaid"></span>');

		if (sold == 1) {
			$('#tr' + i).addClass('sold');
		}
	});
	$('#imagemap .infobox').hide();
	$('#imagemap .areaid').hide();
	

	// show imagemap labels
	if($('#imagemap')) {
		$('#imagemap area').each(function() {
	
			$(this).mouseover(function(e) {
				var tr_id = $(this).attr('rel');
				var tr_index = $(this).attr('rel').replace('tr', '');
				$('span#area'+tr_index).show();
				$('#' + tr_id).show();
			});
			
			$(this).mouseout(function(e) {
				var tr_id = $(this).attr('rel');
				var tr_index = $(this).attr('rel').replace('tr', '');
				$('span#area'+tr_index).hide();
				$('#' + tr_id).hide();
			});
			
			$(this).focus(function(e) {
				var tr_id = $(this).attr('rel');
				var tr_index = $(this).attr('rel').replace('tr', '');
				$('span#area'+tr_index).show();
				$('#' + tr_id).show();
			});
			
			$(this).blur(function(e) {
				$('#imagemap .areaid').hide();
				$('#imagemap .infobox').hide();
			});

			$(this).click(function(e) {
				e.preventDefault();
			});
		
		});
	}


	// show map area on table row mousover
	$('#table tr').mouseover(function() {
		var x = $(this).children(":first-child").text();
		$('span#area'+x).show();
	}).mouseout (function() {
		$('#imagemap .areaid').hide();
	});

});
