var EventSlider = Class.create();
EventSlider.prototype = {
	initialize : function() {
	},
	initSuper : function(e, d, b, a, c) {
		this.calendarSize = (b) ? parseInt(b, 10) : 12;
		this.language = (e) ? e : "en";
		this.currentDate = new Date();
		this.month = null;
		this._initMonth();
		this.activeMon = parseInt(this.currentDate.getMonth(), 10) + 1;
		this.activeYear = parseInt(this.currentDate.getFullYear(), 10);
		this.activeMonId = this.activeMon + "-" + this.activeYear;
		this.leftLimit = parseInt(a, 10);
		this.rightLimit = parseInt(c, 10);
		this.leftMonthLimit = null;
		this.timelineArray = null;
		this.timelineIdArray = null;
		this.drag = false;
		this._startX = 0;
		this._startY = 0;
		this._offsetX = 0;
		this._offsetY = 0;
		this._dragElement;
		this._dragLeftElement;
		this._dragRightElement;
		this._oldZIndex = 0;
		this._initRange();
		this._initialHide();
		
		this.redirectUrl = "/investor/";
		switch(location.hostname) {
		case "edit.siemens.dev.publicis.de":
		case "edit.siemens.com":
			this.redirectUrl = "/cc/corp_ir/root/";
			break;
		case "stage.siemens.com":
			this.redirectUrl = "/cc/corp/investor/";
			break;
		default:
			this.redirectUrl = "/investor/";
		}
		
	},
	_initMonth : function() {
		switch (this.language) {
		case "de":
			this.month = new Array("Jan", "Feb", "Mrz", "Apr", "Mai", "Jun",
					"Jul", "Aug", "Sep", "Okt", "Nov", "Dez");
			break;
		case "en":
			this.month = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun",
					"Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
			break
		}
	},
	_initRange : function() {
		var b = 8;
		var a = parseInt(this.activeYear, 10) - 2;
		this.timelineIdArray = new Array();
		$A($R(1, b)).each(function(d) {
			$A($R(1, 12)).each(function(f) {
				var e = f + "-" + a;
				this.timelineIdArray.push(e)
			}.bind(this));
			a++
		}.bind(this));
		var c = this.timelineIdArray.indexOf(this.activeMonId) - 3;
		this.leftMonthLimit = c;
		this.leftMonthOffset = 44;
		this.rightYearLimit = this.activeYear + b - 2;
		this.rightMonthLimit = (b - 1) * 12 + 1;
		this._drawRuler(c);
		this.createSlider()
	},
	_drawRuler : function(c) {
		$("eventruler").update();
		var b = (c + this.calendarSize);
		this.currentRange = $R(c, b);
		for ( var a = c; a < b; a++) {
			this._addMonth(this.timelineIdArray[a], 1)
		}
	},
	_addMonth : function(k, h) {
		var d = k.split("-");
		var l = d[0];
		var i = d[1];
		var a = this.month[l - 1];
		var j = new Element("a", {
			"class" : "eventCalItem",
			id : k
		}).update(a);
		var e = new Element("div", {
			"class" : "eventCalItemHolder"
		}).update(j);
		var b = new Element("div", {
			"class" : "eventCalItemTop"
		}).update('<span class="space">&nbsp;</span>');
		var f = new Element("div", {
			"class" : "eventCalItemBottom"
		}).update('<span class="space">&nbsp;</span>');
		var g = new Element("div", {
			"class" : "eventCalMon"
		});
		if (this._isYearChange(k)) {
			g.addClassName("leftYearBorder");
			var c = new Element("span", {
				"class" : "eventCalItemYear"
			}).update(i);
			b.update(c)
		}
		g.appendChild(b);
		g.appendChild(e);
		g.appendChild(f);
		if (h > 0) {
			$("eventruler").appendChild(g)
		} else {
			Element.insert($("eventruler"), {
				top : g
			})
		}
	},
	_isYearChange : function(a) {
		var d = parseInt(a.split("-")[1], 10);
		var c = this.timelineIdArray.indexOf(a) - 1;
		var b = parseInt(this.timelineIdArray[c].split("-")[1], 10);
		return (d > b) ? true : false
	},
	_isNewYear : function(a) {
		var c = this.timelineIdArray.indexOf(this.activeMonId);
		var b = parseInt(this.timelineIdArray[c].split("-")[1], 10);
		return (a < b && b < this.rightYearLimit) ? true : false
	},
	_isYearBack : function(a) {
		var c = this.timelineIdArray.indexOf(this.activeMonId);
		var b = parseInt(this.timelineIdArray[c].split("-")[1], 10);
		return (a > b) ? true : false
	},
	createSlider : function() {
		var a = "<div id='eventsliderpanelleft' class='drag'><a href='javascript:void(0);' id='slider_left'>&nbsp;</a></div>";
		a += "<div id='eventslider_drag' class='drag'><a href='javascript:void(0);' id='slider_drag'>&nbsp;</a></div>";
		a += "<div id='eventsliderpanelright' class='drag'><a href='javascript:void(0);' id='slider_right'>&nbsp;</a></div>";
		this.slider = new Element("div", {
			id : "eventsliderpanel"
		}).update(a);
		$(this.activeMonId).up().addClassName("active");
		$(this.activeMonId).addClassName("active");
		Element.insert($(this.activeMonId).up(), {
			after : this.slider
		});
		Event.observe($("eventsliderpanelleft"), "click", this.moveSlider
				.bindAsEventListener(this));
		Event.observe($("eventsliderpanelright"), "click", this.moveSlider
				.bindAsEventListener(this));
		this.eventMouseDown = this.startDrag.bindAsEventListener(this);
		this.eventMouseUp = this.endDrag.bindAsEventListener(this);
		this.eventMouseMove = this.update.bindAsEventListener(this);
		this.sliderDrag = $("eventslider_drag");
		Event.observe(this.sliderDrag, "mousedown", this.eventMouseDown);
		//Event.observe(document, "mouseup", this.eventMouseUp);
		Event.observe(this.sliderDrag, "mouseup", this.eventMouseUp);
		Event.observe(document, "mousemove", this.eventMouseMove)
	},
	startDrag : function(b) {
		if (b == null) {
			b = window.event
		}
		var a = Event.findElement(b, "div");
		if ((b.button == 1 && window.event != null || b.button == 0)
				&& a.className == "drag") {
			this._startX = b.clientX;
			this._startY = b.clientY;
			this._offsetX = this.extractNumber(a.style.left);
			this._offsetY = this.extractNumber(a.style.top);
			this._oldZIndex = a.style.zIndex;
			a.style.zIndex = 10000;
			this._dragElement = a;
			this._dragLeftElement = $("eventsliderpanelleft");
			this._dragLeftElement.style.zIndex = 10000;
			this._dragRightElement = $("eventsliderpanelright");
			this._dragRightElement.style.zIndex = 10000;
			document.body.focus();
			document.onselectstart = function() {
				return false
			};
			a.ondragstart = function() {
				return false
			};
			return false
		}
		Event.stop(b)
	},
	update : function(c) {
		if (c == null) {
			var c = window.event
		}
		if (this._dragElement) {
			var b = this._offsetX + c.clientX - this._startX;
			var a = b + "px";
			var d = this._dragElement.cumulativeOffset()[0];
			if (this.leftLimit < d && this.rightLimit + 10 > d) {
				this._dragElement.style.left = a;
				this._dragLeftElement.style.left = a;
				this._dragRightElement.style.left = a
			} else {
				this.endDrag(c)
			}
		}
	},
	endDrag : function(a) {
		if (this._dragElement != null) {
			var b = this._dragElement.cumulativeOffset()[0];
			this._dragElement.style.zIndex = this._oldZIndex;
			Event.findElement(a, "div").stopObserving("mousemove");
			document.onselectstart = null;
			this._dragElement.ondragstart = null;
			this._dragElement = null;
			this._findDropTarget(b)
		}
		Event.stop(a)
	},
	_findDropTarget : function(b, a) {
		$$("div.eventCalItemHolder a.eventCalItem").each(function(e) {
			var c = e.cumulativeOffset()[0];
			var f = c + 42;
			if (c <= b && f > b) {
				this._removeSlider();
				var g = this.timelineIdArray.indexOf(e.id);
				var d = this.timelineIdArray.indexOf(this.activeMonId);
				if (g > d) {
					this._setUp(g)
				} else {
					if (g < d) {
						this._setDown(g)
					} else {
						this._setActiveMon();
						this.createSlider()
					}
				}
				this.showContent()
			}
		}.bind(this))
	},
	extractNumber : function(a) {
		var b = parseInt(a, 10);
		return b == null || isNaN(b) ? 0 : b
	},
	_removeSlider : function() {
		$(this.activeMonId).removeClassName("active");
		$(this.activeMonId).up().removeClassName("active");
		$(this.slider).remove()
	},
	_addSlider : function() {
		$(this.activeMonId).addClassName("active");
		$(this.activeMonId).up().addClassName("active");
		$(this.activeMonId).up().appendChild(this.slider)
	},
	moveSlider : function(b) {
		var a = Event.findElement(b, "div");
		if (a) {
			this._removeSlider();
			if (a.down().id == "slider_left") {
				this._calcUpDown(false)
			} else {
				if (a.down().id == "slider_right") {
					this._calcUpDown(true)
				}
			}
			this.showContent()
		}
	},
	_setUp : function(b) {
		if (b < this.timelineIdArray.length - this.calendarSize) {
			if (b < this.rightMonthLimit) {
				this.activeMonId = this.timelineIdArray[b];
				if (this._isNewYear(this.activeYear)) {
					this._drawRuler(this.timelineIdArray
							.indexOf(this.activeMonId) - 3);
					this._setActiveMon();
					this._hideNonYearContent()
				} else {
					if (b == this.currentRange.end) {
						this._setActiveMon();
						this._hideNonYearContent();
						var a = this.timelineIdArray.indexOf(this.activeMonId)
								- this.calendarSize + 1;
						this._drawRuler(a)
					}
				}
			} else {
			}
		}
		this._setActiveMon();
		this.createSlider()
	},
	_setDown : function(b) {
		if (b > 1) {
			if (b >= this.leftMonthLimit) {
				this.activeMonId = this.timelineIdArray[b];
				if (this._isYearBack(this.activeYear)) {
					var a = this.timelineIdArray.indexOf(this.activeMonId)
							- this.calendarSize + 3;
					this._drawRuler(a);
					this._setActiveMon();
					this._hideNonYearContent()
				} else {
					if (b == this.currentRange.start) {
						this._setActiveMon();
						this._hideNonYearContent();
						var a = this.timelineIdArray.indexOf(this.activeMonId) - 1;
						this._drawRuler(a)
					}
				}
			} else {
				this.activeMonId = this.timelineIdArray[b];
				this._setActiveMon();
				this._hideNonYearContent();
				this
						._drawRuler(this.timelineIdArray
								.indexOf(this.activeMonId) - 1)
			}
		}
		this._setActiveMon();
		this.createSlider()
	},
	_setActiveMon : function() {
		var a = this.activeMonId.split("-");
		this.activeMon = parseInt(a[0], 10);
		this.activeYear = parseInt(a[1], 10)
	},
	_setPosition : function(b) {
		this.activeMonId = b;
		this._setActiveMon();
		this._hideNonYearContent();
		var a = this.timelineIdArray.indexOf(this.activeMonId)
				- this.calendarSize + 1;
		this._drawRuler(a);
		this.createSlider()
	},
	_calcUpDown : function(a) {
		if (a) {
			var b = this.timelineIdArray.indexOf(this.activeMonId) + 1;
			this._setUp(b)
		} else {
			var b = this.timelineIdArray.indexOf(this.activeMonId) - 1;
			this._setDown(b)
		}
	},
	showContent : function() {
	},
	createContent : function(a) {
	},
	_setNavigationLinks : function() {
	},
	_hideNonYearContent : function() {
	},
	_initialHide : function() {
	}
};
var SmallIREventSlider = Class.create();
SmallIREventSlider.prototype = Object
		.extend(
				new EventSlider,
				{
					initialize : function(e, d, b, a, c) {
						this.initSuper(e, d, b, a, c);
						this.data = null;
						
						new Ajax.Request(this.redirectUrl + this.language
								+ "/data/events.xml", {
							method : "get",
							onSuccess : this._loadContent.bind(this),
							onFailure : function(f) {
							}
						})
					},
					_loadContent : function(a) {
						var b = a.responseXML.documentElement;
						this.data = $A(b.getElementsByTagName("event"));
						this.showContent()
					},
					_getAttribute : function(b, a) {
						return (b.attributes.getNamedItem(a)) ? b.attributes
								.getNamedItem(a).nodeValue : "&#160;"
					},
					showContent : function() {
						var d = false;
						$("eventbodycontent").update();
						if ($("eventheadline")) {
							$("eventheadline").remove()
						}
						this.data
								.each(function(h) {
									var f = h.attributes.getNamedItem("date").nodeValue;
									if (this._compare(f, this.activeMon)) {
										d = true;
										var e = new Element("a", {
											"class" : "ir_collapsed"
										}).update(f
												+ "&#160;|&#160;"
												+ this
														._getAttribute(h,
																"title"));
										var g = this._getAttribute(h, "key");
										Event.observe(e, "click", function(j) {
											this.jumpToCalendar(g);
											Event.stop(j)
										}.bindAsEventListener(this));
										var i = new Element("p", {
											"class" : "eventline"
										}).update(e);
										$("eventbodycontent").appendChild(i)
									}
								}.bind(this));
						if (d) {
							var a = (this.language == "de") ? "<p>Events</p>"
									: "<p>Events</p>";
							var c = new Element("div", {
								"class" : "p clearfix"
							}).update(a);
							var b = new Element("div", {
								id : "eventheadline"
							}).update(c);
							Element.insert($("eventbodycontent"), {
								before : b
							})
						}
					},
					_compare : function(d, c) {
						var b = parseInt(d.substring(0, 4), 10);
						var a = parseInt(d.substring(5, 7), 10);
						return (b == this.activeYear && a == c) ? true : false
					},
					jumpToCalendar : function(a) {
						if (this.language == "de") {
							window.location.href = this.redirectUrl
									+ "de/finanzpublikationen_events/finanzkalender.htm?key="
									+ a + "&id=" + this.activeMonId
						} else {
							window.location.href = this.redirectUrl
									+ "en/publications_events/financial_calendar.htm?key="
									+ a + "&id=" + this.activeMonId
						}
					}
				});
var MediumIREventSlider = Class.create();
MediumIREventSlider.prototype = Object
		.extend(
				new EventSlider,
				{
					initialize : function(e, d, b, a, c) {
						this.initSuper(e, d, b, a, c);
						this.data = null;
						this._navigateTo();
						new Ajax.Request(this.redirectUrl + this.language
								+ "/data/events.xml", {
							method : "get",
							onSuccess : this._loadContent.bind(this),
							onFailure : function(f) {
							}
						})
					},
					_loadContent : function(a) {
						var b = a.responseXML.documentElement;
						this.data = $A(b.getElementsByTagName("event"));
						this.showContent()
					},
					_navigateTo : function() {
						var a = getUrlParameter("id");
						if (a) {
							this._setPosition(a)
						}
					},
					_showKey : function() {
						var b = getUrlParameter("key");
						if (b) {
							var c = "linkblock" + b;
							var a = "block" + b;
							if ($(a)) {
								showItem(a, c)
							}
						}
					},
					_getAttribute : function(b, a) {
						return (b.attributes.getNamedItem(a)) ? b.attributes
								.getNamedItem(a).nodeValue : "&#160;"
					},
					showContent : function() {
						var d = false;
						$("eventbodycontent").update();
						if ($("eventheadline")) {
							$("eventheadline").remove()
						}
						this.data
								.each(function(u) {
									var m = u.attributes.getNamedItem("date").nodeValue;
									if (this._compare(m, this.activeMon)) {
										d = true;
										var r = this._getAttribute(u, "key");
										var i = "block" + r;
										var s = "link" + i;
										var p = this._getAttribute(u, "title");
										var h = new Element("a", {
											"class" : "ir_collapsed",
											id : s
										}).update(m + "&#160;|&#160;" + p);
										Event.observe(h, "click", function(v) {
											showItem(i, Event.findElement(v,
													"a"));
											Event.stop(v)
										}.bindAsEventListener(this));
										var f = new Element("p", {
											"class" : "eventline"
										}).update(h);
										$("eventbodycontent").appendChild(f);
										var q = new Element("p")
												.update(this._getAttribute(u,
														"description"));
										var j = new Element("div", {
											"class" : "expandcontent",
											id : i
										}).update(q);
										var l = $A(u
												.getElementsByTagName("link"));
										var g = new Element("ul", {
											"class" : "link"
										});
										l.each(function(y) {
											var w = "javascript:openWindow('"
													+ this._getAttribute(y,
															"link") + "')";
											var v = new Element("li");
											var x = new Element("a", {
												"class" : "external",
												href : w
											}).update(this._getAttribute(y,
													"title"));
											v.update(x);
											g.appendChild(v)
										}.bind(this));
										var k = new Element("div", {
											"class" : "list quick-links"
										}).update(g);
										j.appendChild(k);
										var e = $A(u
												.getElementsByTagName("download"));
										var t = new Element("ul", {
											"class" : "link"
										});
										e.each(function(C) {
											var y = this
													._getAttribute(C, "url");
											var A = this._getAttribute(C,
													"type");
											var B = "external";
											switch (A) {
											case "pdf":
												B = "pdf";
												break;
											case "zip":
												B = "zip";
												break;
											case "doc":
												B = "doc";
												break;
											case "xls":
												B = "xls";
												break;
											case "ppt":
												B = "ppt";
												break;
											case "pps":
												B = "ppt";
												break
											}
											var x = parseInt(this
													._getAttribute(C, "size"),
													10);
											x = (x > 1024) ? "&#160;&#91;"
													+ Math.round(x * 10 / 1024)
													/ 10 + "&#160;MB&#93;"
													: "&#160;&#91;" + x
															+ "&#160;KB&#93;";
											var w = this._getAttribute(C,
													"title")
													+ x;
											var v = new Element("li");
											var z = new Element("a", {
												"class" : B,
												href : y
											}).update(w);
											v.update(z);
											t.appendChild(v)
										}.bind(this));
										var o = new Element("div", {
											"class" : "list quick-links"
										}).update(t);
										j.appendChild(o);
										j.hide();
										if (this._isFutureEvent(m)) {
											j.appendChild(this._createMailForm(
													p, r, m))
										}
										$("eventbodycontent").appendChild(j);
										var n = "submitForm-" + r;
										if ($(n)) {
											Event
													.observe(
															$(n),
															"click",
															function(v) {
																this
																		.submitMailForm(r);
																Event.stop(v)
															}
																	.bindAsEventListener(this))
										}
									}
								}.bind(this));
						if (d) {
							var a = (this.language == "de") ? "<p>Events</p>"
									: "<p>Events</p>";
							var c = new Element("div", {
								"class" : "p clearfix"
							}).update(a);
							var b = new Element("div", {
								id : "eventheadline"
							}).update(c);
							Element.insert($("eventbodycontent"), {
								before : b
							});
							this._showKey()
						}
					},
					_compare : function(d, c) {
						var b = parseInt(d.substring(0, 4), 10);
						var a = parseInt(d.substring(5, 7), 10);
						return (b == this.activeYear && a == c) ? true : false
					},
					_isFutureEvent : function(i) {
						var c = i.split("-");
						var b = parseInt(c[2], 10);
						var g = parseInt(c[1], 10);
						var f = parseInt(c[0], 10);
						var h = parseInt(this.currentDate.getDate(), 10);
						var e = parseInt(this.currentDate.getMonth(), 10) + 1;
						var a = this.currentDate.getYear();
						if (a < 999) {
							a += 1900
						}
						return ((f > a) || ((g > e) && (f == a)) || ((b > h)
								&& (g == e) && (f == a))) ? true : false
					},
					_createMailForm : function(g, d, f) {
						var a = "remindMe-" + d;
						var e = "remindevent-" + d;
						var b = "submitForm-" + d;
						var c = '<form id="' + e + '" class="remindevent" action="" enctype="application/x-www-form-urlencoded" method="post">';
						c += '<input type="HIDDEN" name="lang" value="' + this.language + '" >';
						c += '<input type="HIDDEN" name="Event" value="' + g + '" >';
						c += '<input type="HIDDEN" name="EventDate" value="' + f + '" >';
						if (this.language == "de") {
							c += '<div class="first"><span class="target">E-Mail Erinnerung</span>';
							c += '<select name="EventDay" id="daysbefore" class="gui-select"><option value="1">1 Tag</option><option value="3">3 Tage</option><option value="7">7 Tage</option></select></div>';
							c += '<div class="second"><span class="target"> im Voraus</span></div><div class="first"><span class="target">E-Mail</span><input name="email" id="emailaddress" value="" type="text"></div>';
							c += '<div class="third"><a id="' + b + '" class="generic-button" href="javascript:void(0);"><span><span>Senden</span></span></a></div></form>'
						} else {
							c += '<div class="first"><span class="target">E-Mail for this event</span>';
							c += '<select name="EventDay" id="daysbefore" class="gui-select"><option value="1">1 Day</option><option value="3">3 Days</option><option value="7">7 Days</option></select></div>';
							c += '<div class="second"><span class="target"> in advance</span></div><div class="first"><span class="target">E-Mail</span><input name="email" id="emailaddress" value="" type="text"></div>';
							c += '<div class="third"><a id="' + b + '" class="generic-button" href="javascript:void(0);"><span><span>submit</span></span></a></div></form>'
						}
						return new Element("div", {
							id : a,
							"class" : "remindMeForm clearfix"
						}).update(c)
					},
					submitMailForm : function(a) {
						var c = $("remindevent-" + a).serialize();
						var b = (this.language == "de") ? "Vielen Dank f&uuml;r Ihr Interesse an diesem Investor Relations Event. Wir haben Ihren Benachrichtigungswunsch erhalten, und werden Sie im Voraus an diesen Event per E-Mail erinnern."
								: "Thank you very much for your interest in this Investor Relations Event. We have received your entry for an email alert and will send you a reminder email in advance.";
						new Ajax.Request("../../apps/event_calendar/proxy.php", {
							method : "post",
							parameters : c,
							onSuccess : function(e) {
								var d = new Element("p").update(b);
								$("remindMe-" + a).update(d)
							},
							onFailure : function(e) {
								var d = new Element("p").update(b
										+ e.statusText);
								$("remindMe-" + a).update(d)
							}
						})
					}
				});