var main = {
	path:{},
	init: function(){
		this.initNavi();
//		this.initFooter();
	},
	initNavi: function(){
		$("navi").childElements().each(function(e){
			if(!e.hasClassName("navi_spacer") && !e.hasClassName("clearer") && Object.isElement(e.down("ul.subs"))){
//				e.down("ul.subs").setStyle({zIndex:50})
				e.observe("mouseenter",function(){
					e.down("ul.subs").show();
				}.bind(this)).observe("mouseleave",function(){
					e.down("ul.subs").hide();
				});
			}
		}.bind(this));
	},
	print: function(){
		window.print();
	},
	today: "",
	tabs: [],
	initFooter: function(){
		var tab_container = $$("div.footer_tabs")[0];
		if(!Object.isUndefined(tab_container)){
			this.tabs = tab_container.select("div.tab");
			this.tabs.each(function(e,i){
				e.content = tab_container.next("div.footer_tabs_content").select("div.tab_content")[i];
				// yeardays highlight
				e.content.select(".entry .text").each(function(t){
					var yearday = t.readAttribute("yearday");
					if(yearday!=""){
						var regexp = eval("/("+yearday+")/gi");
						t.innerHTML = t.innerHTML.replace(regexp,"<em>$1<\/em>");
					}
				}.bind(this));
				
				e.observe("click",function(){
					this.handleFooterTabs(i);
				}.bind(this));
			}.bind(this));
		}
	},
	handleFooterTabs: function(index){
		this.tabs.each(function(e,i){
			if(index==i){
				e.addClassName("active");
				e.content.show();
			} else {
				e.removeClassName("active");
				e.content.hide();
			}
		}.bind(this));
	},
	ajax: function(settings){
		if(Object.isUndefined(settings.path))
			return false;
		
		var callback = Object.isFunction(settings.onSuccess)?settings.onSuccess:Prototype.emptyFunction;
		var callbackError = Object.isFunction(settings.onError)?settings.onError:Prototype.emptyFunction;
		
		new Ajax.Request(settings.path,{
			parameters:settings.parameters||{},
			onSuccess: function(t){			
				var response = t.responseText;
				if(response.isJSON()){
					response = response.evalJSON();
					if(response.error){
						response.error = response.error.gsub("<br>","\n").gsub("<br />","\n").strip();
						if(Object.isUndefined(settings.abortError))
							alert(response.error);
						callbackError(response);
					} else if(callback){
						callback(response);
					}
				}
			}
		});
	},
	url: function(button){
		if(Prototype.Browser.IE){
			location.href = button.href;
		}
	},
	back: function(){
		history.back();
	}
}

function showQuizPlayer(){
	Lightview.show({
		href: "http://kunden.men-gmbh.de/ccopal/gewinnspiel/player.swf",
		rel: "flash",
		title: "",
		options: {
			topclose: false,
			autosize: false,
			width: 682,
			height: 384,
			flashvars: "xmlPath=http://kunden.men-gmbh.de/ccopal/gewinnspiel/content.xml"
		}
	});
}

document.observe("dom:loaded",main.init.bind(main));
