Changed to MADDE; moved sb1 files to zouba.sb1 and made new zouba.madde for madde...
[ptas] / zouba.sb1 / wrt / preview / script / nokia.js
1 /*
2         @chinnapp
3 */
4
5 if(typeof NOKIA == "undefined" || !NOKIA) 
6 {
7         var NOKIA = {
8                 version : 'WRT 1.1',
9                 currentDevice : '240x320',
10                 mode : 'portrait',
11                 resolution : ['240x320', '320x240', '360x640', '800x352'],
12                 scriptsLoaded : {
13                         loader : false,
14                         widget : false,
15                         systeminfo : false,
16                         menu   : false,
17                         menuItem : false,
18                         console : false
19                 }
20         };
21         NOKIA.namespace = function(name)
22         {
23                 var parts = name.split('.');
24                 var current = NOKIA;
25                 for(var key in parts){
26                         if(!current[parts[key]]){
27                                 current[parts[key]] = {};
28                         }
29                         current = current[parts[key]];
30                 }  
31         };
32         
33         NOKIA.init = function()
34         {
35                 // Not-Supported Browser check
36                 NOKIA.emulator.is_browserReady = (/MSIE/i.test(navigator.userAgent));
37                 if(NOKIA.emulator.is_browserReady)
38                 {
39                         var notSupportedBrowser = NOKIA.helper.readCookie('NOKIA_NOT_SUPPORTED_BROWSER');
40                         if (notSupportedBrowser != 1) {
41                                 $("#NotificationDiv")[0].className = 'show';
42                                 $("#NotificationDiv").dialog({
43                                         width: 550,
44                                         minWidth: 550,
45                                         minHeight: 350,
46                                         height: 150,
47                                         autoOpen: true,
48                                         position: top,
49                                         title: 'Notification window',
50                                         buttons: {
51                                                 Cancel: function(){
52                                                         $("#NotificationDiv").dialog('close');
53                                                 },
54                                                 Continue: function(){
55                                                         $("#NotificationDiv").dialog('close');
56                                                         NOKIA.helper.createCookie('NOKIA_NOT_SUPPORTED_BROWSER', 1);
57                                                         NOKIA.init();
58                                                 }
59                                         }
60                                 });
61                                 return false;
62                         }else{
63                                 $("#BrowserNotificationBar").css({display:'block'});
64                                 $("#BrowserNotificationBar > p > a").click(function(){ $("#BrowserNotificationBar").hide(); });
65                         }
66                 }
67         
68                 $('iframe')[0].src = "wrt_preview_main.html";
69
70                 NOKIA.data.load(deviceResolutionList);
71                 
72                 var url = window.location.toString();                   
73                 url = url.split('/');
74                 
75                 var pointer = 3;
76                 if(url[0] == 'http:')
77                         pointer = 2;
78
79                 var t = ''; 
80                 for(var i=pointer; i<url.length-1; i++){        t = t + url[i] + '/';   }
81                 if(url[0] == 'file:')
82                         NOKIA.emulator.url = 'file:///' + t;
83                 else
84                         NOKIA.emulator.url = 'http://' + t;
85
86                 //      Common Error/Notification Dialog
87                 NOKIA.helper.errorDailog = $("#Dialog").dialog({
88                         bgiframe: true, minHeight: 150, width: 450, modal: true, autoOpen: false,
89                         buttons: {      
90                                         Cancel: function(){ $(this).dialog('close');    },                      
91                                         Reload: function(){ 
92                                                 $(this).dialog('close');
93                                                 $("#loaderDiv").html("Widget is reloading. Please wait...");
94                                                 $("#loaderDiv")[0].className = 'green';
95                                                 $("#loaderDiv").show();
96                                                 window.setTimeout(function(){
97                                                         document.location = document.location;
98                                                 }, 3000);
99                                         }                       
100                                 }
101                 });
102
103                 //      validating Info.plist
104                 this.helper.getInfo('Info.plist', NOKIA.helper.getInfoCallback);        
105
106                 //      For getting Icon.png
107                 this.helper.getInfo('Icon.png', NOKIA.helper.getIconCallback);  
108         };
109
110         /*
111          * NOKIA.data
112          */
113         NOKIA.namespace('data.load');
114
115         NOKIA.data.load = function(data){
116                 NOKIA.deviceList = data;
117         }
118
119
120
121         /*
122          * NOKIA.emulator
123          */
124         NOKIA.namespace('menu');
125         NOKIA.menu = {
126                 is_menu_visible : false,                // true/false
127                 is_softkeys_visible : false,    // true : only when MenuItem's are displayed
128                 softkeys_visibility : true,             // true/false : for hide/show SFK's
129                 is_dimmed : false,
130                 is_rsk_overridden : false,
131                 log_counter : 1,
132                 enable_log : false,
133                 rsk_label : '',
134                 rsk_event : false,
135                 highlighted_item : null,
136                 
137                 hide : function()
138                 {
139                         $("#MenuItemsArea").fadeIn("slow");
140
141                         //      Hide the SFK's If user hidden them from his code
142                         if(NOKIA.menu.softkeys_visibility)
143                                 $("#SoftKeysArea").fadeIn("slow");
144                         
145                         NOKIA.menu.is_softkeys_visible = false;
146                 },
147
148                 log : function(str)
149                 {
150                         if(!this.enable_log)
151                                 return false;
152                         NOKIA.layout.log("log", NOKIA.menu.log_counter + ' ' +str);
153                         NOKIA.layout.log("log", 'is_rsk_overridden: '+NOKIA.menu.is_rsk_overridden);
154                         NOKIA.layout.log("log", 'rsk_label: '+NOKIA.menu.rsk_label);
155                         NOKIA.layout.log("log", 'rsk_event: '+NOKIA.menu.rsk_event);
156                         
157                         NOKIA.menu.log_counter++;
158                 },
159
160                 show : function()
161                 {
162                         if(NOKIA.menu.is_dimmed)
163                                 return false;
164                                 
165                         NOKIA.menu.showSoftKeys();
166                         
167                         NOKIA.menu.is_menu_visible = true;
168                         $("#MenuItemsArea").show();
169                         
170                         NOKIA.menu.highlighted_item = $("#MenuItemsArea > ul > li")[0];
171                         NOKIA.menu.highlighted_item.className = 'active';
172
173
174                         $("#MenuItemsArea > ul > li").mouseover(function(){
175                                 if(NOKIA.menu.highlighted_item != null)
176                                 {
177                                         NOKIA.menu.highlighted_item.className = '';
178                                         NOKIA.menu.highlighted_item = null;
179                                 }
180
181                                 NOKIA.menu.highlighted_item = this;
182                                 NOKIA.menu.highlighted_item.className = 'active';
183                         });
184
185                         $("#SoftKeysArea").mouseout(function(){
186                                 if (!NOKIA.menu.is_menu_visible) {
187                                         return false;
188                                 }
189                                 
190                                 if (NOKIA.helper.intervalId) {
191                                         clearInterval(NOKIA.helper.intervalId);
192                                 }
193                                 NOKIA.helper.intervalId = setTimeout(function(){
194                                         NOKIA.menu.cancel()
195                                 }, 500);
196                         });
197
198
199                         //      Change the label "Options" to "Select" to LSK
200                         $("#LskLabel > a")[0].innerHTML = "Select";
201                         NOKIA.menu.setLsk(NOKIA.menu.selectMenu);
202                         
203                         //      Change the label "Exit" to "Cancel" to RSK
204                         $("#RskLabel > a")[0].innerHTML = 'Cancel';
205                         NOKIA.menu.setRsk(NOKIA.menu.cancel);
206                         
207
208                         NOKIA.emulator.setMenuItemsStyle();
209                         
210                 },
211                 
212                 selectMenu : function(){
213                         try {
214                                 if(typeof NOKIA.menu.highlighted_item.onclick != 'undefined'){
215                                         eval(NOKIA.menu.highlighted_item.onclick)();
216                                 }
217                         } catch (e) {
218                                 
219                         }
220 //                      NOKIA.menu.cancel();
221                 },
222
223                 
224                 cancel : function()
225                 {
226                         if(NOKIA.menu.is_dimmed)
227                                 return false;
228                                 
229                         NOKIA.menu.hideSoftKeys();
230
231                         NOKIA.menu.is_menu_visible = false;
232                         $("#MenuItemsArea").hide();
233
234                         //      Reset the "OPTION" label to LSK
235                         $("#LskLabel > a")[0].innerHTML = 'Options';
236                         NOKIA.menu.setLsk(NOKIA.emulator.child.menu.show);
237
238                         //      Change the label "CANCEL" to "EXIT" to RSK
239                         if(!NOKIA.menu.is_rsk_overridden)
240                         {
241                                 $("#RskLabel > a")[0].innerHTML = 'Exit';
242                                 NOKIA.menu.setRsk(NOKIA.menu.exit);     
243                         }
244                         else
245                         {
246                                 $("#RskLabel > a")[0].innerHTML = NOKIA.menu.rsk_label;
247                                 NOKIA.menu.setRsk(NOKIA.menu.rsk_event);        
248                         }
249                         
250                 },
251
252                 exit : function()
253                 {
254                         if(NOKIA.menu.is_dimmed)
255                                 return false;
256                                 
257                         if(NOKIA.helper.setHomeScreen())
258                                 return false;
259
260                         //      clear the Menu Settings
261                         NOKIA.menu.cancel();
262                         NOKIA.emulator.child.menu.setRightSoftkeyLabel('', null);
263                         NOKIA.emulator.child.menu.items = [];
264                         NOKIA.menu.softkeys_visibility = false;
265                         
266                         // Hide Widget DIV
267                         NOKIA.menu.hideSoftKeys();
268                         NOKIA.menu.setLsk(function(){});
269                         NOKIA.menu.setRsk(function(){});
270                         
271                         $("#WidgetArea").hide();
272
273                         //      Show Icon
274                         var style = NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode]['style'];
275                         $('#IconArea').css({
276                                 'width'         :       '100%',
277                                 'height'        :       style['widget']['height']+'px',
278                                 'float'         :       style['widget']['float']
279                         });
280                         
281                         $('#IconArea')[0].className = NOKIA.mode+NOKIA.currentDevice;
282                         
283                         var img = document.createElement('img');
284                         img.src = NOKIA.emulator.iconFile;
285                         img.border = 0;
286                         
287                         var div = document.createElement('div');
288                         var p = document.createElement('p');
289                         
290                         if(NOKIA.emulator.plist.DisplayName.length <= 12)
291                                 p.innerHTML = NOKIA.emulator.plist.DisplayName; 
292                         else
293                                 p.innerHTML = NOKIA.emulator.plist.DisplayName.substr(0, 11) + '...' 
294
295                         div.className = 'IconFile';
296                         div.style.marginTop = parseInt(parseInt(style['widget']['height']/2)-80) + 'px';
297                         div.appendChild(img);
298                         img.onclick = function(){
299                                 
300                                 //      close the console DIV
301                                 NOKIA.layout._console_enabled = false;
302                                 NOKIA.layout.render();
303                                 
304                                 $("#loaderDiv").html("Widget is loading. Please wait...");
305                                 $("#loaderDiv")[0].className = 'green';
306                                 $("#loaderDiv").show();
307                                 window.setTimeout(function(){
308                                         document.location = document.location;
309                                 }, 3000);
310                                 
311                         };
312                         
313                         div.appendChild(p);
314
315                         $("#loaderDiv").html("Click on Icon to Launch Widget");
316                         $("#loaderDiv").show();
317                         $("#loaderDiv")[0].className = 'yellow';
318
319                         $('#IconArea').append(div);
320                         $('#IconArea').show();
321
322                         NOKIA.menu.is_dimmed = true;
323                         
324                         $("#PreferencesBtn").hide();
325                         $("#PreferencesTab").dialog('close');
326                         
327                 },
328                 
329                 setLsk : function(func)
330                 {
331                         //      for RSK
332                         $('#LskArea')[0].onclick = function(){
333                                 if(!NOKIA.menu.is_dimmed)
334                                         func();
335                         };
336                 
337                         $('#LskLabel > a')[0].onclick = function(){
338                                 if(!NOKIA.menu.is_dimmed)
339                                         func();
340                         };
341
342                         return true;
343                 },
344                 
345                 setRsk : function(func)
346                 {
347                         //      for RSK
348                         $('#RskArea')[0].onclick = function(){
349                                 if(!NOKIA.menu.is_dimmed)
350                                         func();
351                         };
352                         
353                         $('#RskLabel > a')[0].onclick = function(){
354                                 if(!NOKIA.menu.is_dimmed)
355                                         func();
356                         };
357                         
358                         return true;
359                 },
360
361
362                 triggerLsk : function(event)
363                 {
364                         var callback;
365                         if(NOKIA.mode == 'portrait')
366                                 callback = NOKIA.menu.lsk_event;
367                         else if( (NOKIA.mode == 'landscape') && (event.id =='LskLabel') )
368                                 callback = NOKIA.menu.lsk_event;
369                         else
370                                 callback = NOKIA.menu.rsk_event;
371                         
372                         if(typeof callback == 'function' && !NOKIA.menu.is_dimmed)
373                         {
374                                 callback();
375                         }
376                 },
377
378                 triggerRsk : function(event)
379                 {
380                         var callback;
381                         if(NOKIA.mode == 'portrait')
382                                 callback = NOKIA.menu.rsk_event;
383                         else if( (NOKIA.mode == 'landscape') && (event.id =='RskLabel') )
384                                 callback = NOKIA.menu.rsk_event;
385                         else
386                                 callback = NOKIA.menu.lsk_event;
387                         
388                         if(typeof callback == 'function')
389                         {
390                                 if(!NOKIA.menu.is_dimmed)
391                                 {
392                                         callback();
393                                         NOKIA.menu.cancel();
394                                 }
395                         }
396                 },
397                 
398                 render : function()
399                 {
400                         if(!NOKIA.menu.softkeys_visibility)
401                                 NOKIA.menu.hideSoftKeys();
402                         else
403                                 NOKIA.menu.showSoftKeys();
404                         
405                         NOKIA.emulator.setWidgetStyle();
406                 },
407                 
408
409                 init : function()
410                 {
411                         NOKIA.menu.render();
412                 },
413                 
414                 createSFKArea : function()
415                 {
416                         var a = $('#SoftKeys > a');
417                         a.html('');
418                         
419                         var preferences = NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode];
420                         
421                         var lsk = document.createElement('img');
422                         lsk.border="0";
423                         lsk.id = "LskArea";
424                         lsk.name ="LskArea";
425                         lsk.src = "preview/images/TransperantImage.png";
426                         lsk.style.width = preferences.style.softkeysImg.width; 
427                         lsk.style.height = preferences.style.softkeysImg.height;
428                         
429                         var rsk = document.createElement('img');
430                         rsk.border = 0;
431                         rsk.id = "RskArea";
432                         rsk.name = "RskArea";
433                         rsk.src = "preview/images/TransperantImage.png";
434                         rsk.style.width = preferences.style.softkeysImg.width; 
435                         rsk.style.height = preferences.style.softkeysImg.height;
436
437                         if(NOKIA.mode == 'portrait')
438                         {       
439                                 lsk.onclick = function(){
440                                         $("#LskLabel > a").trigger('click');
441                                 }
442                                 a[0].appendChild(lsk);
443
444                                 rsk.onclick = function(){
445                                         $("#RskLabel > a").trigger('click');
446                                 }
447                                 a[1].appendChild(rsk);
448
449                         }else{
450
451                                 rsk.onclick = function(){
452                                         $("#RskLabel > a").trigger('click');
453                                 }
454                                 a[0].appendChild(rsk);
455
456                                 lsk.onclick = function(){
457                                         $("#LskLabel > a").trigger('click');
458                                 }
459                                 a[1].appendChild(lsk);
460                         }
461                         
462                         
463                 },
464
465                 showSoftKeys : function()
466                 {
467                         NOKIA.menu.is_softkeys_visible = true;
468
469                         NOKIA.emulator.setWidgetStyle();
470                         $("#SoftKeysArea").show();
471                 },
472                 
473                 hideSoftKeys : function()
474                 {
475                         //      Hide the SFK's If user hidden them from his code
476                         if(!NOKIA.menu.softkeys_visibility)
477                                 $("#SoftKeysArea").hide();
478                         
479                         NOKIA.menu.is_softkeys_visible = false;
480
481                         NOKIA.emulator.setWidgetStyle();
482                 }
483         };
484
485
486
487         /*
488          * NOKIA.emulator
489          */
490         NOKIA.namespace('emulator');
491         NOKIA.emulator = {
492                 child : false,
493                 iconFile : 'preview/images/default-Icon.png',
494                 loaded : false,
495                 plist : {
496                         DisplayName     :       '',
497                         Identifier      :       '',
498                         MainHTML        :       '',
499                         AllowNetworkAccess      :       "false",
500                         Version         :       '',
501                         MiniViewEnabled         :       "false",
502                         is_browserReady : false
503                 },
504                 
505                 load : function()
506                 {
507                         if(this.loaded)
508                                 return false;
509                                 
510                         //      load the saved device Info
511                         var device = NOKIA.helper.readCookie('NOKIA_EMULATOR_DEVICE');
512                         NOKIA.currentDevice = device || NOKIA.currentDevice;
513
514
515                         //      load the saved device mode
516                         var mode = NOKIA.helper.readCookie('NOKIA_EMULATOR_DEVICE_MODE');
517                         if(mode != null)
518                                 NOKIA.mode = mode;
519
520                         //      SAVE the device DATA
521                         NOKIA.helper.createCookie('NOKIA_EMULATOR_DEVICE', NOKIA.currentDevice);
522                         NOKIA.helper.createCookie('NOKIA_EMULATOR_DEVICE_MODE', NOKIA.mode);
523                         
524                         this.loaded = true;
525                         
526                 },
527         
528                 render : function()
529                 {
530                         this.load();
531                         
532                         if(!NOKIA.emulator.orientationSupports())
533                                 NOKIA.mode = NOKIA.deviceList[NOKIA.currentDevice]['default'];
534                         
535                         if(typeof NOKIA.deviceList == 'undefined' || typeof NOKIA.deviceList[NOKIA.currentDevice] == 'undefined' || typeof NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode] == 'undefined')
536                         {
537                                 alert('Deive resolution: '+NOKIA.currentDevice+' or the mode: '+NOKIA.mode+' not found');
538                                 return false;
539                         }
540                         
541                         this.setStyle();
542                 },
543                 
544                 setMode : function(mode)
545                 {
546                         NOKIA.mode = mode;
547
548                         //      SAVE the device DATA
549                         NOKIA.helper.createCookie('NOKIA_EMULATOR_DEVICE_MODE', NOKIA.mode);
550
551                         NOKIA.emulator.render();
552                 },
553                 
554                 orientationSupports : function()
555                 {
556                         return NOKIA.deviceList[NOKIA.currentDevice]['orientation'];
557                 },
558                 
559                 setStyle:function()
560                 {
561                         if(!NOKIA.helper.checkDependencies())
562                         {
563                                 setTimeout(NOKIA.emulator.setStyle, 1000);
564                         }
565                         
566                         var deviceProperties = NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode];
567                         var style = deviceProperties['style'];
568
569                         //      Apply Style and propertis to Device layers
570                         $("#DeviceDisplayLayout").css(style['layout']);
571                         $('#DisplayArea').css(style['display']);
572                         
573                         NOKIA.emulator.setWidgetStyle();
574                         
575                         $('#SoftKeysArea').css({
576                                 'width' :       style['menu']['width']+'px',
577                                 'height'        :       style['menu']['height']+'px',
578                                 'float'         :       style['menu']['float']
579                         });
580                         
581                         $('#SoftKeysArea > ul > li').css('width', parseInt(style['menu']['width']/2)-10);
582
583                         
584                         NOKIA.emulator.setMenuItemsStyle();
585                         
586                         $('#SoftKeys').css(style['softkeys']);
587 //                      $('#SoftKeys > a > img').css(style['softkeysImg']);
588
589                         NOKIA.menu.createSFKArea();
590                         
591                         $("#DeviceDisplayLayout").show();
592                         $("#PreferencesTab").show();
593                         
594                         if(!NOKIA.menu.is_dimmed)
595                                 $("#PreferencesBtn").show();
596                 },
597                 
598                 setWidgetStyle : function()
599                 {
600                         var style = NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode]['style'];
601                         var height;
602                         if(NOKIA.menu.softkeys_visibility || NOKIA.menu.is_softkeys_visible)
603                                 height = parseInt(style['widget']['height'] - style['menu']['height']);
604                         else
605                                 height = style['widget']['height'];
606
607                         $('#WidgetArea').css({
608                                 'width'         :       style['widget']['width']+'px',
609                                 'height'        :       height+'px',
610                                 'float'         :       style['widget']['float']
611                         });
612                 },
613                 
614                 setMenuItemsStyle : function()
615                 {
616                         var style       = NOKIA.deviceList[NOKIA.currentDevice][NOKIA.mode]['style'];
617                         var count = 1;
618                         try {
619                                 if (NOKIA.emulator.child.menu) {
620                                         count = parseInt(NOKIA.helper.getElementsLengthInObject(NOKIA.emulator.child.menu.items)) + 1;
621                                 }
622                         } catch (e) {
623                                 count = 1;
624                         }
625                         var height      = parseInt(count*style['menu']['optionKeysheight']) + 10;
626                         var top         = parseInt(style['widget']['height'] - height); 
627
628                         $('#MenuItemsArea').css({
629                                 'width'         :       style['widget']['width']+'px',
630                                 'height'        :       height+'px',
631                                 'marginTop'     :       '-2px',
632                                 'top'           :       (style['widget']['height']-height-style['menu']['height']+2)+'px',
633                                 'position'      :       'relative'
634                         });
635                 }
636         };
637
638         /*
639          * NOKIA.helper functions
640          */
641         NOKIA.namespace('helper.loadScript');
642         NOKIA.helper = {
643                 path : document.location.pathname,
644                 errorDailog     : null,
645                 prefDailog : null,
646                 intervalId : null,
647                 infoPlistCounter : false,
648                 IconFileCounter  : false,
649                 loadScript : function(path)
650                 {
651                         var head = document.getElementsByTagName("head")[0] || document.documentElement;
652                         var script = document.createElement("script");
653         
654                         script.type = "text/javascript";
655                         script.src = src;
656                         head.appendChild( script );
657                 },
658
659                 loadPreferences : function()
660                 {
661                         if(/dreamweaver/i.test(navigator.userAgent))
662                         {
663                                 $("#dwDeviceHelp")[0].className = '';
664                                 $("#resSupportLink")[0].className = 'hide';
665                         }
666                         //      Selecting Resoltion
667                         var resOptions = $("#resOptions")[0];
668                         for(var i=0; i<NOKIA.resolution.length; i++)
669                         {
670                                 if(NOKIA.resolution[i] == NOKIA.currentDevice)
671                                 {
672                                         resOptions.options[i].selected = true;
673                                         $("#resSupportLink")[0].href = resOptions.options[i].value;
674                                         break;
675                                 }                               
676                         }
677                         
678                         //      Selecting Orientation
679                         if(NOKIA.mode == 'portrait')
680                                 $('#input_portrait')[0].checked = true;
681                         else
682                                 $('#input_landscape')[0].checked = true;
683
684                         if (!NOKIA.emulator.orientationSupports()) {
685                                 if (NOKIA.mode == 'portrait') 
686                                         $("#input_landscape")[0].disabled = true;
687                                 else 
688                                         $("#input_portrait")[0].disabled = true;
689                                         
690                                 $("#Orientation_Info").html("Not supported");
691                                 $("#Orientation_Info").show();
692                                 $("#Orientation_Controls").hide();
693                         }
694                         else {
695                                 $("#input_landscape")[0].disabled = false;
696                                 $("#input_portrait")[0].disabled = false;
697
698                                 $("#Orientation_Info").hide();
699                                 $("#Orientation_Controls").show();
700                         }
701                         
702                         //      Selecting Version
703                         if(NOKIA.version == 'WRT 1.0')
704                                 $('#wrt_version_1_0')[0].checked = true;
705                         else
706                                 $('#wrt_version_1_1')[0].checked = true;
707                                 
708                         //      HomeScreen Support
709                         if(NOKIA.deviceList[NOKIA.currentDevice].homeScreenSupport)
710                         {
711                                 if (typeof NOKIA.emulator.plist.MiniViewEnabled != 'undefined') {
712                                         if (NOKIA.emulator.plist.MiniViewEnabled == 'false') 
713                                                 $('#HS_Control_Info').html("<span id='wrt-help' onclick='javascipt:NOKIA.helper.showMiniviewHelp();'></span><strong>Not Enabled</strong><br/><small>Click on help to read more about enabling Mini view support</small>");
714                                         else 
715                                                 $('#HS_Control_Info').html("Supported");
716                                 }
717                                 else
718                                         $('#HS_Control_Info').html("<span id='wrt-help'></span>Not Supported");
719
720                                 $('#HS_Control_Info').show();
721
722                         }
723                         else
724                         {
725                                 $('#HS_Control_Info').html("Not Supported for the selected Device resolution");
726                                 $('#HS_Control_Info').show();
727                         }
728                 },
729
730                 getInfo : function(url, callback)
731                 {
732                         try {
733                                 var xhr = this.ajax();
734                                 
735                                 if ((/AppleWebKit/i.test(navigator.userAgent)))
736                                         xhr.open("GET", url, false);
737                                 else
738                                         xhr.open("GET", url, true);
739                                 
740                                 
741                                 xhr.onreadystatechange = function() 
742                                 {
743                                                 // readyState = 4 ; "complete"
744                                                 if (xhr.readyState==4)
745                                                 {
746                                                         // status = 200 ; "ok"
747                                                         if( (xhr.status == 200) || (!xhr.status) )
748                                                         {
749                                                                 callback(true, xhr);
750                                                         }
751                                                         else
752                                                         { 
753                                                                 callback(false, xhr);
754                                                         }
755                                                 }
756         
757                                 }
758                                 xhr.send(null);
759                         } catch (e) {
760                                 if (e.name == 'NS_ERROR_FILE_NOT_FOUND') {
761                                         callback(false, xhr);
762                                 }                       
763                         }
764                 },
765
766                 getInfoCallback : function(flag, xhr)
767                 {
768                         //      If Info.plis NOT FOUND / FAILED LOAD
769                         //      an ERROR!, unable to proceed further
770                         //      STOP there
771                         if(!flag)
772                         {
773                                 if(!NOKIA.helper.infoPlistCounter)
774                                 {
775                                         NOKIA.helper.infoPlistCounter = true;
776                                         NOKIA.helper.getInfo('info.plist', NOKIA.helper.getInfoCallback);
777                                         return false;
778                                 }
779
780                                 NOKIA.helper.error('Unable to intialize the widget, failed to process Info.plist file. <br/>Please ensure <strong style="color:#efe352;">Info.plist</strong> file exists on the widget root folder <br/>or check the filename of <strong style="color:#efe352;">Info.plist</strong> It is case-sensitive');
781                                 return false;
782                         }
783                         else{
784                                 
785                                 var xmlString = xhr.responseText;
786                                 
787                                 // do some cheating here
788                                 xmlString = xmlString.replace(/<\s*true\s*\/>/gi, "<string>true</string>");
789                                 xmlString = xmlString.replace(/<\s*false\s*\/>/gi, "<string>false</string>");
790         
791                         /*
792                          *      DomParser Logic
793                                 var appXml = new DOMParser();
794                                 var xmlobject = appXml.parseFromString(xmlString, "text/xml");
795                          */
796                         
797                                 //      return the JSON Object
798                                 NOKIA.helper.validate(xml2json.parser(xmlString));
799                         }
800                         
801                 },
802                 
803                 getIconCallback : function(flag, xhr)
804                 {
805                         
806                         if(!flag)
807                         {
808                                 if(!NOKIA.helper.IconFileCounter)
809                                 {
810                                         NOKIA.helper.IconFileCounter = true;
811                                         NOKIA.helper.getInfo('icon.png', NOKIA.helper.getIconCallback);
812                                         return false;   
813                                 }
814                         }
815                         else
816                                 NOKIA.emulator.iconFile =  (NOKIA.helper.IconFileCounter) ? "icon.png" : "Icon.png";
817                 },
818                 
819
820                 validate : function(xmlObject)
821                 {
822                         window.xmlObject = xmlObject;
823                         
824                         //      <plist>
825                         if(typeof xmlObject.plist != 'object' || xmlObject.plist == 'undefined')
826                         {
827                                 NOKIA.helper.error('Corrupted Info.plist file');
828                                 return false;
829                         }
830                         //      <dict>
831                         xmlObject = xmlObject.plist;
832                         if(typeof xmlObject.dict != 'object' || xmlObject.dict == 'undefined')
833                         {
834                                 NOKIA.helper.error('Corrupted Info.plist file');
835                                 return false;
836                         }
837
838                         //      <key>
839                         xmlObject = xmlObject.dict;
840                         if(typeof xmlObject.key != 'object' || xmlObject.key == 'undefined')
841                         {
842                                 NOKIA.helper.error('Corrupted Info.plist file');
843                                 return false;
844                         }
845
846                         //      <string>
847                         if(typeof xmlObject.string != 'object' || xmlObject.string == 'undefined')
848                         {
849                                 NOKIA.helper.error('Corrupted Info.plist file');
850                                 return false;
851                         }
852
853                         //      num of <key> = num of <string>
854                         if(xmlObject.key.length != xmlObject.string.length)
855                         {
856                                 NOKIA.helper.error('Corrupted Info.plist file');
857                                 return false;
858                         }
859
860                         for(var val in xmlObject.key)
861                         {
862                                 if(NOKIA.emulator.plist[xmlObject.key[val]] != 'undefined'){
863                                         NOKIA.emulator.plist[xmlObject.key[val]] = xmlObject.string[val].toString(); 
864                                 }
865                         }
866
867                         try {
868                                 if(typeof NOKIA.emulator.plist.DisplayName != 'undefined'){
869                                         document.title = NOKIA.emulator.plist.DisplayName + ' - ' + document.title;
870                                 }
871                         } catch (e) {}
872
873                         //      Add UI-Event listeners
874                         NOKIA.helper.addListeners();
875                         NOKIA.layout.init();
876                         NOKIA.emulator.render();
877                 },
878
879
880                 ajax : function() 
881                 {
882                         //      xmlHttpRequest object   
883                         var request = null;
884                 
885                     // branch for native XMLHttpRequest object
886                     if(window.XMLHttpRequest && !(window.ActiveXObject)) {
887                         try 
888                                 {
889                                         request = new XMLHttpRequest();
890                                         try
891                                         {
892                                                 //      attach the Bypass code, if the browser is firefox
893                                                 if(netscape.security.PrivilegeManager.enablePrivilege)
894                                                 {
895                                                         //      duplicate the function
896                                                         request._open = request.open;
897                                                         
898                                                         //      redefine the function definition
899                                                         request.open = function(method, url, flag)
900                                                         {
901                                                                 try
902                                                                 {
903                                                                         // Enable Universal Browser Read
904                                                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
905                 
906                                                                         //      call the native XmlHttpRequest.open method
907                                                                         this._open(method, url, flag);
908                                                                 }catch(e)
909                                                                 {
910                                                                         //      call the native XmlHttpRequest.open method
911                                                                         this._open(method, url, flag);
912                                                                 }
913                                                         }
914                                                 }
915                                         }
916                                         catch(e)
917                                         {
918                                                 //      eatup all exceptions
919                                         }
920                                 } 
921                                 catch(e) {
922                                         request = null;
923                         }
924                     // branch for IE/Windows ActiveX version
925                     } else if(window.ActiveXObject) {
926                         try {
927                                 request = new ActiveXObject("Msxml2.XMLHTTP");
928                         } catch(e) {
929                                 try {
930                                         request = new ActiveXObject("Microsoft.XMLHTTP");
931                                 } catch(e) {
932                                         alert('Failed to create XmlHttprequest');
933                                                 return null;
934                                 }
935                                 }
936                     }
937                         
938                         return (request);
939                 },
940
941                 error : function(msg)
942                 {
943                         if(NOKIA.menu.enable_log)
944                                 NOKIA.layout.log("log", msg);
945                         
946                         $("#Dialog").html(msg);
947                         $("#Dialog").dialog('open');
948                 },
949
950                 createCookie : function(name,value) 
951                 {
952                         var days = 240000;
953                     if (days) {
954                                 var date = new Date();
955                                 date.setTime(date.getTime()+(days*24*60*60*1000));
956                                 var expires = "; expires="+date.toGMTString();
957                         }
958                         else var expires = "";
959                         document.cookie = "Nokia_WRT#" + NOKIA.helper.path + "#" + name + "=" + value + expires + "; path=/";
960                 },
961                 
962                 readCookie : function(name) 
963                 {
964                         var nameEQ = "Nokia_WRT#" + NOKIA.helper.path + "#" + name + "=";
965                         var ca = document.cookie.split(';');
966                         for(var i=0;i < ca.length;i++) {
967                                 var c = ca[i];
968                                 while (c.charAt(0)==' ') c = c.substring(1,c.length);
969                                 if (c.indexOf(nameEQ) == 0) {
970                                         return c.substring(nameEQ.length,c.length);
971                                 }
972                         }
973                         return undefined;
974                 },
975
976                 toggle : function(ele)
977                 {
978                         if (NOKIA.emulator.orientationSupports()) {
979 //                              var mode = (NOKIA.mode == 'portrait') ? 'landscape' : 'portrait';
980                                 NOKIA.emulator.setMode(ele.value);
981                         }
982                         else
983                         {       
984                                 ele.checked = false;
985                                 if(ele.value == 'portrait')
986                                         $("#input_landscape")[0].checked = true;
987                                 else
988                                         $("#input_portrait")[0].checked = true;
989                         }
990                 },
991
992                 version : function(ele)
993                 {
994                         if (confirm('Would you like to reload the widget to apply the changes on the Version settings?')) 
995                         {
996                                 NOKIA.helper.createCookie('_WRT_VERSION', ele.value);
997                                 $("#loaderDiv").html("Applying the " + ele.value + ", please wait...");
998                                 $("#loaderDiv").show();
999                                 $("#loaderDiv")[0].className = 'green';
1000                                 
1001                                 $("#PreferencesTab").dialog('close');
1002                                 
1003                                 window.setTimeout(function(){
1004                                         document.location = document.location;
1005                                 }, 3000);
1006                         }
1007                         else
1008                         {
1009                                 ele.checked = false;
1010                                 if(ele.value != 'WRT 1.0')
1011                                         $("#wrt_version_1_0")[0].checked = true;
1012                                 else
1013                                         $("#wrt_version_1_1")[0].checked = true;
1014                         }
1015                 },
1016
1017                 addListeners : function()
1018                 {
1019                         /*
1020                          * Render Emulator for Interaction
1021                          */
1022                         NOKIA.helper.prefDailog = $("#PreferencesTab").dialog({
1023                                         width: 550,     minWidth: 550, minHeight: 350, height: 350, autoOpen: false, position : top, title : '&nbsp;',
1024                                         buttons : {
1025                                                 Close : function(){
1026                                                         $("#PreferencesTab").dialog('close');
1027
1028                                                         //      Hack for Mac firefox
1029                                                         if(/Mac/i.test(navigator.userAgent))
1030                                                         {
1031                                                                 $("#WidgetArea iframe").css({overflow:'auto'});
1032                                                         }
1033                                                         
1034                                                         //      select index : 0 tab selected
1035                                                         $('#tabs').tabs( 'select' , 0);
1036                                                 }
1037                                         }
1038                                 });
1039                                 
1040                         $('#PreferencesBtn').click(function(){
1041                                 //      Load preferences
1042                                 NOKIA.helper.loadPreferences();
1043                                 $('#PreferencesTab').dialog('open');
1044
1045                                 //      Hack for Mac firefox
1046                                 if(/Mac/i.test(navigator.userAgent))
1047                                 {
1048                                         $("#WidgetArea iframe").css({overflow:'hidden'});
1049                                 }
1050                         });
1051                         
1052                         $('#input_portrait').change(function(){
1053                                 NOKIA.helper.toggle(this);
1054                         });
1055
1056                         $('#input_landscape').change(function(){
1057                                 NOKIA.helper.toggle(this);
1058                         });
1059
1060                         $('#resOptions').change(function(ele){
1061                                 ele = ele.target || this;
1062                                 
1063                                 NOKIA.currentDevice = ele.options[ele.selectedIndex].text;
1064                                 $("#resSupportLink")[0].href = ele.value;
1065                 
1066                                 //      SAVE the device DATA
1067                                 NOKIA.helper.createCookie('NOKIA_EMULATOR_DEVICE', NOKIA.currentDevice);
1068                 
1069                                 NOKIA.emulator.render();
1070                                 NOKIA.helper.loadPreferences();
1071                         });
1072
1073                         //      Hack for Mac firefox
1074                         if (/Mac/i.test(navigator.userAgent)) {
1075                                 if (!(/AppleWebKit/i.test(navigator.userAgent))) {
1076                                         $("#resOptions")[0].size = '4';
1077                                 }
1078                         }
1079
1080
1081                         //      WRT Version controls
1082                         $('#wrt_version_1_0').change(function(){
1083                                 NOKIA.helper.version(this);
1084                         });
1085                         
1086                         $('#wrt_version_1_1').change(function(){
1087                                 NOKIA.helper.version(this);
1088                         });
1089
1090
1091                         $("#orientationIcon").click(function(){
1092                                 var mode = (NOKIA.mode == 'portrait') ? 'landscape' : 'portrait';
1093                                 NOKIA.emulator.setMode(mode);
1094                                 $("#WidgetArea")[0].className = 'hs_'+NOKIA.mode;
1095                         });
1096
1097
1098                         $("#iframeMask").click(function(){
1099
1100                                 $("#PreferencesBtn").show();
1101                                 $("#orientationIcon").hide();
1102                                 $("#iframeMask").hide();
1103                                 $("#loaderDiv").hide();
1104
1105                                 NOKIA.menu.is_dimmed = false;
1106                                 
1107                                 $("#WidgetArea")[0].className = '';
1108                                 
1109                                 NOKIA.menu.softkeys_visibility = true;
1110                                 NOKIA.menu.showSoftKeys();
1111
1112                         });
1113
1114
1115                         //      MenuItems DIV events
1116                         $("#MenuItemsArea").mouseover(function(){
1117                                 if(NOKIA.helper.intervalId)
1118                                         clearInterval(NOKIA.helper.intervalId);
1119
1120                                 $("#MenuItemsArea").show();
1121                         });
1122
1123                         $("#MenuItemsArea").mouseout(function(){
1124                                 if(NOKIA.helper.intervalId)
1125                                         clearInterval(NOKIA.helper.intervalId);
1126
1127                                 NOKIA.helper.intervalId = setTimeout(function(){
1128                                         NOKIA.menu.cancel()
1129                                 }, 500);
1130                         });
1131
1132
1133                         // Tabs
1134                         $('#tabs').tabs({
1135                                 select : function(event, ui){
1136                                         if(parseInt(ui.index) == 1)
1137                                         {
1138                                                 $("#event-icons").show();
1139                                                 $("#event-battery-info").hide();
1140                                                 $("#event-messaging-info").hide();
1141                                                 $("#event-memory-info").hide();
1142                                                 
1143                                                 //      WRT versionn check
1144                                                 if(NOKIA.version == 'WRT 1.1')
1145                                                 {
1146                                                         $("#event-messaging")[0].className = 'active';
1147                                                         $("#event-memory")[0].className = 'active';
1148                                                 }else
1149                                                 {
1150                                                         $("#event-messaging")[0].className = 'inactive';
1151                                                         $("#event-memory")[0].className = 'inactive';
1152                                                 }
1153                                                 $("#event-battery")[0].className = 'active';
1154                                         }else if(parseInt(ui.index) == 0)
1155                                         {
1156                                                 $("#settings-view").show();
1157                                                 $("#mini-view-info").hide();
1158                                         }
1159                                 }
1160                         });
1161
1162                         
1163                         /*      
1164                          *      Event triggering
1165                          */
1166                         
1167                         //      for battery
1168                         $("#event-battery").click(function(event){
1169                                 if(event.target.className == 'active')
1170                                 {
1171                                         $("#event-icons").hide();
1172                                         $("#event-battery-info").show();
1173
1174 /*
1175                                 $('#slider').slider('option', 'value', NOKIA.emulator.child._BRIDGE_REF.helper.getBatteryStrength());
1176                                 NOKIA.emulator.child._BRIDGE_REF.helper.getBatteryStrength()
1177                                 $('#slider').slider('option', 'value', 10);
1178                                 $('#slider').slider();
1179 */
1180                                 }
1181                         });
1182
1183                         $("#event-battery-back").click(function(event){
1184                                 $("#event-icons").show();
1185                                 $("#event-battery-info").hide();
1186                         });
1187
1188
1189                         //      for messaging
1190                         $("#event-messaging").click(function(event){
1191                                 if(event.target.className == 'active')
1192                                 {
1193                                         $("#event-icons").hide();
1194                                         $("#event-messaging-info").show();
1195                                 }
1196                         });
1197
1198                         $("#event-messaging-back").click(function(event){
1199                                 $("#event-icons").show();
1200                                 $("#event-messaging-info").hide();
1201                         });
1202
1203
1204                         //      for memory
1205                         $("#event-memory").click(function(event){
1206                                 if(event.target.className == 'active')
1207                                 {
1208                                         $("#event-icons").hide();
1209                                         $("#event-memory-info").show();
1210                                 }
1211                         });
1212
1213                         $("#event-memory-back").click(function(event){
1214                                 $("#event-icons").show();
1215                                 $("#event-memory-info").hide();
1216                         });
1217
1218
1219                         //      for minView more info
1220                         $("#mini-view-back").click(function(event){
1221                                 $("#settings-view").show();
1222                                 $("#mini-view-info").hide();
1223                         });
1224
1225
1226                         // Slider
1227                         $('#slider').slider({
1228                                 range: true,
1229                                 min : 0,
1230                                 max : 100,
1231                                 step : 1,
1232                                 value : 10,
1233                                 animate: true,
1234                                 slide: function(event, ui) {
1235                                         $("#slider-value-panel > span").html(ui.value.toString());
1236                                 }
1237                                 });
1238
1239                         //      Bind Buttons to trigger values to WRT 1.0 / 1.1 bindings
1240                         
1241                         $("#connect-charger").click(NOKIA.helper.triggerEvents);
1242                         $("#disconnect-charger").click(NOKIA.helper.triggerEvents);
1243                         $("#update-batter-strength").click(NOKIA.helper.triggerEvents);
1244
1245                         $("#send-sms").click(NOKIA.helper.triggerEvents);
1246                         $("#send-mms").click(NOKIA.helper.triggerEvents);
1247
1248                         $("#connect-memory-card").click(NOKIA.helper.triggerEvents);
1249                         $("#disconnect-memory-card").click(NOKIA.helper.triggerEvents);
1250                         
1251                 },
1252                 
1253                 setHomeScreen : function()
1254                 {
1255                         //      HomeScreen Support
1256                         if (NOKIA.deviceList[NOKIA.currentDevice].homeScreenSupport) {
1257
1258                                 if (typeof NOKIA.emulator.plist.MiniViewEnabled != 'undefined') {
1259                                         if (NOKIA.emulator.plist.MiniViewEnabled != 'false') 
1260                                         {
1261                                                 $("#WidgetArea")[0].className = 'hs_' + NOKIA.mode;
1262                                                 
1263                                                 //      menu handlining
1264                                                 NOKIA.menu.softkeys_visibility = false;
1265                                                 NOKIA.menu.cancel();
1266                                                 NOKIA.menu.is_dimmed = true;
1267                                                 
1268
1269                                                 $("#loaderDiv").html("Click on widget for Return to Full view");
1270                                                 $("#loaderDiv")[0].className = 'green';
1271                                                 $("#loaderDiv").show();
1272
1273                                                 $("#iframeMask").show();
1274                                                 $("#orientationIcon").show();
1275                                                 $("#PreferencesBtn").hide();
1276
1277                                                 $("#PreferencesTab").dialog('close');
1278                                                 return true;
1279                                         }
1280                                 }
1281                         }
1282                         return false;                   
1283                 },
1284                 
1285                 getElementsLengthInObject : function(items){
1286                         var count = 0;
1287                         for (var i in items) 
1288                         {
1289                                 if(!items[i].isDimmed)
1290                                         count++;
1291                         }
1292                         
1293                         return count;
1294                 },
1295                 
1296                 triggerEvents : function(event)
1297                 {
1298                         if(typeof event.target.id == 'undefined')
1299                         return false;
1300                         
1301                         switch(event.target.id)
1302                         {
1303                                 //      for battery
1304                                 case 'connect-charger': 
1305                                                                                 NOKIA.helper.trigger("power", "chargerconnected", 1);
1306                                                                                 if(NOKIA.version == 'WRT 1.1')
1307                                                                                         NOKIA.helper.triggerSapi("Service.SysInfo", "Battery.ChargingStatus", {Status: 1});
1308                                                                                 break;
1309
1310                                 case 'disconnect-charger': 
1311                                                                                 NOKIA.helper.trigger("power", "chargerconnected", 0);
1312                                                                                 if(NOKIA.version == 'WRT 1.1')
1313                                                                                         NOKIA.helper.triggerSapi("Service.SysInfo", "Battery.ChargingStatus", {Status: 0});
1314                                                                                 break;
1315
1316                                 case 'update-batter-strength': 
1317                                                                                 var chargeValue = parseInt($('#slider').slider('value'));
1318                                                                                 NOKIA.helper.trigger("power", "chargelevel", chargeValue);
1319                                                                                 if(NOKIA.version == 'WRT 1.1')
1320                                                                                         NOKIA.helper.triggerSapi("Service.SysInfo", "Battery.BatteryStrength", {Status: chargeValue});
1321                                                                                 break;
1322
1323                                 //      for messaging
1324                                 case 'send-sms': 
1325                                                                                 if(NOKIA.version == 'WRT 1.1')
1326                                                                                         NOKIA.helper.triggerSapi("Service.Messaging", "NewMessage", {MessageType: 'SMS'});
1327                                                                                 break;
1328                                 case 'send-mms': 
1329                                                                                 if(NOKIA.version == 'WRT 1.1')
1330                                                                                         NOKIA.helper.triggerSapi("Service.Messaging", "NewMessage", {MessageType: 'MMS'});
1331                                                                                 break;
1332
1333                                 //      for memory
1334                                 case 'connect-memory-card': 
1335                                                                                 if(NOKIA.version == 'WRT 1.1')
1336                                                                                         NOKIA.helper.triggerSapi("Service.SysInfo", "Memory.MemoryCard", {Status: 1});
1337                                                                                 break;
1338                                 case 'disconnect-memory-card': 
1339                                                                                 if(NOKIA.version == 'WRT 1.1')
1340                                                                                         NOKIA.helper.triggerSapi("Service.SysInfo", "Memory.MemoryCard", {Status: 0});
1341                                                                                 break;
1342                         }
1343                 },      
1344
1345                 triggerSapi : function(provider, eventType, data){
1346                         NOKIA.emulator.child.device.implementation.triggerListener(provider, eventType, data);
1347                 },      
1348
1349                 trigger : function(provider, eventType, data){
1350                         NOKIA.emulator.child.widget.triggerListener(provider, eventType, data);
1351                 },
1352                 
1353                 showMiniviewHelp : function(){
1354                         $("#settings-view").hide();
1355                         $("#mini-view-info").show();
1356                 },
1357                 
1358                 checkDependencies : function(){
1359                         
1360                         for(var key in NOKIA.scriptsLoaded)
1361                         {
1362                                 if(!NOKIA.scriptsLoaded[key])
1363                                         return false;
1364                         }
1365
1366                         //      for LSK
1367                         NOKIA.menu.setLsk(NOKIA.emulator.child.menu.show);
1368                 
1369                         //      for RSK
1370                         NOKIA.menu.setRsk(NOKIA.menu.exit);
1371
1372                         return true;
1373                 }
1374         };
1375         
1376
1377         /*
1378          * NOKIA.layout functions
1379          */
1380         NOKIA.namespace('layout');
1381         NOKIA.layout = {
1382                 _console_minimized : true,
1383                 _console_enabled : false,
1384                 _consoleWindowHeight : 200,
1385                 _consoleHeaderHeight : 31,
1386
1387                 init : function(){
1388                         
1389                         //      Toggle console window
1390                         $('#Console-Toggle-Button').click(function(){
1391                                 
1392                                 NOKIA.layout._console_minimized = (NOKIA.layout._console_minimized) ? false : true;
1393                                 NOKIA.layout.render();
1394                         });
1395                         
1396                         // clear Log
1397                         $("#Console-Clear-Button").click(function(){
1398                                 $("#preview-ui-bottom-body")[0].innerHTML = '';
1399                         });
1400
1401
1402                         $('#preview-ui-bottom').show();
1403                         NOKIA.layout.render();
1404                 },
1405                 
1406                 log : function(type, msg){
1407                         var p = document.createElement('p');
1408                         p.className = type;
1409                         p.innerHTML = msg;
1410                         var divBody = $('#preview-ui-bottom-body')
1411                         divBody.append(p);
1412                         divBody[0].scrollTop = divBody[0].scrollHeight;
1413                 },
1414                 
1415                 
1416                 render : function(){
1417                         var _width = parseInt(window.innerWidth);
1418                         var _height = parseInt(window.innerHeight);
1419                         
1420                         if(!NOKIA.layout._console_enabled)
1421                         {
1422                                 $('#preview-ui-bottom').css({
1423                                         display: 'none'
1424                                 });
1425                                 
1426                                 $('#preview-ui-top').css({
1427                                         height: _height+'px'
1428                                 });
1429
1430                                 return false;
1431                         }
1432                         
1433                         
1434                         if(!NOKIA.layout._console_minimized)
1435                         {
1436                                 $('#Console-Toggle-Button')[0].className = 'open';
1437                                 
1438                                 //      set STYLE details for TOP window
1439                                 $('#preview-ui-top').css({
1440                                         height: parseInt(_height - NOKIA.layout._consoleWindowHeight) + 'px'
1441                                 });
1442                                 
1443                                 //      set STYLE details for Bottom window
1444                                 $('#preview-ui-bottom').css({
1445                                         height: NOKIA.layout._consoleWindowHeight + 'px',
1446                                         display : 'block'
1447                                 });
1448
1449                                 $('#preview-ui-bottom-header').css({
1450                                         height: NOKIA.layout._consoleHeaderHeight + 'px'
1451                                 });
1452
1453                                 $('#preview-ui-bottom-body').css({
1454                                         height: parseInt(NOKIA.layout._consoleWindowHeight - NOKIA.layout._consoleHeaderHeight) + 'px',
1455                                         display : 'block'
1456                                 });
1457                                 
1458                                 // Auto scroll when console window opened from MINIMIZED => MAXIMIZED state
1459                                 window.setTimeout(function(){
1460                                         $('#preview-ui-bottom-body')[0].scrollTop = $('#preview-ui-bottom-body')[0].scrollHeight;
1461                                 }, 100);
1462                                 
1463                         }else{
1464                                 $('#Console-Toggle-Button')[0].className = 'close';
1465
1466                                 //      set STYLE details for TOP window
1467                                 $('#preview-ui-top').css({
1468                                         height: parseInt(_height - NOKIA.layout._consoleHeaderHeight) + 'px'
1469                                 });
1470                                 
1471                                 //      set STYLE details for Bottom window
1472                                 $('#preview-ui-bottom').css({
1473                                         height: NOKIA.layout._consoleHeaderHeight + 'px',
1474                                         display : 'block'
1475                                 });
1476
1477                                 $('#preview-ui-bottom-header').css({
1478                                         height: NOKIA.layout._consoleHeaderHeight + 'px',
1479                                         display : 'block'
1480                                 });
1481
1482                                 $('#preview-ui-bottom-body').css({
1483                                         display : 'none'
1484                                 });
1485                         }
1486                 }
1487                 
1488         };
1489 }
1490
1491 $(document).ready(function () {
1492         NOKIA.init();   
1493 });
1494
1495 window.onresize = NOKIA.layout.render;