// IE - fix blikajicich backgroundu
eval("try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}");

function execFunction(objName, fncName) {
	eval(objName+"."+fncName);
}

// inicializace boxu s novinkami
function initNewsBox() {
	$("#hp #content #news-box h2, #hp #content #news-box span.perex, #hp #content #news-box p:not(.visible)").hide();
	$("#hp #content #news-box").prepend("<p class='visible btn more'><a href='#' title='Otevřít novinky'><span>Otevřít</span></a></p>");

	$("#hp #content #news-box p.btn a").click( function() {
		if ($("#hp #content #news-box p.btn").hasClass("more")) {
			$("#hp #content #news-box p.btn").removeClass("more").addClass("less");
			$("#hp #content #news-box p.btn a").attr("title","Zavřít novinky");
			$("#hp #content #news-box p.btn a span").text("Zavřít");
			$("#hp #content #news-box h2, #hp #content #news-box span.perex, #hp #content #news-box p:not(.visible)").slideDown();
		}
		else {
			$("#hp #content #news-box p.btn").removeClass("less").addClass("more");
			$("#hp #content #news-box p.btn a").attr("title","Otevřít novinky");
			$("#hp #content #news-box p.btn a span").text("Otevřít");
			$("#hp #content #news-box h2, #hp #content #news-box span.perex, #hp #content #news-box p:not(.visible)").slideUp();
		}
		return false;
	});
}

//inicializace slideshow na HP
function slideShow(objName, timer, lang) {
	this.blockCount = 5;
	this.blockActive = 1;
	this.timer = timer*1000;
	this.timeout = null;
	this.slideStopped = false;
	this.backgrounds = new Array(
		"/img/u/hp/background-01.jpg",
		"/img/" + lang + "/hp/background-02.jpg",
		"/img/u/hp/background-03.jpg",
		"/img/" + lang + "/hp/background-04.jpg",
		"/img/u/hp/background-05.jpg"
		/*"/img/u/hp/background-christmass-1.jpg",
		"/img/u/hp/background-christmass-2.jpg"*/
	)

	this.initSwitch = function() {
		$("#hp #content").append("<div id='slideshow-box'><p><a href='#' title='Předchozí foto' class='previous'><span>Předchozí</span></a> <span class='hidden'>|</span> <a href='#' title='Další foto' class='next'><span>Další</span></a></p></div>");
		$("#hp #content #slideshow-box a").bind("click", function() { return false; });
		
		// uložení všech backgroundů do cache
		for (var i=0; i<this.blockCount; i++) {
				$("#hp #content #slideshow-box").append("<span class='decache' style='background: url(" + this.backgrounds[i] + ")'></span>");
		}

		if (this.blockCount <= 1) return;
		$("#hp #content #slideshow-box a.previous").bind("click", function() { execFunction(objName, "previousBlock()");return false; });
		$("#hp #content #slideshow-box a.next").bind("click", function() { execFunction(objName, "nextBlock()");return false; });

		this.timeout = setInterval( function() { execFunction(objName, "nextBlock()"); } , this.timer);
		$("#hp #content #slideshow-box a").bind("mouseover", function() { clearInterval(eval(objName+".timeout")); });
		$("#hp #content #slideshow-box a").bind("mouseout", function() { eval(objName+".timeout = setInterval( function() { execFunction('"+objName+"', 'nextBlock()'); } , "+objName+".timer)");});
	}

	this.nextBlock = function() {
		var nextBlockId = this.blockActive + 1;
		if (nextBlockId > this.blockCount) {
			nextBlockId = 1;
		}

		$("#p-root").css("background-image","url(" + this.backgrounds[nextBlockId-1] + ")");
		this.blockActive = nextBlockId;
	}
	this.previousBlock = function() {
		var previousBlockId = this.blockActive - 1;
		if (previousBlockId < 1) {
			previousBlockId = this.blockCount;
		}

		$("#p-root").css("background-image","url(" + this.backgrounds[previousBlockId-1] + ")");
		this.blockActive = previousBlockId;
	}
}

//google maps
function getById(id) {
	if(document.getElementById)
		ex=document.getElementById(id);
	else if(document.all)
		ex=document.all[id];
	else
		ex=null;
	return ex;
}

function googleMaps() {
	if (GBrowserIsCompatible()) {
		function createMarker(point,html) {
			var marker = new GMarker(point);
			GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(html);
			});
			return marker;
		}
		var map1 = new GMap2(getById("googleMap1"));
		map1.addControl(new GSmallMapControl());
		map1.addControl(new GMapTypeControl());
		map1.addControl(new GScaleControl());
		var point1 = new GLatLng(50.149539, 14.564028);
		var marker1 = createMarker(point1,'Zámecký areál Ctěnice')
		map1.addOverlay(marker1);
	}
	else {
		alert("Omlouváme se, ale vypadá to, že Váš prohlížeč není kompatibilní s aplikací API Google Maps");
	}
	map1.setCenter(new GLatLng(50.149539, 14.564028), 12);
}

function writeMapContainer() {
	document.writeln('<div id="googleMap1" class="visible"></div>')
}
