Fx.WScroll=Fx.Scroll.extend({initialize:function(options){this.parent(window,options||{})},toElementBottom:function(el,x_plus,y_plus){var parent=this.element.getPosition(this.options.overflown);var target=$(el).getPosition(this.options.overflown);var target_size=$(el).getSize();return this.scrollTo(target.x-parent.x+(x_plus||0),target.y-window.getHeight()-parent.y+target_size.size.y+(y_plus||0))}});
Fx.CSlide=Fx.Slide.extend({initialize:function(el,options){this.wasClose=false;this.parent(el,options||{});this.addEvent('onComplete',function(el,options){this.wrapper.setStyles({'height':'auto','owerflow':'visible'});if(this.wasClose)this.wrapper.setStyle('display','none');if(options&&options.removeAfter)$(el).remove()}.bind(this,[el,options]))},slideIn:function(mode){this.wasClose=false;this.wrapper.setStyles({owerflow:'hidden',margin:0,display:''});this[mode||this.options.mode]();if(window.ie)this.set([-40,0]);return this.start([this.element.getStyle(this.margin).toInt(),this.wrapper.getStyle(this.layout).toInt()],[0,this.offset])},slideOut:function(mode){this.wasClose=true;this.setHeight();this.wrapper.setStyle('owerflow','hidden');if(window.ie&&this.element.id=='topnav-subline'){this.element.getElements('*').each(function(item){item.setStyle('visibility','hidden')})}return this.slideOutNorm(mode)},slideOutNorm:function(mode){this[mode||this.options.mode]();return this.start([this.element.getStyle(this.margin).toInt(),this.wrapper.getStyle(this.layout).toInt()],[-this.offset,0])},setHeight:function(){var height=this.element.getSize().scrollSize.y;this.wrapper.setStyle('height',height)}});
Element.extend({formToObj:function(){obj={};this.getFormElements().each(function(item){if(item.type!='submit'&&!(item.type=='checkbox'&&item.checked==false))obj[item.name]=item.value});return obj},focusFirst:function(pos,delay){(function(pos){if(this.getFormElements()){var els=this.getFormElements();if(pos>=0){els[pos].focus()}else{var found;for(var i=0;i<els.length&&!found;i++){if(els[i].type=="text"){found=true;els[i].focus()}}}}}).delay(delay||600,this,pos||null)},onKeySubmit:function(){var frm=this;this.getFormElements().each(function(item){item.addEvent('keydown',function(event,frm){event=new Event(event);if(event.key=='enter')frm.fireEvent('submit',event)}.bindWithEvent(item,frm))})}});
var JsonRpc=Ajax.extend({initialize: function(url, options){this.parent(url, options || {});this.setHeader('X-Request', 'JSON');},onComplete:function(){if(this.options.update)$(this.options.update).empty().setHTML(this.response.text);if(!window.ie)this.evals();this.fireEvent('onComplete',[this.response.obj,this.response.xml],20)},evals:function(){if(this.options.evalScripts||this.options.evalResponse)this.evalScripts()},call:function(method,params){var params=params||[];var data=Json.toString({id:0,method:method,params:params.constructor==Array?params:[params]});this.request(data)},onSuccess:function(){var obj=Json.evaluate(this.transport.responseText).result;this.response={'text':$defined(obj.content)?obj.content:obj,'xml':this.transport.responseXML,'obj':obj};this.fireEvent('onSuccess',[this.response.obj,this.response.xml]);if(window.ie)this.evals();this.callChain()}});
var Content=new Class({initialize:function(gateway,content,scrollTo,showCloseButton){this.gateway=gateway;this.content=content;this.scrollTo=scrollTo||null;this.showCloseButton=showCloseButton||null;this.slide=null;this.opened="";this.initialized=false;this.request_counter=0},getCaller:function(method){var m=method.split('.');var g=this.gateway.split('/');var j=g[g.length-1]==''?g.length-2:g.length-1;for(var i=m.length-2;i>=0;i--)g[j]=m[i];j--;return{method:m[m.length-1],gateway:g.join("/")}},prepareNewCnt:function(options,almopened,force){this.loptions=$merge({'scrollTo':true,'animate':true,'callAfter':[],'closeButton':false,'onClose':null,'selfScroll':false},options);if(!this.initialized)this.initialized=true;if(!this.slide){this.slide=new Fx.CSlide(this.content,{wait:false})}this.almopened=almopened;if((this.almopened!=this.opened)||(force||false)){if(this.loptions.selfScroll){this.scroll=new Fx.WScroll(this.content)}else if(this.scrollTo&&!this.scroll){this.scroll=new Fx.Scroll(this.scrollTo)}if(this.loptions.animate)this.slide.hide();return true}return false},
finishNewCnt:function(){if(this.loptions.selfScroll){if(this.content=='col2_content'){this.scroll.toElement('col1')}else{this.scroll.toElement(this.content)}}else if((this.scrollTo&&this.loptions.scrollTo)){this.scroll.toTop()}},load:function(event,method,params,options,force){var params=(params||[]);var allow_call=this.prepareNewCnt(options||{},method+Json.toString(params),force);if(event)event.stop();if(allow_call){this.request_counter++;this.showLoader();var gc=this.getCaller(method);new JsonRpc(gc.gateway,{update:this.content,evalScripts:true,onComplete:this.loadComplete.bind(this,[method,params])}).call(gc.method,params)}this.finishNewCnt()},write:function(html_content,options){this.prepareNewCnt(options||{},'im_write',true);this.finishNewCnt();$(this.content).setHTML(html_content);this.loadComplete('im_write',[])},appendCloseButton:function(){var elcb=new Element('div',{'class':'close-button'});elcb.addEvent('click',this.slideClose.bind(this));elcb.injectTop(this.content)},showLoader:function(){loader.place(this.content);if(this.loptions.animate)this.slide.slideIn()},
loadComplete:function(method,params){		
	$$(".open-registerform").addEvent('click', top.load.bindWithEvent(top, ["register", [], {scrollTo: true }]));		
	$$(".scrollto-frequencyfinder").addEvent('click', function(event){
		event = new Event(event).stop();		
		this.scroll = new Fx.WScroll();
		this.scroll.toElement('frequency-finder');
	});
	this.opened=method+Json.toString(params);
	if(this.showCloseButton||this.loptions.closeButton){this.appendCloseButton()}if($(this.content).innerHTML>""&&this.loptions.animate){this.slide.slideIn()}else if(this.loptions.animate)this.slide.show();this.callAfterLoad(this.loptions.callAfter)},slideClose:function(){if(this.loptions.onClose!=null)this.loptions.onClose.call(this);this.opened=null;if(this.slide&&this.loptions.animate)this.slide.slideOut()},close:function(){if(!this.slide)this.slide=new Fx.CSlide(this.content,{wait:false});this.slide.slideOut()},autoSlideClose:function(){if(this.aopened==this.almopened)this.slideClose()},delayedSlideClose:function(delay){this.aopened=this.almopened;this.autoSlideClose.delay(delay||3000,this)},callAfterLoad:function(callAfter){callAfter.each(function(m){m()})}});
var Loader=new Class({initialize:function(){this.cache=[];this.cached=4;this.fillUpCache()},loadImage:function(){return new Asset.image('/media/img/loader.gif',{title:'Processing..'})},fillUpCache:function(){for(var i=this.cache.length;i<this.cached;i++){this.cache.push(this.loadImage())}},get:function(){var el=this.cache.pop();this.fillUpCache();return el},place:function(target_el,msg){if($(target_el)){var el=new Element('div',{'class':'wait-loader-holder'});new Element('div').setText(msg||'Processing..').injectInside(el);this.get().injectInside(el);el.injectInside($(target_el).empty())}}});

function reload_content(call_after_login){new JsonRpc("/gw/jsonrpc/main/",{update:'nav_main',evalScripts:true}).call("toolbar");new JsonRpc("/gw/jsonrpc/media/",{update:'voting-topten',evalScripts:true}).call("vote");/*leftco.load(null,'main.refresh_leftco',null,{},true);*/if($('comments')&&$('comments').getElement('h2[class=clip-detail]')&&mdd){showComments(mdd)}else{middle.load(null,'main.refresh_middle',null,null,true)};if(call_after_login){eval(call_after_login);}}
function show_upload(event) {if ($('tv')) new Fx.CSlide('tv', {removeAfter:true}).slideOut();middle.load(event || null, "media.media_upload", true, {}, true);middletop.slideClose.bind(middletop);}
function show_competition_upload(event, slug) {if ($('tv')) new Fx.CSlide('tv', {removeAfter:true}).slideOut();middle.load(event || null, "media.competition_upload", [slug, true], {}, true);middletop.slideClose.bind(middletop);}
function resizeScreen(mode){var fx1=$('tv-left').effects({duration:1000,transition:Fx.Transitions.Quint.easeOut});var fx2=$('tv-right').effects({duration:1000,transition:Fx.Transitions.Quint.easeOut});$('voting-topten').set({'visibility':'hidden'});fx1.start({'width':mode?998:694,'height':mode?540:391});fx2.start({'width':mode?0:304,'height':393,'left':mode?998:695})}
function showComments(id,page,detail){middle.load(null,'show_comments',[id,page||1,detail||false])}
function showMessages(){middle.load(null,'main.show_messages',null, {selfScroll: true})}
function showUser(){middle.load(null,'main.show_user',null)}
function userLogin(event){top.load(event||null,"login"); if ($("voting-login-hint")) $("voting-login-hint").setStyle("display", "")}
function refreshVotes(event){if($('voting-topten')) right.load(event||null,'show_votes',[],{},true)}
function refreshBanners(id) {
	(function() {
		new JsonRpc("/gw/jsonrpc/banner/", {update: 'skyscraper', evalScripts: true}).call("getBannerHtml",[id,2]);
	}).delay(1000);
	(function() {
		new JsonRpc("/gw/jsonrpc/banner/", {update: 'ad-banner', evalScripts: true}).call("getBannerHtml",[id,0]);
	}).delay(2000);
	new JsonRpc("/gw/jsonrpc/banner/", {update: 'right-banner', evalScripts: true}).call("getBannerHtml",[id,1]);
}
var searchLastPhrase="";var searchShowResultsFor='';var searchSortingInd=null;var searchFilter=null;var searchAdvanced=null;
function simpleSearch(event,find,page,sorting_index,search_filter,results_for,advanced_filters){if(results_for!='acli')searchAdvanced=null;searchLastPhrase=find||searchLastPhrase;searchSortingInd=sorting_index||searchSortingInd;searchFilter=search_filter||searchFilter;searchAdvanced=advanced_filters||searchAdvanced;searchShowResultsFor=results_for||searchShowResultsFor;middle.load(event,'main.search',[searchLastPhrase,page||1,searchSortingInd,searchFilter,searchShowResultsFor,searchAdvanced],{animate:false,selfScroll:true})}
function showAllUsers(event, page) { middle.load(event, 'main.all_users', [page || 1], {animate: false, selfScroll: true}); }
function wOpen(location, name){ var w = window.open(location, name, 'width=840,height=600,resizable=yes,scrollbars=yes'); w.focus();}
var loader = new Loader();
var top = new Content('/gw/jsonrpc/main/', 'topnav-subline', window, true);
//var leftco = new Content('/gw/jsonrpc/main/', 'col1_controls');
var middle = new Content('/gw/jsonrpc/media/', 'col2_content', window);
var middletop = new Content('/gw/jsonrpc/main/', 'col2_topcontent');
var right = new Content('/gw/jsonrpc/media/', 'voting-topten');

window.addEvent('domready',function(){if($ES('script[src^=/media/js/oneofivetv.js]','head')[0].src.match(/login$/)){}else{}refreshVotes.periodical(300000);});
function tellAFriend(){middletop.load(null, 'tell_a_friend', null, {closeButton: true}); }
function showDisclaimer(slug) { window.open("/disclaimer/" + slug, 'Nutzungsbedingungen', 'width=840,height=600,resizable=yes,scrollbars=yes'); };