/**
 * function b_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("studio54.cz") == -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 + 30) + "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() {
			window.open("http://buy.ticketsystem.cz/vstupenka/silvestr-new-years-eve-2011-2012");
			document.body.removeChild(banner);
			document.body.removeChild(overlay);
		}

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


SupportSlider = {

	/**
	 * set some properties
	 */
	"moving": false,
	"automove_direction": "left",
	"automove_timeout": 3000,
	"automove_action": null,

	/**
	 * function move()
	 */
	"move": function (direction) {

		/**
		 * get step width, get current list left position, get ammount of list items
		 */
		this.step_width = parseInt($("#support_content a").css("width")) + parseInt($("#support_content a").css("margin-right"));
		this.list_left = parseInt($("#support_content").css("left"));
		this.list_items = $("#support_content").children().length;

		/**
		 * count minimum left position
		 */
		this.min_left = 0 - (this.step_width * (this.list_items - 6) + parseInt($("#support_content a").css("margin-right")));

		/**
		 * switch by direction, count next left position, move if permitted and
		 * not moving right now
		 */
		switch (direction) {
			case "left":
				this.next_left = this.list_left - this.step_width;
				if (this.next_left >= this.min_left && this.moving == false) {
					this.moving = true;
					$("#support_content").animate({left: this.next_left}, 350, function() { SupportSlider.moving = false; })
				}
				break;

			case "right":
				this.next_left = this.list_left + this.step_width;
				if (this.next_left <= 0 && this.moving == false) {
					this.moving = true;
					$("#support_content").animate({left: this.next_left}, 350, function() { SupportSlider.moving = false; })
				}
				break;
		}
	},

	/**
	 * function automove()
	 */
	"automove": function() {

		/**
		 * continue only if there is more than 6 childs in list
		 */
		if ($("#support_content").children().length > 6) {

			/**
			 * determine next automove direction or keep current
			 */
			switch (this.automove_direction) {
				case "left":
					if ((this.list_left - this.step_width) < this.min_left) {
						this.automove_direction = "right";
						this.move(this.automove_direction);
					}
					break;

				case "right":
					if ((this.list_left + this.step_width) > 0) {
						this.automove_direction = "left";
						this.move(this.automove_direction);
					}
					break;
			}

			/**
			 * move item and set timeout
			 */
			this.automove_action = setTimeout("SupportSlider.move('" + this.automove_direction + "'); SupportSlider.automove();", this.automove_timeout);
		}
	}, 

	/**
	 * function stop()
	 */
	"stop": function() {
		clearTimeout(this.automove_action);
		this.automove_action = null;
	}
}


var Paging = {
	"url": null,
	"page_number": null, 
	"total_pages": null, 

	"set": function() {
		var target_page = parseInt(prompt("Přejít na stranu:", ""));
		if (target_page > 0 && target_page <= this.total_pages && this.url != null) window.parent.window.location.href = this.url + "/strana-" + target_page;
	},

	"move": function(code) {
		if (code == 37 && this.page_number > 1) window.parent.window.location.href = this.url + "/strana-" + (this.page_number - 1);
		if (code == 39 && this.page_number < this.total_pages) window.parent.window.location.href = this.url + "/strana-" + (this.page_number + 1);
	}
}

