/**
 * show / hide filter options
 */
function filter_toggle(filter, toggler, fieldset) {

	/**
	 * switch current status
	 */
	switch (document.getElementById(filter).style.display) {

		/**
		 * filter shown - hide it, change toggler innerHTML and title, hide
		 * fieldset border
		 */
		case "block":
			document.getElementById(filter).style.display = "none";

			document.getElementById(toggler).innerHTML = "+ zobrazit filtr";
			document.getElementById(toggler).title = "Zobrazit možnosti filtrování";
			document.getElementById(toggler).blur();

			document.getElementById(fieldset).style.border = "none";
			document.getElementById(fieldset).style.padding = "0";
			break;

		/**
		 * filter hidden
		 */
		case "none":
			document.getElementById(filter).style.display = "block";

			document.getElementById(toggler).innerHTML = "- schovat filtr";
			document.getElementById(toggler).title = "Schovat možnosti filtrování";
			document.getElementById(toggler).blur();

			document.getElementById(fieldset).style.border = "1px #dedede solid";
			document.getElementById(fieldset).style.padding = "15px";
			break;
	}

	/**
	 * always return false
	 */
	return false;
}


/**
 * function flyer_overlay
 *
 * display overlay with image in the middle
 *
 * @param int image_width "image width in pixels"
 * @param int image_height "image height in pixels"
 * @param strin image_location "image location" 
 */
function flyer_overlay(image_width, image_height, image_location) {
	var width = 0;
	var height = 0;

	/**
	 * get referrer
	 */
	var ref = document.referrer;

	/**
	 * continue only of referrer does not contain "studio54.cz"
	 */
	if (ref.indexOf("djtommyrogers.com") == -1) {

		/**
		 * get window height
		 */
		if (typeof(window.innerWidth) == "number" ) {
			width = window.innerWidth;
			height = window.innerHeight;
		} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
			width = document.documentElement.clientWidth;
			height = document.documentElement.clientHeight;
		} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
			width = document.body.clientWidth;
			height = document.body.clientHeight;
		}

		/**
		 * create overlay above visible page area
		 */
		var overlay = document.createElement("div");
		overlay.style.position = "fixed";
		overlay.style.width = width + "px";
		overlay.style.height = height + "px";
		overlay.style.top = "0";
		overlay.style.left = "0";
		overlay.style.backgroundColor = "#000";
		overlay.style.opacity = "0.7";
		overlay.style.filter = "alpha(opacity=70)";
		overlay.style.cursor = "pointer";
		document.body.appendChild(overlay);

		/**
		 * append banner image
		 */
		var top = (height - image_height) / 2;
		var left = (width - image_width) / 2;
		var banner = document.createElement("img");
		banner.src = image_location;
		banner.style.position = "fixed";
		banner.style.top = (top) + "px";
		banner.style.left = ((left >= 0) ? left : 0) + "px";
		banner.style.border = "1px #fff solid";
		banner.style.zIndex = "500";
		banner.style.cursor = "pointer";
		document.body.appendChild(banner);

		/**
		 * click function for banner and overlay
		 */
		banner.onclick = function() {
			document.body.removeChild(banner);
			document.body.removeChild(overlay);
			document.body.removeChild(close);
		}

		overlay.onclick = function() {
			document.body.removeChild(banner);
			document.body.removeChild(overlay);
			document.body.removeChild(close);
		}
	}
}


var NewsTicker = {

	/**
	 * set some properties...
	 */
	"ticking": null, 
	"current_id": null, 
	"current_index": null, 
	"available": [], 
	"timeout_animation": 500, 
	"timeout_tick": 5000, 

	/**
	 * function move()
	 *
	 *	manually move to next strip
	 *
	 * @param int $id (target strip ID)
	 */
	"move": function(id) {
	
		/**
		 * disable automatic ticking if running
		 */
		if (this.ticking != null) {
		 	clearTimeout(this.ticking);
		 	this.ticking = null;
		}

		/**
		 * tick
		 */
		this.tick(id);
	}, 

	/**
	 * function tick()
	 *
	 *	switch stripes with opacity animation
	 *
	 * @param int $id (target strip ID)
	 */
	"tick": function(id) {

		/**
		 * if something is displayed, hide it (we will set display to none for
		 * MSIE, in all other browsers we can use opacity animation)
		 */
		if (this.current_id != null && id != this.current_id) {
			if ("\v" == "v") {
				$("#nt_" + this.current_id).css("display", "none");
			} else {
				$("#nt_" + this.current_id).animate({opacity: 0}, this.timeout_animation);
			}
		}

		/**
		 * display selected strip, animate for non-MSIE browsers
		 */
		$("#nt_" + id).css("display", "block");
		if ("\v" != "v") $("#nt_" + id).animate({opacity: 1}, this.timeout_animation);

		/**
		 * set currently displayed strip to selected one
		 */
		this.current_id = id;
	}, 

	/**
	 * function autotick()
	 *
	 *	determine next item to display and automatically update
	 */
	"autotick": function() {

		/**
		 * determine key of next strip from array
		 */
		if (this.current_id != null) {
			this.current_index++;
			if (!this.available[this.current_index]) this.current_index = 1;
		} else {
			this.current_index = 1;
		}

		/**
		 * move to next strip
		 */
		this.move(this.available[this.current_index]);		

		/**
		 * call self, set autotick to true
		 */
		this.ticking = setTimeout("NewsTicker.autotick();", this.timeout_tick);
	}
}
