$(document).ready(function() {
	
	// ===================================================================================================
	// Submenu
	// ===================================================================================================
	$("ul#submenu li a").hover(
		function() {
			var img = $(this).attr('rel');
			if(img) {
				$("div#content").html('<p><img src="/media/site/images/'+img+'" alt="" /></p>');
			}
		},
		function() {}
	);
	
	// ===================================================================================================
	// Popups
	// ===================================================================================================
	$("a.popup-link").click(function() {
		$(this).parent().next(".popup-window").show();	
		return false;
	});	
	$('div.popup-window').prepend('<p class="popup-close"><a href="#">Zatvori&nbsp;&nbsp;&nbsp;X</a></p>');
	$('div.popup-window p.popup-close a').click(function() {
		var win = $(this).parent().parent();
		win.hide();		
		return false;
	});
	
	// Pouzdanost popup
	$(".pouzdanost").hover(
		function() {
			$(this).next(".pouzdanost-popup").show();	
			return false;
		},
		function() {
			$(this).next(".pouzdanost-popup").hide();	
			return false;
		}
	);	
	
	// ===================================================================================================
	// Leksikon	
	// ===================================================================================================
	$('div#leksikon ul li a').click(function() {
		var letter = $(this).attr('rel');
		$('div#leksikon div#terms').load('/site/terms_for_letter/'+letter);
		return false;
	});
	
	// ===================================================================================================
	// Search Box
	// ===================================================================================================
	$('form#search-form input#query').click(function() {
		$(this).attr({ value: '' })
	});
	
	// ===================================================================================================
	// Galerije
	// ===================================================================================================
	$('div.gallery img').click(function() {
		var item = $(this).attr('alt');
		var numberOfImages = $('div.gallery div.gallery-links img').length;
		var nextImage = parseInt(item) + 1;
		if(nextImage > numberOfImages) {
			nextImage = 1;
		}
		var prevImage = parseInt(item) - 1;
		if(prevImage < 1) {
			prevImage = numberOfImages;
		}
		$('div.gallery table').hide();
		$('table#gallery-item-'+item).show();
		$('div.gallery div.gallery-links img').attr({ 'src': '/images/bild.gif' });
		$('div.gallery div.gallery-links img[alt='+item+']').attr({ 'src': '/images/bild_gewaehlt.gif' });
		$('div.gallery div.gallery-arrow-links img[src*=vor]').attr({ 'alt': nextImage });
		$('div.gallery div.gallery-arrow-links img[src*=zur]').attr({ 'alt': prevImage });
	});
	$('div.gallery div.gallery-links img').hover(
		function() {
			var img = $(this).attr('src');
			if(img.indexOf('gewaehlt') > 0) {
				$(this).attr({ 'src': '/images/bild_gewaehlt_r.gif' });
			} else {
				$(this).attr({ 'src': '/images/bild_r.gif' });
			}
		},
		function() {
			var img = $(this).attr('src');
			if(img.indexOf('gewaehlt') > 0) {
				$(this).attr({ 'src': '/images/bild_gewaehlt.gif' });
			} else {
				$(this).attr({ 'src': '/images/bild.gif' });
			}
		}
	);
	$('div.gallery div.gallery-arrow-links img').hover(
		function() {
			var img = $(this).attr('src');
			if(img.indexOf('vor') > 0) {
				$(this).attr({ 'src': '/images/bildpfeil_vor_r.gif' });
			} else {
				$(this).attr({ 'src': '/images/bildpfeil_zurueck_r.gif' });
			}
		},
		function() {
			var img = $(this).attr('src');
			if(img.indexOf('vor') > 0) {
				$(this).attr({ 'src': '/images/bildpfeil_vor.gif' });
			} else {
				$(this).attr({ 'src': '/images/bildpfeil_zurueck.gif' });
			}
		}
	);
	
});

var Timeline = {
	showDecade: function(selectedDecade) {
		$('div.timeline-decade', top.document).hide();
		$('div#decade-'+selectedDecade, top.document).show();
	}
};

var Maps = {
	Europe: {
		countries: new Array(null,
			"belgium", "bulgaria", "bosnia_herzegowina", "germany", "denmark",
			"estonia", "finland", "france", "greece", "great_britain",
			"ireland", "italy", "serbia", "croatia", "latvia",
			"macedonia", "netherlands", "norway", "austria", "poland",
			"portugal", "romania", "russia", "slovakia", "slovenia",
			"spain", "sweden", "switzerland", "czechia", "turkey", "ukrain", 
			"hungary", "cyprus", "luxembourg", "lithuania", "belarus", 
			"moldova", "albania", "montenegro", "kosovo"
		),
		highlightMap: function(index) {
			document.getElementById("highlight").src = "/images/maps/europe/europe_"+index+".gif";
		},
		unhighlightMap: function() {
			document.getElementById("highlight").src = "/images/maps/europe/europe_blank.gif";
		},
		showCountry: function(index) {
			alert(Maps.Europe.countries[index]);
		}
	},
	World: {
		continents: new Array(null, "Sjeverna i Srednja Amerika", "Južna Amerika", "Europa", "Afrika", "Azija", "Australija i Oceanija"),
		highlightMap: function(index) {
			document.getElementById("highlight").src = "/images/maps/world/world_"+index+".gif";
		},
		unhighlightMap: function() {
			document.getElementById("highlight").src = "/images/maps/world/world_blank.gif";
		}
	}
};