/**
 * Ticker
 * @param el
 * @returns Ticker
 */
var Ticker = function(el) {
	var interval = null,
	ticker = {
		active: 0,
		constructor: function(el) {
			this.el = el;
			this.items = el.getElements("li");
		},
		tick: function() {
			if (this.active >= this.items.length)
				this.active = 0;
			
			for (var i in this.items) {
				var li = this.items[i];
				if (typeof(li.style) != "undefined") {
					if (i == this.active) {
						li.style.display = "";
					} else {
						li.style.display = "none";
					}
				}
			}
			
			if (this.items.length <= 1)
				this.stop();
			
			this.active++;
		},
		start: function(startLater) {
			if (startLater != true)
				ticker.tick();
			interval = window.setInterval(function() {
				ticker.tick.call(ticker);
			}, 10 * 1000);
		},
		stop: function() {
			if (interval != null) {
				window.clearInterval(interval);
				interval = null;
			}
		}
	};
	ticker.constructor(el);
	ticker.start();
	
	return ticker;
};

var Tip = function(cfg) {
	var o = {
		el: cfg.el,
		overEl: cfg.overEl,
		selector: cfg.selector,
		constructor: function() {
			this.el.style.position = "absolute";
			this.initOverEl();
		},
		initOverEl: function() {
			this.overEl = this.overEl || this.el.getParent("." + this.selector.replace(/^[\.\#]/, "") + "-container");
			this.overEl = this.overEl || this.el.getParent();
			var tip = this;
			this.overEl.addEvents({
				mouseover: function(e) {
					tip.el.style.display = "";
				},
				/*mousemove: function(e) {
					tip.el.style.top = e.event.layerY + "px";
					tip.el.style.left = e.event.layerX + "px";
				},*/
				mouseout: function(e) {
					tip.el.style.display = "none";
				}
			});
			this.el.style.display = "none";
		},
		getMousePosition: function(e) {
			var posx = 0;
			var posy = 0;
			if (!e) var e = window.event;
			if (e.pageX || e.pageY) 	{
				posx = e.pageX;
				posy = e.pageY;
			}
			else if (e.clientX || e.clientY) 	{
				posx = e.clientX + document.body.scrollLeft
					+ document.documentElement.scrollLeft;
				posy = e.clientY + document.body.scrollTop
					+ document.documentElement.scrollTop;
			}

			return {
				x: posx,
				y: posy
			}
		}
	};
	o.constructor();
	return o;
};
var Tips = function(selector) {
	var els = $$(selector);
	
	var o = {
		constructor: function() {
			els.each(function(tipEl) {
				new Tip({selector: selector, el: tipEl}); 
			});
		}
	};
	o.constructor();
	return o;
}

function protectedDownload( blockId ){
	var downloadurl = '/eproweb/download.php';
    var password = prompt("Bitte Passwort eingeben", "");

	if (password != "" && password != null){
		var r = new Request({
			url: downloadurl,
			method: 'post',
			data: "block="+blockId+"&pw="+password,
			onSuccess: function(response) {
				if(response == "200"){
					top.location.href = downloadurl + "?block="+blockId;
				}
				else{
					alert("Das Passwort ist leider falsch");
				}
			}
		});
		r.send();
	}
}
