webif:
[enigma2-plugins.git] / webinterface / src / web-data / core.js
1 Element.prototype.fadeIn = function(parms, out) {
2                 var _this = this;
3                 var opacityTo = function(elm,v){
4                         elm.style.opacity = v/100;
5                         elm.style.MozOpacity =  v/100;
6                         elm.style.KhtmlOpacity =  v/100;
7                         elm.style.filter=" alpha(opacity ="+v+")";
8                 };
9                 var delay = parms.delay;
10                 var to = parms.to;
11                 if(!to)
12                         to = 100;
13                 
14                 _this.style.zoom = 1;
15                 // for ie, set haslayout
16                 _this.style.display = "block";
17         
18                 for (var i=1; i<=to; i++) {
19                         (function(j) {
20                                 setTimeout(function() {
21                                         if (out == true)
22                                                 j = to - j;
23                                         opacityTo(_this, j);
24                                 }, j * delay / to);
25                         })(i);
26                 };
27         };
28 Element.prototype.fadeOut = function(delay) {
29                 this.fadeIn({'delay' : delay}, true);
30         };
31
32 String.prototype.e = function(){
33         return this.replace("\"","&quot;");
34 };
35         
36 // General Helpers
37 function toOptionList(lst, selected, split) {
38         var retList = Array();
39         retList.push("");
40         if(split && !selected == ''){
41                 selected = selected.split(split);
42         } else {
43                 if(selected && selected != ""){
44                         selected = [selected];
45                 } else {
46                         selected = [];
47                 }
48         }
49
50         selected.each(function(item){
51                 var found = false;
52                 lst.each(function(listItem){
53                         
54                         if (listItem == item) {
55                                 found = true;
56                         }
57                 });
58                 if (!found) {
59                         lst.push(item);
60                 }
61         });
62
63         
64         lst.each(function(listItem){
65                 var sel = '';
66                 selected.each(function(item){
67                         if (listItem == item) {
68                                 sel = 'selected';
69                         }
70                 });
71                 
72                 retList.push({
73                         'value': listItem,
74                         'txt': listItem,
75                         'selected': sel
76                 });
77         });
78
79         return retList;
80 }
81
82 function debug(item){
83         if(userprefs.data.debug)
84                 console.log(item);
85 }
86
87 function parseNr(num) {
88         if(isNaN(num)){
89                 return 0;
90         } else {
91                 return parseInt(num);
92         }
93 }
94
95 var Controller = Class.create({
96         initialize: function(model){
97                 this.model = model;
98                 this.model.onFinished[this.model.onFinished.length] = this.registerEvents.bind(this);
99                 this.model.onFinished[this.model.onFinished.length] = this.onFinished.bind(this);
100                 this.eventsregistered = false;
101         },
102
103         registerEvents: function(){
104                 this.eventsregistered = true;
105         },
106         
107         onFinished: function(){}
108 });
109
110 var Bouquets = Class.create(Controller, {
111         initialize: function($super, targetBouquets, targetMain){
112                 $super(new BouquetListHandler(targetBouquets, targetMain));
113                 this.loadFirstOnFinished = false;
114         },
115         
116         load: function(sRef, loadFirstOnFinished){
117                 if(loadFirstOnFinished)
118                         this.loadFirstOnFinished = true;
119                 this.model.load( {'sRef' : sRef} );
120         },
121         
122         loadBouquetsTv: function(){
123                 this.load(bouquetsTv);
124         },
125         
126         loadProviderTv: function(){
127                 this.load(providerTv);
128         },
129         
130         loadSatellitesTv: function(){
131                 this.load(satellitesTv);
132         },
133         
134         loadBouquetsRadio: function(){
135                 this.load(bouquetsRadio);
136         },
137         
138         loadProviderRadio: function(){
139                 this.load(providerRadio);
140         },
141         
142         loadSatellitesRadio: function(){
143                 this.load(satellitesRadio);
144         },
145         
146         onFinished: function(){
147                 var bouquet = this.model.data.services[0];
148                 if(bouquet){
149                         setContentHd(bouquet.servicename);
150                         if(this.loadFirstOnFinished){
151                                 this.loadFirstOnFinished = false; 
152                                 hash = core.getBaseHash() + '/' + bouquet.servicereference;
153                                 hashListener.setHash(hash);
154                         }
155                 }
156         }
157 });
158
159 var Current = Class.create(Controller, {
160         initialize: function($super, curTarget, volTarget){
161                 $super(new CurrentHandler(curTarget, volTarget));
162                 this.model.onFinished[this.model.onFinished.length] = this.onFinished.bind(this);
163                 this.display = 'none';
164         },
165         
166         load: function(){
167                 var ext = $('trExtCurrent'); 
168                 if(ext != null){
169                         this.display = $('trExtCurrent').style.display;
170                 }
171                 this.model.load({});
172         },
173         
174         onFinished: function(){
175                 var ext = $('trExtCurrent'); 
176                 if(ext != null){
177                         ext.style.display = this.display;
178                 }
179                 core.currentData = this.model.data;
180         }
181 });
182
183 var EPG = Class.create(Controller, {
184         initialize: function($super){
185                 $super(new EpgListHandler(this.show.bind(this)));
186                 this.window = '';
187         },
188         
189         show:function(html){
190                 var win = core.popup("EPG" + new Date().getTime(), html, 900, 500);
191                 this.doRegisterEvents(win);
192         },
193         
194         load: function(sRef){
195                 this.model.load({'sRef' : sRef});
196         },
197
198         search: function(needle){
199                 this.model.search({'search' : needle});
200         },
201         
202         doRegisterEvents: function(win){
203                 var elem = win.document;
204                 var onload = function(event){
205                         elem.on(
206                                 'click',
207                                 '.eListAddTimer',
208                                 function(event, element){
209                                         core.timers.addByEventId(element, 0);
210                                         return false;
211                                 }
212                         );
213                         elem.on(
214                                 'click',
215                                 '.eListZapTimer',
216                                 function(event, element){
217                                         core.timers.addByEventId(element, 1);
218                                         return false;
219                                 }
220                         );
221                         elem.on(
222                                 'click',
223                                 '.eListEditTimer',
224                                 function(event, element){
225                                         var hash = ["#!/timer", "edit"].join("/");
226                                         hashListener.setHash(hash);
227                                         core.timers.editFromEvent(element);
228                                         //return false;
229                                 }
230                         );
231                 };
232                 if(elem.on){
233                         onload();
234                 } else {
235                         win.onload = onload;
236                 }
237         }
238 });
239
240 var Power = Class.create({
241         STATES: {'toggle' : 0, 'deep' : 1, 'reboot' : 2, 'gui' : 3},
242         
243         initialize: function(){
244                 this.provider = new PowerstateProvider(this.onLoadFinished.bind(this));
245                 this.callbacks = [];
246                 this.isLoading = false;
247                 this.isStandby = false;
248         },
249         
250         load: function(params){
251                 this.isLoading = true;
252                 this.provider.load(params);
253         },
254         
255         onLoadFinished:function (isStandby){
256                 this.isStandby = isStandby;
257                 this.isLoading = false;
258                 var len = this.callbacks.length;
259                 for(var i = 0; i < len; i++){
260                         callback = this.callbacks.pop();
261                         callback(this.isStandby);
262                 }
263         },
264         
265         inStandby: function(callback){
266                 this.callbacks.push(callback);
267                 if(!this.isLoading){
268                         this.load({});
269                 }
270         },
271         
272         set: function(newstate, callback){
273                 this.callbacks.push(callback);
274                 this.load({'newstate' : this.STATES[newstate]});
275         }
276 });
277
278 var LocationsAndTags = Class.create({
279         initialize: function(){
280                 this.currentLocation = '';
281                 this.locations = [];
282                 this.tags = [];
283                 this.isCurrentLocationsLoading = false;
284                 this.isCurrentLocationReady = false;
285                 this.isLocationsLoading = false;
286                 this.isLocationsReady = false;
287                 this.isTagsLoading = false;
288                 this.isTagsReady = false;
289                 this.curLocCallbacks = [];
290                 this.locCallbacks = [];
291                 this.tagCallbacks = [];
292                 this.locTagCallbacks = [];
293                 
294                 this.curlocprovider = new CurrentLocationProvider(this.onCurrentLocationAvailable.bind(this));
295                 this.locprovider = new LocationProvider(this.onLocationsAvailable.bind(this));          
296                 this.tagprovider = new TagProvider(this.onTagsAvailable.bind(this));
297         },
298         
299         getCurrentLocation: function(callback){
300                 if(this.isCurrentLocationReady){
301                         callback(this.currentLocation);
302                 } else {
303                         this.curLocCallbacks[this.curLocCallbacks.length] = callback;
304                         if(!this.isCurrentLocationLoading){
305                                 this.curlocprovider.load({});
306                                 this.isCurrentLocationLoading = true;
307                         }
308                 }
309         },
310         
311         onCurrentLocationAvailable: function(currentLocation){
312                 debug("[LocationsAndTags].onCurrentLocationAvailable");
313                 this.isCurrentLocationReady = true;
314                 this.isCurrentLocationLoading = false;
315                 this.currentLocation = currentLocation;
316                 var len = this.curLocCallbacks.length;
317                 for(var i = 0; i < len; i++){
318                         callback = this.curLocCallbacks.pop();
319                         callback(this.currentLocation);
320                 }
321                 this.onLocationsOrTagsAvailable();
322         },
323         
324         getLocations: function(callback){
325                 if(this.isLocationsReady){
326                         callback(this.locations);
327                 } else {
328                         this.locCallbacks[this.locCallbacks.length] = callback;
329                         if(!this.isLocationsLoading){
330                                 this.locprovider.load({});
331                                 this.isLocationsLoading = true;
332                         }
333                 }
334         },
335         
336         onLocationsAvailable: function(locations){
337                 debug("[LocationsAndTags].onLocationsAvailable");
338                 this.isLocationsReady = true;
339                 this.isLocationsLoading = false;
340                 this.locations = locations.getList();
341                 var len = this.locCallbacks.length;
342                 for(var i = 0; i < len; i++){
343                         callback = this.locCallbacks.pop();
344                         callback(this.locations);
345                 }
346                 this.onLocationsOrTagsAvailable();
347         },
348         
349         getTags: function(callback){
350                 if(this.isTagsReady){
351                         callback(this.tags);
352                 } else {
353                         this.tagCallbacks[this.tagCallbacks.length] = callback;
354                         if(!this.isTagsLoading){
355                                 this.tagprovider.load({});
356                                 this.isTagsLoading = true;
357                         }
358                 }
359         },
360         
361         onTagsAvailable: function(tags){
362                 debug("[LocationsAndTags].onTagsAvailable");
363                 this.isTagsReady = true;
364                 this.isTagsLoading = false;
365                 this.tags = tags.getList();
366                 var len = this.tagCallbacks.length;
367                 for(var i = 0; i < len; i++){
368                         callback = this.tagCallbacks.pop();
369                         callback(this.tags);
370                 }
371                 this.onLocationsOrTagsAvailable();
372         },
373         
374         getLocationsAndTags: function(callback){
375                 if(this.isCurrentLocationReady && this.isLocationsReady && this.isTagsReady){
376                         callback(this.currentLocation, this.locations, this.tags);
377                 } else {
378                         this.locTagCallbacks[this.locTagCallbacks.length] = callback;
379                         if(!this.isCurrentLocationLoading)
380                                 this.curlocprovider.load({});
381                         if(!this.isLocationsLoading)
382                                 this.locprovider.load({});
383                         if(!this.isTagsLoading)
384                                 this.tagprovider.load({});
385                 }
386         },
387         
388         onLocationsOrTagsAvailable: function(){
389                 if(this.isCurrentLocationReady && this.isLocationsReady && this.isTagsReady){
390                         var len = this.locTagCallbacks.length;
391                         for(var i = 0; i < len; i++){
392                                 callback = this.locTagCallbacks.pop();
393                                 callback(this.currentLocation, this.locations, this.tags);
394                         }
395                 }
396         }
397 });
398
399 var MediaPlayer = Class.create(Controller, {
400         initialize: function($super, target){
401                 $super(new MediaPlayerHandler(target));
402         },
403
404         load: function(path){
405                 if(!path){
406                         path = 'Filesystems';
407                 }
408                 var parms = {'path' : path};
409                 this.model.load(parms);
410         },
411         
412         playFile: function(file){
413                 this.model.playFile(file);
414         },
415         
416         removeFile: function(file){
417                 this.model.removeFile(file);
418         },
419         
420         savePlaylist: function(filename){
421                 this.model.savePlaylist(filename);
422         },
423         
424         command: function(cmd){
425                 this.model.command(cmd);
426         }
427 });
428
429 var Messages = Class.create({
430         initialize: function(){
431                 this.model = new SimpleRequestHandler();
432         },
433         
434         send: function(text, type, timeout){
435                 this.model.load(URL.message, {'text' : text, 'type' : type, 'timeout' : timeout});
436         }
437 });
438
439 var Movies = Class.create(Controller, {
440         initialize: function($super, listTarget, navTarget){
441                 $super(new MovieListHandler(listTarget));
442                 this.navModel = new MovieNavHandler(navTarget);
443         },
444         
445         load: function(location, tags){ 
446                 if(!location){
447                         var sethash = function(location){
448                                 var hash = [core.getBaseHash(), "filter", encodeURIComponent(location), encodeURIComponent(tags)].join("/");
449                                 hashListener.setHash(hash);
450                         };
451                         if(core.currentLocation == ""){ //wait for currentLocation to be set;
452                                 core.lt.getCurrentLocation(sethash);
453                         } else {
454                                 sethash(core.currentLocation);
455                         }
456                         return;
457                 }
458                                 
459                 this.model.load({'dirname' : location, 'tag' : tags});
460         },
461         
462         loadNav: function(){
463                 core.lt.getLocationsAndTags(this.showNav.bind(this));
464         },
465         
466         showNav: function(currentLocation, locations, tags){
467                 this.navModel.load(toOptionList(locations, currentLocation), toOptionList(tags, core.currentTag));
468         },
469         
470         del: function(element){
471                 this.model.del(element);
472         }
473 });
474
475 var RemoteControl = Class.create({
476         initialize: function(){
477                 this.model = new RemoteControlHandler();
478                 this.window = '';
479         },
480         
481         open: function(){
482                 if(!this.window)
483                         this.window = '';
484                 if (this.window.closed || !this.window.location){
485                         var tpl;
486                         switch(core.deviceInfo.info.devicename){
487                         case 'dm8000':
488                         case 'dm7020hd':
489                                 tpl = 'tplWebRemote';
490                                 break;
491                         default:
492                                 tpl = 'tplWebRemoteOld';
493                         }
494                         
495                         templateEngine.fetch(tpl, function(template){
496                                 this.eventsregistered = false;
497                                 this.window = core.popup('WebRemote', template, 250, 600);
498                                 this.registerEvents();
499                         }.bind(this));
500                 }
501         },
502         
503         sendKey: function(cmd, type, shotType){
504                 debug("[RemoteControl].sendKey: " + cmd); 
505                 this.model.sendKey({'command' : cmd, 'type': type});
506                 
507                 var hash = '!/control'; //FIXME
508                 switch(shotType){               
509                 case undefined:
510                 case '':
511                         return;
512                 case 'osd':
513                         hash = [hash, 'osdshot'].join("/");
514                         break;
515                 case 'all':
516                         hash = [hash, 'screenshot'].join("/");
517                         break;
518                 }
519                 //the box needs at least a little bit of time to actually draw the window
520                 //wait 250ms before fetching a new screenshot
521                 setTimeout(
522                                 function(){
523                                         hashListener.setHash(hash);
524                                         if(hash == hashListener.getHash()){
525                                                 core.onHashChanged(true);
526                                         }
527                                 },
528                                 250);
529         },
530         
531         registerEvents:function(){
532                 var _this = this;
533                 var win = this.window;          
534                 var elem = win.document;
535                 
536                 var onload = function(event){                   
537                         elem.on(
538                                 'click',
539                                 '.remoteKey',
540                                 function(event, element){
541                                         var id = element.readAttribute('data-keyid');
542                                         var long = _this.window.document.getElementById('long').checked;
543                                         var screenshot = _this.window.document.getElementById('screenshot').checked;
544                                         var video = _this.window.document.getElementById('video').checked;
545                                         var type = '';
546                                         if(long){
547                                                 type = 'long';
548                                         }
549                                         var shotType = 'none';
550                                         if(screenshot && video){
551                                                 shotType = 'all';
552                                         } else if (screenshot && !video) {
553                                                 shotType = 'osd';
554                                         }
555                                         _this.sendKey(id, type, shotType);
556                                 }
557                         );
558                 };
559                 if(typeof(elem.on) == "function"){
560                         onload();
561                 } else {
562                         win.onload = onload;
563                 }
564         }
565 });
566
567 var Screenshots = Class.create(Controller, {
568         TYPE_OSD : 'o',
569         TYPE_VIDEO : 'v',
570         TYPE_ALL : '',
571         
572         initialize: function($super, target){
573                 $super(new ScreenshotHandler(target));
574         },
575         
576         load: function(type){
577                 var filename = '/tmp/' + new Date().getTime();
578                 var params = {'format' : 'jpg', 'r': '720', 'filename' : filename};
579                 
580                 switch(type){
581                         case this.TYPE_OSD:
582                                 params['o'] = '';
583                                 params['n'] = '';
584                                 break;
585                         case this.TYPE_VIDEO:
586                                 params['v'] = '';
587                                 break;
588                         default:
589                                 break;
590                 }
591                 this.model.load(params);                
592         },
593
594         shootOsd: function(){
595                 this.load(this.TYPE_OSD);
596         },
597         
598         shootVideo: function(){
599                 this.load(this.TYPE_VIDEO);
600         },
601         
602         shootAll: function(){
603                 this.load(this.TYPE_ALL);
604         }
605 });
606
607 var Services = Class.create(Controller, {
608         initialize: function($super, target, epg){
609                 $super(new ServiceListHandler(target));
610                 this.epg = epg;
611                 this.cachedServiceElements = null;
612         },
613         
614         zap: function(sRef){
615                 this.model.zap({'sRef' : sRef});
616         },
617         
618         load: function(sRef){
619                 this.model.load({'bRef' : sRef});
620         },
621         
622         getNowNext: function(){
623                 this.model.getNowNext();
624         },
625         
626         getSubservices: function(){
627                 this.model.getSubservices();
628         },
629         
630         loadAllTv: function(){
631                 this.load(allTv);
632                 setContentHd("All (Tv)");
633         },
634
635         loadAllRadio: function(){
636                 this.load(allRadio);
637                 setContentHd("All (Radio)");
638         },
639         
640         onFilterFocus: function(event){
641                 event.element().value = '';
642                 this.cachedServiceElements = null;
643                 this.filter(event);
644         },
645
646         filter: function(event){
647                 var needle = event.element().value.toLowerCase();
648                 
649                 if(this.cachedServiceElements == null){
650                         this.cachedServiceElements = $$('.sListRow');
651                 }
652                 
653                 for(var i = 0; i < this.cachedServiceElements.length; i++){
654                         var row = this.cachedServiceElements[i];
655                         var serviceName = row.readAttribute('data-servicename').toLowerCase();
656                         
657                         if(serviceName.match(needle) != needle && serviceName != ""){
658                                 row.hide();
659                         } else {                
660                                 row.show();
661                         }
662                 }
663         },
664         
665         addFilterInput: function(){
666                 var input = new Element('input');
667                 input.id = 'serviceFilter';
668                 input.value = 'Filter Services';                
669                 $('contentHdExt').update(input);                
670                 input.on('focus', this.onFilterFocus.bind(this));
671                 input.on('keyup', this.filter.bind(this));      
672         },
673         
674         onFinished: function(){
675                 this.addFilterInput();
676                 core.startUpdateBouquetItemsPoller();
677         }
678 });
679
680 var SignalWindow = Class.create(Controller, {
681         initialize: function($super, seconds){
682                 $super(new SignalHandler(this.show.bind(this)));
683                 this.window = '';
684                 if(!isNaN(Number(seconds))){
685                         this.seconds = seconds * 1000;
686                 } else {
687                         this.seconds = 5000;
688                 } 
689                 this.interval = '';
690         },
691         
692         load: function(){
693                 this.model.load({});
694         },
695         
696         reload: function(){
697                 debug('[SignalWindow].reload');
698                 if (!this.window.closed && this.window.location){
699                         this.load();
700                 } else {
701                         clearInterval(this.interval);
702                 }
703         },
704
705         show: function(html){
706                 debug('[SignalWindow].show');
707                 if (this.window.closed || !this.window.location){
708                         this.window = core.popup("SignalPanel", html, 220, 120);
709                         this.window.onbeforeunload = function(){
710                                 clearInterval(this.interval);
711                         };
712                         
713                         var _this = this;
714                         clearInterval(_this.interval);
715                         this.interval = setInterval(_this.reload.bind(this), _this.seconds);
716                 } else if(!this.window.closed && this.window.location) {
717                         this.window.document.write(html);
718                         this.window.document.close();
719                 }
720         }
721 });
722
723 var SimplePages = Class.create({
724         PAGE_ABOUT : 'tplAbout',
725         PAGE_GEARS : 'tplGears',
726         PAGE_MESSAGE : 'tplSendMessage',
727         PAGE_POWER : 'tplPower',
728         PAGE_SETTINGS: 'tplSettings',
729         PAGE_TOOLS: 'tplTools',
730         
731         initialize: function(target){
732                 this.simpleHandler = new SimplePageHandler(target);
733                 this.deviceInfoHandler = new DeviceInfoHandler(target);
734         },
735         
736         show: function(tpl, data){
737                 if(!data)
738                         data = {};
739                 this.simpleHandler.show(tpl, data);
740         },
741
742         loadAbout: function(){
743                 this.show(this.PAGE_ABOUT);
744         },
745         
746         loadGears: function(){
747                 var enabled = false;
748                 
749                 if (window.google && google.gears){
750                         enabled = gearsEnabled();
751                 }
752                 
753                 data = { 'useGears' : enabled };
754                 this.show(this.PAGE_GEARS, data);
755         },
756         
757         loadMessage: function(){
758                 this.show(this.PAGE_MESSAGE);
759         },
760         
761         loadPower: function(){
762                 this.show(this.PAGE_POWER);
763         },
764         
765         loadSettings: function(){
766                 var debug = userprefs.data.debug;
767                 var debugChecked = "";
768                 if(debug){
769                         debugChecked = 'checked';
770                 }
771                 
772                 var updateCurrentInterval = userprefs.data.updateCurrentInterval / 1000;
773                 var updateBouquetInterval = userprefs.data.updateBouquetInterval / 1000;
774
775                 data = {'debug' : debugChecked,
776                                 'updateCurrentInterval' : updateCurrentInterval,
777                                 'updateBouquetInterval' : updateBouquetInterval
778                 };
779                 this.show(this.PAGE_SETTINGS, data);
780         },
781         
782         loadTools: function(){
783                 this.show(this.PAGE_TOOLS);
784         },
785         
786         loadDeviceInfo: function(){
787                 this.deviceInfoHandler.load({});
788         },
789         
790         getDeviceInfo: function(callback){
791                 this.deviceInfoHandler.get({}, callback);
792         }
793 });
794
795 var Timers = Class.create({
796         initialize: function(target){
797                 this.listHandler = new TimerListHandler(target);
798                 this.timerHandler = new TimerHandler(target, this.loadList.bind(this), [this.onTimerEditLoadFinished.bind(this)]);
799         },
800         
801         loadList: function(){
802                 this.listHandler.load({});
803         },
804         
805         create: function(){
806                 this.timerHandler.load({}, false, true);
807         },
808         
809         edit: function(element){
810                 this.timerHandler.load(element, true);
811         },
812         
813         editFromEvent: function(element){
814                 this.timerHandler.load(element, false, false, true);
815         },
816         
817         save: function(element){
818                 this.timerHandler.commitForm(element);
819         },
820         
821         onBouquetChanged: function(bRef){
822                 this.timerHandler.onBouquetChanged(bRef, this.onUpdatedServiceListReady.bind(this));
823         },
824         
825         onUpdatedServiceListReady: function(data, timer){
826                 var serviceSel = $('service');
827                 var options = serviceSel.options;
828                 options.length = 0;
829                 
830                 var i = 0;
831                 data.services.each(function(s){
832                         var selected = false;
833                         if(timer.servicereference == unescape(s.servicereference)){
834                                 selected = true;
835                         }
836                         options.add ( new Option(s.servicename, s.servicereference, false, selected) );
837                         i++;
838                 });
839         },
840
841         recordNow: function(type, callback){
842                 this.timerHandler.recordNow(type, callback);
843         },
844         
845         addByEventId: function(element, justplay){
846                 var parent = element.up('.epgListItem');
847                 var sRef = unescape(parent.readAttribute('data-servicereference'));
848                 var eventId = unescape(parent.readAttribute('data-eventid'));
849                 this.timerHandler.addByEventId(sRef, eventId, justplay);
850         },
851         
852         toggleDisabled: function(element){
853                 this.timerHandler.toggleDisabled(element);
854         },
855         
856         del: function(element){
857                 this.timerHandler.del(element);
858         },
859         
860         onTimerEditLoadFinished: function(){
861                 debug("[Timers].onTimerEditLoadFinished");
862                 datePickerController.destroyDatePicker('sdate');
863                 datePickerController.destroyDatePicker('edate');
864                 var today = new Date();
865                 var pad = function(value, length) { 
866                         length = length || 2; 
867                         return "0000".substr(0,length - Math.min(String(value).length, length)) + value; 
868                 };
869                 var opts = { 
870                                 showWeeks: true,
871                                 noFadeEffect: true,
872                                 rangeLow: today.getFullYear() + "" + pad(today.getMonth()+1) + pad(today.getDate())
873                         };
874                 
875                 
876                 opts['formElements'] = { 'sdate' : 'Y-ds-m-ds-d'};
877                 datePickerController.createDatePicker(opts);
878                 
879                 opts['formElements'] = { 'edate' : 'Y-ds-m-ds-d'};
880                 datePickerController.createDatePicker(opts);
881
882         }
883 });
884
885 var Volume = Class.create(Controller, {
886         initialize: function($super, target){
887                 $super(new VolumeHandler(target));
888         },
889         
890         load: function(){
891                 this.model.load({});
892         },
893         
894         set: function(value){
895                 this.model.load({'set' : value});
896         }
897 });
898
899 var E2WebCore = Class.create({
900         initialize: function(){ 
901                 this.mediaPlayerStarted = false; 
902                 this.popUpBlockerHinted = false;
903                 this.settings = null;
904                 this.parentControlList = null;
905
906                 this.debugWin = '';
907                 this.signalWin = '';
908                 this.webRemoteWin = '';
909                 this.EPGListWin = '';
910
911                 this.currentBouquet = bouquetsTv;
912
913                 this.updateBouquetItemsPoller = '';
914                 this.updateCurrentPoller = '';
915                 this.signalPanelUpdatePoller = '';
916
917                 this.hideNotifierTimeout = '';
918
919                 this.isActive = {};
920                 this.isActive.getCurrent = false;
921                 
922                 this.locationsList = [];
923                 this.tagList = [];
924
925                 this.boxtype = "dm8000";
926                 this.mode = "";
927                 this.subMode = "";
928                 
929                 //create required Instances
930                 this.bouquets = new Bouquets('contentBouquets', 'contentMain');
931                 this.current = new Current('currentContent', 'volContent');
932                 this.epg = new EPG(new EpgListHandler());
933                 this.lt = new LocationsAndTags();
934                 this.mediaplayer = new MediaPlayer('contentMain');
935                 this.messages = new Messages();
936                 this.movies = new Movies('contentMain', 'navContent');
937                 this.power = new Power();
938                 this.remote = new RemoteControl();
939                 this.screenshots = new Screenshots('contentMain');
940                 this.services = new Services('contentServices', this.epg);
941                 this.signal = new SignalWindow(3);
942                 this.simplepages = new SimplePages('contentMain');
943                 this.timers = new Timers('contentMain');
944                 this.volume = new Volume('volContent');
945                 
946                 this.currentData = {};
947                 this.currentLocation = this.lt.getCurrentLocation(function(location){this.currentLocation = location;}.bind(this));
948                 this.currentTag = "";
949                 this.deviceInfo = this.simplepages.getDeviceInfo(function(info){this.deviceInfo = info;}.bind(this));
950                 
951                 this.navlut = {
952                         'tv': {
953                                 'bouquets' : this.bouquets.loadBouquetsTv.bind(this.bouquets), 
954                                 'provider' : this.bouquets.loadProviderTv.bind(this.bouquets),
955                                 'all' : this.services.loadAllTv.bind(this.services)
956                                 },
957                         'radio': {
958                                 'bouquets' : this.bouquets.loadBouquetsRadio.bind(this.bouquets),
959                                 'provider' : this.bouquets.loadProviderRadio.bind(this.bouquets),
960                                 'all' : this.services.loadAllRadio.bind(this.services)
961                         },
962                         'movies':{
963                                 'list' : function(){}
964                         },
965                         'timer': {
966                                 'create' : this.timers.create.bind(this.timers),
967                                 'edit' : false,
968                                 'list' : function() { this.loadContentDynamic(this.timers.loadList.bind(this.timers), 'Timer'); }.bind(this)
969                         },
970                         'control': {
971                                 'message' : this.simplepages.loadMessage.bind(this.simplepages),
972                                 'power' : this.simplepages.loadPower.bind(this.simplepages),
973                                 'osdshot' : this.screenshots.shootOsd.bind(this.screenshots),
974                                 'screenshot' : this.screenshots.shootAll.bind(this.screenshots),
975                                 'videoshot' : this.screenshots.shootVideo.bind(this.screenshots)
976                         },
977                         'extras': {
978                                 'about' : this.simplepages.loadAbout.bind(this.simplepages),
979                                 'deviceinfo' : this.simplepages.loadDeviceInfo.bind(this.simplepages),
980                                 'gears' : this.simplepages.loadGears.bind(this.simplepages),
981                                 'mediaplayer' : this.mediaplayer.load.bind(this.mediaplayer),
982                                 'settings' : this.simplepages.loadSettings.bind(this.simplepages),
983                                 'tools' : this.simplepages.loadTools.bind(this.simplepages)
984                         }
985                 };
986         },
987         
988         hideNotifier: function(){
989                 debug("[E2WebCore].hideNotifier");
990                 $('notification').fadeOut(500);
991         },
992
993         notify: function(text, state){
994                 debug("[E2WebCore].notify");
995                 notif = $('notification');
996
997                 if(notif !== null){
998                         //clear possibly existing hideNotifier timeout of a previous notfication
999                         clearTimeout(this.hideNotifierTimeout);
1000                         if(state === false){
1001                                 notif.style.background = "#C00";
1002                         } else {
1003                                 notif.style.background = "#85C247";
1004                         }                               
1005
1006                         this.set('notification', "<div>"+text+"</div>");
1007                         notif.fadeIn({'delay' : 500, 'to' : 90});
1008                         var _this = this;
1009                         this.hideNotifierTimeout = setTimeout(_this.hideNotifier.bind(this), 5000);
1010                 }
1011         },
1012         
1013         set: function(element, value){
1014                 element = parent.$(element);
1015                 if (element){
1016                         element.update(value);
1017                 }
1018         },
1019         
1020         setAjaxLoad: function(targetElement){
1021                 target = $(targetElement);
1022                 if(target != null){
1023                         target.update( getAjaxLoad() );
1024                 }
1025         },
1026         
1027         messageBox: function(message){
1028                 alert(message);
1029         },
1030         
1031         popUpBlockerHint: function(){
1032                 if(!this.popUpBlockerHinted){
1033                         this.popUpBlockerHinted = true;
1034                         this.messageBox("Please disable your Popup-Blocker for enigma2 WebControl to work flawlessly!");
1035
1036                 }
1037         },
1038         
1039         setWindowContent: function(window, html){
1040                 window.document.write(html);
1041                 window.document.close();
1042         },
1043         
1044         popup: function(title, html, width, height, x, y){
1045                 try {
1046                         var popup = window.open('about:blank',title,'scrollbars=yes, width='+width+',height='+height);          
1047                         this.setWindowContent(popup, html);
1048                         return popup;
1049                 } catch(e){
1050                         this.popUpBlockerHint();
1051                         return "";
1052                 }
1053         },
1054         
1055         updateItems: function(){
1056                 debug("[E2WebCore].updateItems");
1057                 this.current.load();
1058                 this.power.inStandby(this.onPowerStateAvailable.bind(this));
1059         },
1060         
1061         onPowerStateAvailable: function(isStandby){
1062                 if(isStandby){
1063                         $('openSignalPanelImg').src="/web-data/img/transmit_grey.png";
1064                 } else {
1065                         $('openSignalPanelImg').src="/web-data/img/transmit_blue.png";
1066                 }
1067         },
1068
1069         updateItemsLazy: function(){
1070                 debug("[E2WebCore].updateItemsLazy");
1071                 this.services.getNowNext();
1072                 this.services.getSubservices();
1073         },
1074         
1075         startUpdateCurrentPoller: function(){
1076                 debug("[E2WebCore].startUpdateCurrentPoller");
1077                 clearInterval(this.updateCurrentPoller);
1078                 var _this = this;
1079                 this.updateCurrentPoller = setInterval(_this.updateItems.bind(this), userprefs.data.updateCurrentInterval);
1080         },
1081         
1082         stopUpdateCurrentPoller: function(){
1083                 clearInterval(this.updateCurrentPoller);
1084         },
1085         
1086         startUpdateBouquetItemsPoller: function(){
1087                 debug("[E2WebCore].startUpdateBouquetItemsPoller");
1088                 clearInterval(this.updateBouquetItemsPoller);
1089                 var _this = this;
1090                 this.updateBouquetItemsPoller = setInterval(_this.updateItemsLazy.bind(this), userprefs.data.updateBouquetInterval);
1091         },
1092         
1093         stopUpdateBouquetItemsPoller: function(){
1094                 debug("[E2WebCore].stopUpdateBouquetItemsPoller");
1095                 clearInterval(this.updateBouquetItemsPoller);
1096         },
1097         
1098         onHashChanged: function(isReload){
1099                 var hash = hashListener.getHash();              
1100                 var parts = hash.split("/");
1101         
1102                 var len = parts.length;
1103                 if(len >= 2){
1104                         var mode = parts[1];
1105                         if(mode != this.mode || isReload || ( len <= 2 && this.subMode != '') ){
1106                                 this.switchMode(mode);
1107                                 this.subMode = '';
1108                         }
1109                         this.mode = mode;
1110                         if(len > 2){
1111                                 var subMode = parts[2];
1112                                 if(subMode != this.subMode || isReload){
1113                                         this.subMode = subMode;
1114                                         if(!this.navlut[this.mode][this.subMode]){
1115                                                 return;
1116                                         } else {
1117                                                 if(this.mode != "movies")
1118                                                         this.navlut[this.mode][this.subMode]();
1119                                         }
1120                                 }
1121                                 if(len > 3){
1122                                         switch(this.mode){
1123                                         case 'tv':
1124                                         case 'radio':
1125                                                 this.services.load(unescape(parts[3]));
1126                                                 break;
1127                                         case 'movies':
1128                                                 var location = decodeURIComponent(parts[4]);
1129                                                 var tag = decodeURIComponent(parts[5]);
1130                                                 
1131                                                 this.currentLocation = location;
1132                                                 this.currentTag = tag;
1133                                                 this.loadContentDynamic(
1134                                                         function(){
1135                                                                 this.movies.load(location, tag);
1136                                                         }.bind(this),
1137                                                         'Movies'
1138                                                 );
1139                                                 
1140                                                 break;
1141                                         case 'extras':
1142                                                 if(subMode == 'mediaplayer'){
1143                                                         this.mediaplayer.load(decodeURIComponent(parts[3]));
1144                                                 }
1145                                                 break;
1146                                         default:
1147                                                 return;
1148                                         }
1149                                 }
1150                         }
1151                 }
1152         },
1153         
1154         getBaseHash: function(){
1155                 var hash = ['#!', this.mode].join("/");
1156                 if(this.subMode != ''){
1157                         hash = [hash, this.subMode].join("/");
1158                 }
1159                 return hash;
1160         },
1161         
1162         loadDefault: function(){
1163                 debug("[E2WebCore].loadDefault");
1164                 this.switchMode('tv');
1165                 this.mode = 'tv';
1166                 this.subMode = 'bouquets';
1167                 this.bouquets.load(bouquetsTv, true);
1168         },
1169
1170         run: function(){
1171                 debug("[E2WebCore].run");
1172                 if( parseNr(userprefs.data.updateCurrentInterval) < 10000){
1173                         userprefs.data.updateCurrentInterval = 120000;
1174                         userprefs.save();
1175                 }
1176                 
1177                 if( parseNr(userprefs.data.updateBouquetInterval) < 60000 ){
1178                         userprefs.data.updateBouquetInterval = 300000;
1179                         userprefs.save();
1180                 }
1181                 
1182                 if (typeof document.body.style.maxHeight == undefined) {
1183                         alert("Due to the tremendous amount of work needed to get everthing to " +
1184                         "work properly, there is (for now) no support for Internet Explorer Versions below 7");
1185                 }
1186                 hashListener.onHashChanged = this.onHashChanged.bind(this);
1187                 hashListener.init();
1188                 
1189                 this.registerEvents();
1190                 
1191 //              TODO getBoxtype();
1192
1193                 this.setAjaxLoad('navContent');
1194                 this.setAjaxLoad('contentMain');
1195
1196                 templateEngine.fetch('tplServiceListEPGItem');
1197                 templateEngine.fetch('tplBouquetsAndServices');
1198                 templateEngine.fetch('tplCurrent');
1199                 if(!hashListener.getHash().length >= 1){
1200                         this.loadDefault();
1201                 }
1202                 this.updateItems();
1203                 this.startUpdateCurrentPoller();
1204         },
1205         
1206         registerEvents: function(){
1207                 debug("[E2WebCore].registerEvents");
1208                 //Hash-Reload-Fix
1209                 //HACK :: THIS IS EVIL VOODOO, DON'T TRY THIS AT HOME!
1210                 document.on(
1211                         'click',
1212                         'a',
1213                         function(event, element){ 
1214                                 var parts = element.href.split('#');
1215                                 var curHost = window.location.href.split('#')[0];
1216                                 //Don't do this crazy stuff when the target is another host!
1217                                 if(curHost == parts[0]){
1218                                         if (parts.length > 1){
1219                                                 if(parts[1] != ''){
1220                                                         if(window.location == element.href){
1221                                                                 this.onHashChanged(true);
1222                                                                 return;
1223                                                         }else{
1224                                                                 window.location == element.href;
1225                                                                 return;
1226                                                         }
1227                                                 } else {
1228                                                         element.href = window.location;
1229                                                 }
1230                                                 return false;
1231                                         }
1232                                 }
1233                         }.bind(this)
1234                 );
1235                 //Header
1236                 
1237                 $('openSignalPanel').on(
1238                         'click',
1239                         function(event, element){
1240                                 //FIXME
1241                                 $('openSignalPanel').href = '#';
1242                                 this.signal.load();
1243                         }.bind(this)
1244                 );
1245                 $('instantRecord').on(
1246                         'click',
1247                         function(event, element){
1248                                 //FIXME
1249                                 $('instantRecord').href = '#';
1250                                 var menu = $('instantRecordMenu');
1251                                 if(menu.visible()){
1252                                         menu.hide();
1253                                 } else {
1254                                         menu.show();
1255                                 }
1256                         }
1257                 );
1258                 document.on(
1259                         'click',
1260                         '.doInstantRecord',
1261                         function(event, element){
1262                                 var menu = $('instantRecordMenu');
1263                                 this.timers.recordNow(
1264                                         element.readAttribute('data-type'),
1265                                         function(result){
1266                                                 menu.hide();
1267                                         }
1268                                 );
1269                         }.bind(this)
1270                 );
1271                 //Current
1272                 $('current').on(
1273                         'click',
1274                         '.currentExtShowHide',
1275                         function(event, element){
1276                                 //FIXME
1277                                 element.href = '#';
1278                                 var ext = $('trExtCurrent');
1279                                 if(ext){
1280                                         if(ext.visible())
1281                                                 ext.hide();
1282                                         else
1283                                                 ext.show();
1284                                 }
1285                         }
1286                 );
1287                 $('current').on(
1288                                 'click',
1289                                 '.currentEpg',
1290                                 function(event, element){
1291                                         //FIXME
1292                                         element.href = '#';
1293                                         var ref = unescape( element.readAttribute('data-servicereference') );
1294                                         this.epg.load(ref);
1295                                 }.bind(this)
1296                         );
1297                 //Signal
1298                 $('openSignalPanel').on(
1299                         'click',
1300                         function(event, element){
1301                                 //TODO openSignalPanel
1302                         }
1303                 );
1304                 
1305                 //EPG-Search
1306                 $('epgSearchForm').on(
1307                         'submit',
1308                         function(event, element){
1309                                 this.epg.search($F('epgSearch'));
1310                                 return false;
1311                         }.bind(this)
1312                 );              
1313                 $('epgSearch').on(
1314                         'focus',
1315                         function(event, element){
1316                                 element.value = "";
1317                         }.bind(this)
1318                 );              
1319                 $('epgSearchClear').on(
1320                                 'click',
1321                                 function(event, element){
1322                                         $('epgSearch').value = '';
1323                                         return false;
1324                                 }.bind(this)
1325                 );              
1326                 //Movienav
1327                 var nav = $('navContent');
1328                 nav.on(
1329                         'change',
1330                         '.mNavLoc',
1331                         function(event, element){
1332                                 debug($("locations").value);
1333                                 debug($("tags").value);
1334                                 var hash = [this.getBaseHash(), "filter", encodeURIComponent($("locations").value), encodeURIComponent($("tags").value)].join("/");
1335                                 hashListener.setHash(hash);
1336                         }.bind(this)
1337                 );
1338                 nav.on(
1339                         'change',
1340                         '.mNavTags',
1341                         function(event, element){
1342                                 debug($("locations").value);
1343                                 debug($("tags").value);
1344                                 var hash = [this.getBaseHash(), "filter", encodeURIComponent($("locations").value), encodeURIComponent($("tags").value)].join("/");
1345                                 hashListener.setHash(hash);
1346                         }.bind(this)
1347                 );
1348                 //RemoteControl
1349                 nav.on(
1350                         'click',
1351                         '.webremote',
1352                         this.remote.open.bind(this.remote)
1353                 );
1354                 //Volume
1355                 $('navVolume').on(
1356                         'click',
1357                         'a.volume',
1358                         function(event, element){
1359                                 this.volume.set(element.readAttribute('data-volume'));
1360                                 return false;
1361                         }.bind(this)
1362                 );
1363                 
1364                 //Content
1365                 var content = $('contentMain');
1366                 //MediaPlayer
1367                 content.on(
1368                         'click',
1369                         '.mpCmd',
1370                         function(event, element){
1371                                 this.mediaplayer.command(element.readAttribute('data-command'));
1372                         }.bind(this)
1373                 );
1374                 content.on(
1375                         'click',
1376                         '.mpPlayFile',
1377                         function(event, element){
1378                                 element.href = '#'; //FIXME
1379                                 var parent = element.up('.mpListItem');
1380                                 var ref = decodeURIComponent( parent.readAttribute('data-servicereference') );
1381                                 this.mediaplayer.playFile(ref);
1382                         }.bind(this)
1383                 );
1384                 content.on(
1385                         'click',
1386                         '.mpRemoveFile',
1387                         function(event, element){
1388                                 element.href = '#'; //FIXME
1389                                 var parent = element.up('.mpListItem');
1390                                 var ref = decodeURIComponent( parent.readAttribute('data-servicereference') );
1391                                 this.mediaplayer.removeFile(ref);
1392                         }.bind(this)
1393                 );
1394                 content.on(
1395                                 'click',
1396                                 '.mpSavePlaylist',
1397                                 function(event, element){
1398                                         var filename = prompt('Please enter a filename for the playlist', 'playlist');
1399                                         if(filename != null && filename != ""){
1400                                                 this.mediaplayer.savePlaylist(filename);
1401                                         }
1402                                 }.bind(this)
1403                         );
1404                 //Message
1405                 content.on(
1406                         'click',
1407                         '.messageSend',
1408                         function(event, element){
1409                                 var t = $('messageType');
1410                                 text = $('messageText').value;
1411                                 timeout = $('messageTimeout').value;
1412                                 type = t.options[t.selectedIndex].value;
1413                                 this.messages.send(text, type, timeout);
1414                         }.bind(this)
1415                 );
1416                 //Movielist
1417                 content.on(
1418                         'click', 
1419                         'a.mListDelete', 
1420                         function(event, element){
1421                                 //FIXME
1422                                 element.href = '#';
1423                                 this.movies.del(element);
1424                                 return false;
1425                         }.bind(this)
1426                 );
1427                 //Powerstate
1428                 content.on(
1429                         'click',
1430                         '.powerState',
1431                         function(event, element){
1432                                 var cb = function(isStandby){
1433                                         var text = "Device is now Running";
1434                                         if(isStandby)
1435                                                 text = "Device is now in Standby";
1436                                         this.notify(text, true);
1437                                         this.onPowerStateAvailable(isStandby);
1438                                 }.bind(this);
1439                                 this.power.set(element.readAttribute("data-state"), cb);
1440                         }.bind(this)
1441                 );
1442                 //Settings
1443                 content.on(
1444                         'click',
1445                         '.saveSettings',
1446                         function(event, element){
1447                                 this.saveSettings();
1448                         }.bind(this)
1449                 );
1450                 //Servicelist
1451                 content.on(
1452                         'click', 
1453                         'a.sListSLink', 
1454                         function(event, element){
1455                                 //FIXME
1456                                 element.href = '#';
1457                                 var ref = decodeURIComponent( element.id );
1458                                 this.services.zap(ref);
1459                                 return false;
1460                         }.bind(this)
1461                 );
1462                 content.on(
1463                         'click', 
1464                         'a.sListServiceEpg', 
1465                         function(event, element){
1466                                 //FIXME
1467                                 element.href = '#';
1468                                 var ref = unescape( element.readAttribute('data-servicereference') );
1469                                 this.epg.load(ref);
1470                                 return false;
1471                         }.bind(this)
1472                 );
1473                 content.on(
1474                         'click', 
1475                         'a.sListExtEpg',
1476                         function(event, element){
1477                                 //FIXME
1478                                 element.href = '#';
1479                                 var target = element.down('.sListExtEpgLong');
1480                                 if(target){
1481                                         if(target.visible()){
1482                                                 target.hide();
1483                                         } else {
1484                                                 target.show();
1485                                         }
1486                                 }
1487                                 return false;
1488                         }.bind(this)
1489                 );
1490                 //Timerlist
1491                 content.on(
1492                         'click', 
1493                         '.tListDelete', 
1494                         function(event, element){               
1495                                 this.timers.del(element);
1496                                 return false;
1497                         }.bind(this)
1498                 );
1499                 content.on(
1500                         'click', 
1501                         '.tListToggleDisabled', 
1502                         function(event, element){
1503                                 this.timers.toggleDisabled(element);
1504                                 return false;
1505                         }.bind(this)
1506                 );
1507                 content.on(
1508                         'click', 
1509                         '.tListEdit', 
1510                         function(event, element){
1511                                 var hash = ["#!/timer", "edit"].join("/");
1512                                 hashListener.setHash(hash);
1513                                 this.timers.edit(element);
1514                                 return false;
1515                         }.bind(this)
1516                 );
1517                 //Timer Editing
1518                 content.on(
1519                         'change',
1520                         '.tEditRepeated',
1521                         function(event, element){
1522                                 var days = ['mo', 'tu', 'we', 'th', 'fr', 'sa', 'su'];
1523                                 var weekdays = days.slice(0,5);
1524                                 
1525                                 switch(element.id){
1526                                 case 'mf':
1527                                         var checked = element.checked;
1528                                         weekdays.each(function(day){
1529                                                 $(day).checked = checked;
1530                                         });
1531                                         if(checked){
1532                                                 var others = ['sa', 'su', 'ms'];
1533                                                 others.each(function(item){
1534                                                         $(item).checked = false;
1535                                                 });
1536                                         }
1537                                         break;
1538                                 case 'ms':
1539                                         var checked = element.checked;
1540                                         days.each(function(day){
1541                                                 $(day).checked = checked;
1542                                         });
1543                                         if(checked){
1544                                                 $('mf').checked = false;
1545                                         }
1546                                         break;
1547                                 default:
1548                                         var weekdays = true;
1549                                         var alldays = true;
1550                                         days.each(function(day){
1551                                                 day = $(day);
1552                                                 if(day.value <= 64){
1553                                                         if(!day.checked){
1554                                                                 alldays = false;
1555                                                                 if(day.value <= 16){
1556                                                                         weekdays = false;
1557                                                                         return
1558                                                                 }
1559                                                         } else {
1560                                                                 if(day.value > 16){
1561                                                                         weekdays = false;
1562                                                                 }
1563                                                         }
1564                                                 }
1565                                         });
1566                                         if(alldays){
1567                                                 $('mf').checked = false;
1568                                                 $('ms').checked = true;
1569                                         } else if (weekdays) {
1570                                                 $('mf').checked = true;
1571                                                 $('ms').checked = false;
1572                                         } else {
1573                                                 $('mf').checked = false;
1574                                                 $('ms').checked = false;
1575                                         }
1576                                 }
1577                         }
1578                 );
1579                 content.on(
1580                         'change',
1581                         '.tEditBouquet',
1582                         function(event, element){
1583                                 var value = unescape( element.options[element.selectedIndex].value );
1584                                 core.timers.onBouquetChanged(value);
1585                         }.bind(this)
1586                 );
1587                 content.on(
1588                         'click',
1589                         '.tEditTag',
1590                         function(event, element){
1591                                 element.href = '#'; //FIXME
1592                                 var selected = 'selected';
1593                                 var attr = 'data-selected';
1594                                 if(element.hasClassName(selected)){
1595                                         element.removeClassName(selected);
1596                                         element.writeAttribute(attr, '');
1597                                 } else {
1598                                         element.addClassName(selected);
1599                                         element.writeAttribute(attr, selected);
1600                                 }
1601                         }.bind(this)
1602                 );
1603                 content.on(
1604                         'click',
1605                         '.tEditSave',
1606                         function(event, element){
1607                                 this.timers.save($('timerEditForm'));
1608                         }.bind(this)
1609                 );
1610                 
1611                 $('webTv').on(
1612                         'click',
1613                         function(event, element){
1614                                 window.open('/web-data/streaminterface.html', 'WebTV', 'scrollbars=no, width=800, height=740');
1615                         }.bind(this)
1616                 );
1617         },
1618
1619         /*
1620          * Loads another navigation template and sets the navigation header
1621          * @param template - The name of the template
1622          * @param title - The title to set for the navigation
1623          */
1624         reloadNav: function(template, title){
1625                 this.setAjaxLoad('navContent');
1626                 templateEngine.process(template, null, 'navContent');
1627                 setNavHd(title);
1628         },
1629
1630         reloadNavDynamic: function(fnc, title){
1631                 this.setAjaxLoad('navContent');
1632                 setNavHd(title);
1633                 fnc();
1634         },
1635
1636         /*
1637          * Loads dynamic content to $(contentMain) by calling a execution function
1638          * @param fnc - The function used to load the content
1639          * @param title - The Title to set on the contentpanel
1640          */
1641         loadContentDynamic: function(fnc, title){
1642                 setContentHd(title);
1643                 this.stopUpdateBouquetItemsPoller();
1644                 fnc();
1645         },
1646
1647         /*
1648          * Loads a static template to $(contentMain)
1649          * @param template - Name of the Template
1650          * @param title - The Title to set on the Content-Panel
1651          */
1652         loadContentStatic: function(template, title){
1653                 this.setAjaxLoad('contentMain');
1654                 setContentHd(title);
1655                 this.stopUpdateBouquetItemsPoller();
1656                 templateEngine.process(template, null, 'contentMain');
1657         },
1658         
1659         switchMode: function(mode){
1660                 switch(mode){
1661                 case "tv":
1662                         if(this.mode != 'tv' && this.mode != 'radio'){
1663                                 this.services.registerEvents();
1664                         }
1665                         this.reloadNav('tplNavTv', 'TeleVision');
1666                         break;
1667         
1668                 case "radio":
1669                         if(this.mode != 'TV' && this.mode != 'Radio'){
1670                                 this.services.registerEvents();
1671                         }               
1672                         this.reloadNav('tplNavRadio', 'Radio');
1673                         break;
1674         
1675                 case "movies":  
1676                         this.reloadNavDynamic(this.movies.loadNav.bind(this.movies), 'Movies');
1677 //                      this.loadContentDynamic(this.movies.load.bind(this.movies), 'Movies');
1678                         break;
1679         
1680                 case "timer":
1681                         this.reloadNav('tplNavTimer', 'Timer');
1682 //                      this.loadContentDynamic(this.timers.loadList.bind(this.timers), 'Timer');
1683                         break;
1684         
1685                 case "mediaplayer":
1686                         //TODO this.loadContentDynamic(loadMediaPlayer, 'MediaPlayer');
1687                         debug("mediaplayer not implemented");
1688                         break;
1689         
1690                 case "control":
1691                         this.reloadNav('tplNavBoxControl', 'BoxControl');
1692                         break;
1693         
1694                 case "extras":
1695                         this.reloadNav('tplNavExtras', 'Extras');
1696                         break;
1697                         
1698                 default:
1699                         break;
1700                 }
1701         },
1702         
1703         saveSettings: function(){
1704                 userprefs.load();
1705                 
1706                 var debug = $('enableDebug').checked;
1707                 var changed = false;
1708                 if(debug != undefined){
1709                         if( userprefs.data.debug != debug ){
1710                                 userprefs.data.debug = debug;
1711                                 changed = true;
1712                         }
1713                 }
1714                 
1715                 var updateCurrentInterval = parseNr( $F('updateCurrentInterval') ) * 1000;
1716                 if( updateCurrentInterval < 10000){
1717                         updateCurrentInterval = 120000;
1718                 }
1719                 
1720                 if( userprefs.data.updateCurrentInterval != updateCurrentInterval){
1721                         userprefs.data.updateCurrentInterval = updateCurrentInterval;
1722                         
1723                         changed = true;
1724                         this.startUpdateCurrentPoller();
1725                 }
1726                 
1727                 var updateBouquetInterval = parseNr( $F('updateBouquetInterval') )  * 1000;
1728                 if( updateBouquetInterval < 60000){
1729                         updateBouquetInterval = 300000;
1730                 }
1731                 
1732                 if( userprefs.data.updateBouquetInterval != updateBouquetInterval){
1733                         userprefs.data.updateBouquetInterval = updateBouquetInterval;
1734                         
1735                         changed = true;
1736                         this.startUpdateBouquetItemsPoller();
1737                 }
1738                 
1739                 if(changed){
1740                         userprefs.save();
1741                         this.notify("Settings saved");
1742                 } else {
1743                         this.notify("Nothing changed! No need to save!");
1744                 }
1745         }
1746 });
1747 core = new E2WebCore();