
window.addEvent('domready',function(){Generic.init()});var Helper={ToElement:new Class({$element:null,setElement:function(element){this.$element=element;},toElement:function(){return this.$element;}}),Plugin:new Class({plugin:{},initPlugins:function(){for(i in this.plugin){this[i].getParent=function(){return this;}.bind(this);this[i].initialize(this);}}})};Request.Generic=new Class({Extends:Request.JSON,send:function(prefix,callback,info,options){this.$type=prefix;this.$info=info;this.$callback=callback;if(this.$type)this.parent(options);else new Generic.Note('No prefix ($type) for request specified for '+callback.name).error();},reset:function(){this.$type=null,this.$callback=null;}});var Generic={version:0.35,author:'Sascha Goldhofer',build:'2011.02.28',options:{controller:undefined,routeMedia:undefined,notes:true,errors:false,debug:false,note:{delay:6000},infobar:{id:'gCI_Feedback'}},config:function(options){Generic.options=Object.merge.apply(null,[{},Generic.options].append(arguments));},init:function(){Generic.Note.init();Generic.Infobar.init();var files=$(document.body).getElements('span.gCI_File');if(files)files.each(function(element){var text=element.getElement('input.text');var file=element.getElement('input.file');file.addEvent('change',function(e){text.set('value',file.get('value'));});});},Request:new Request.Generic({link:'chain',timeout:3000,onRequest:function(){Generic.Infobar.show(this.$info+' '+this.$type);},onComplete:function(){Generic.Infobar.close();},onCancel:function(){this.note=new Generic.Note('<h1>Request Timeout ('+this.$type+')</h1>');this.note.error();},onSuccess:function(json,text){if(Generic.options.debug)json.note+=json.debug;if(!Browser.ie){var note=new Generic.Note(json.note);note.close(Generic.options.note.delay);}
if(json.success){this.$callback(json.data);}else if(json.note!==''&&Generic.options.errors){if(!Browser.ie){note.message(json.note);note.error();}}
if(!Browser.ie){if(json.notes.length>=1){for(var i=0;i<json.notes.length;i++){if(json.notes[i].msg){var note=new Generic.Note(json.notes[i].msg);note.close(Generic.options.note.delay);if(json.notes[i].error)note.error();}}}}},onFailure:function(result){return;if(Generic.options.debug){var error=new Element('div',{'html':'<h1>Status: '+this.status+' ('+this.$type+')</h1>'});var details=new Element('a',{'html':'show details','href':'#',events:{'click':function(event){var win=window.open();win.document.open();win.document.write(this.retrieve('error').responseText);win.document.close();}}}).inject(error);details.store('error',result);}else var error='<h1>Status: '+this.status+' ('+this.$type+')</h1>';if(Generic.options.errors&&!Browser.ie)new Generic.Note(error).error();}}),Action:new Class({initialize:function(action,data){this.$data=data|| {};this.$data.action=action;},add:function(key,value){this.$data.key=value;},toJSON:function(method,prefix){this.$data.method=method;this.$data.prefix=prefix;return'data='+JSON.encode(this.$data);}}),Interface:new Class({$type:null,initialize:function(prefix){this.$type=prefix;},setType:function(prefix){this.$type=prefix},save:function(actionString,data,callback){this.$save(new Generic.Action(actionString,data),callback);},load:function(actionString,data,callback){this.$load(new Generic.Action(actionString,data),callback);},remove:function(actionString,data,callback){this.$delete(new Generic.Action(actionString,data),callback);},saved:function(data){},loaded:function(data){},removed:function(data){},$save:function(action,callback){Generic.Request.send(this.$type,callback|| this.saved.bind(this),'saving',{'data':action.toJSON('save',this.$type),'url':window.location.href});},$load:function(action,callback){Generic.Request.send(this.$type,callback|| this.loaded.bind(this),'loading',{'data':action.toJSON('load',this.$type),'url':window.location.href});},$delete:function(action,callback){Generic.Request.send(this.$type,callback|| this.removed.bind(this),'deleting',{'data':action.toJSON('delete',this.$type),'url':window.location.href});}}),debug:function() {if(window.console&&console.info)console.info.apply(console,arguments);},Infobar:{init:function(){this.status=$(Generic.options.infobar.id);if(!status)return;this.status.setStyles({'display':'block','opacity':0});this.statusHeight=this.status.getSize().y;this.statusFX=new Fx.Morph(this.status,{duration:300});},show:function(message){if(!status)return;this.status.set('html',message);this.statusFX.start({'top':[-this.statusHeight,0],'opacity':1});},close:function(){if(!status)return;this.statusFX.cancel();this.statusFX.start({'top':-this.statusHeight,'opacity':0}).chain(function(){this.status.set('html','');}.bind(this));}},Note:new Class({Implements:Helper.ToElement,$class:'gCI_Notification',$markup:'<span class="close"><a class="close" href="#">×</a></span><div class="content"></div>',$countdown:null,initialize:function(message){this.setElement(new Element('div',{'class':this.$class,'html':this.$markup}));this.message(message);$(this).getElement('a.close').addEvent('click',function(event){Generic.Note.remove($(this))}.bind(this).bind(this));new Drag.Move($(this),{grid:20,onStart:this.sticky.bind(this),onComplete:function(draggedElement){Generic.Note.reposition(this);}.bind(this)});$(this).store('anim',new Fx.Morph($(this),{duration:400}));if(message!=='')Generic.Note.add(this);},'message':function(msg){if(typeOf(msg)==='string')$(this).getElement('div.content').set('html',msg);else msg.inject($(this).getElement('div.content'));},'close':function(delay){this.$countdown=Generic.Note.remove.delay(delay,Generic.Note,$(this));},'error':function(){$(this).addClass('error');this.sticky();},sticky:function(){clearTimeout(this.$countdown);$(this).addClass('sticky');}}).extend({$notes:0,$anchor:{x:20,y:80},$position:{x:20,y:80},$direction:{x:1,y:1},$offset:14,'add':function(note){$(note).inject($(document.body),'bottom');$(note).setStyles({'left':this.$position.x,'top':this.$position.y,'opacity':0.01});$(note).retrieve('anim').start({'opacity':0.8});this.$position.y+=($(note).getSize().y+this.$offset)*this.$direction.y;if(this.$position.y<=20|| (this.$position.y+20)>=document.window.getSize().y) {this.$position.x=this.$anchor.x+((180+this.$offset)*this.$direction.x);this.$position.y=this.$anchor.y;}
this.$notes++;return note;},'reposition':function(note){this.$anchor=$(note).getPosition();this.update();this.$position.x=this.$anchor.x;this.$position.y=this.$anchor.y+($(note).getSize().y+this.$offset)*this.$direction.y;},'remove':function(note){var anim=note.retrieve('anim');if(anim===null)return;this.$notes--;anim.start({'opacity':0}).chain(function() {if(this.$notes<=0)this.reset();note.destroy();}.bind(this));},'init':function(){var anchor=new Hash.Cookie('generic').get('anchor');if(anchor)this.$anchor=anchor;this.reset();this.update();for(index in Generic.options.note.notes){var current=Generic.options.note.notes[index];var note=new Generic.Note(''+current.msg);if(current.error===true)note.error();else note.close(Generic.options.note.delay);}},reset:function(){this.$position.x=this.$anchor.x;this.$position.y=this.$anchor.y;this.$notes=0;}.protect(),update:function(){var size=document.window.getSize();if(this.$anchor.y>=size.y/2)this.$direction.y=-1;else this.$direction.y=1;if(this.$anchor.x>=size.x/2)this.$direction.x=-1;else this.$direction.x=1;var cookie=new Hash.Cookie('generic',{duration:30});cookie.set('anchor',this.$anchor);}.protect()})};var Dialogue=new Class({Implements:[Helper.ToElement,Generic.Interface],$type:'dialogue',$request:'replace to requested dialogue_view',$title:'Dialog',$data:{},$drag:null,initialize:function(){this.setElement(new Element('div',{id:'dialogue',html:'<div class="titlebar">'+this.$title+'<div class="close"><a href="#">×</a></div></div><div class="content"></div>',opacity:0.95}));$(this).getElement('div.content').set('opacity',1.0);this.$background=new Element('div',{id:'dialogueBG'});this.load(this.$request,this.$data);$(this).getElement('div.close a').addEvent('click',this.close.bind(this));this.$drag=new Drag.Move($(this),{grid:0,handle:$(this).getElement('div.titlebar')});},setTitle:function(title){this.$title=title;},close:function(){this.$background.destroy();$(this).destroy();},loaded:function(data){$(this).getElement('div.content').set('html',data.html);this.$background.inject($(document.body));$(this).inject($(document.body));}});
