Changed to MADDE; moved sb1 files to zouba.sb1 and made new zouba.madde for madde...
[ptas] / zouba.sb1 / misc / rss / 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;
618                         try {
619                                 count = parseInt(NOKIA.helper.getElementsLengthInObject(NOKIA.emulator.child.menu.items))+1;
620                         } catch (e) {
621                                 count = 1;
622                         }
623                         var height      = parseInt(count*style['menu']['optionKeysheight']) + 10;
624                         var top         = parseInt(style['widget']['height'] - height); 
625
626                         $('#MenuItemsArea').css({
627                                 'width'         :       style['widget']['width']+'px',
628                                 'height'        :       height+'px',
629                                 'marginTop'     :       '-2px',
630                                 'top'           :       (style['widget']['height']-height-style['menu']['height']+2)+'px',
631                                 'position'      :       'relative'
632                         });
633                 }
634         };
635
636         /*
637          * NOKIA.helper functions
638          */
639         NOKIA.namespace('helper.loadScript');
640         NOKIA.helper = {
641                 path : document.location.pathname,
642                 errorDailog     : null,
643                 prefDailog : null,
644                 intervalId : null,
645                 infoPlistCounter : false,
646                 IconFileCounter  : false,
647                 loadScript : function(path)
648                 {
649                         var head = document.getElementsByTagName("head")[0] || document.documentElement;
650                         var script = document.createElement("script");
651         
652                         script.type = "text/javascript";
653                         script.src = src;
654                         head.appendChild( script );
655                 },
656
657                 loadPreferences : function()
658                 {
659                         //      Selecting Resoltion
660                         var resOptions = $("#resOptions")[0];
661                         for(var i=0; i<NOKIA.resolution.length; i++)
662                         {
663                                 if(NOKIA.resolution[i] == NOKIA.currentDevice)
664                                 {
665                                         resOptions.options[i].selected = true;
666                                         $("#resSupportLink")[0].href = resOptions.options[i].value;
667                                         break;
668                                 }                               
669                         }
670                         
671                         //      Selecting Orientation
672                         if(NOKIA.mode == 'portrait')
673                                 $('#input_portrait')[0].checked = true;
674                         else
675                                 $('#input_landscape')[0].checked = true;
676
677                         if (!NOKIA.emulator.orientationSupports()) {
678                                 if (NOKIA.mode == 'portrait') 
679                                         $("#input_landscape")[0].disabled = true;
680                                 else 
681                                         $("#input_portrait")[0].disabled = true;
682                                         
683                                 $("#Orientation_Info").html("Not supported");
684                                 $("#Orientation_Info").show();
685                                 $("#Orientation_Controls").hide();
686                         }
687                         else {
688                                 $("#input_landscape")[0].disabled = false;
689                                 $("#input_portrait")[0].disabled = false;
690
691                                 $("#Orientation_Info").hide();
692                                 $("#Orientation_Controls").show();
693                         }
694                         
695                         //      Selecting Version
696                         if(NOKIA.version == 'WRT 1.0')
697                                 $('#wrt_version_1_0')[0].checked = true;
698                         else
699                                 $('#wrt_version_1_1')[0].checked = true;
700                                 
701                         //      HomeScreen Support
702                         if(NOKIA.deviceList[NOKIA.currentDevice].homeScreenSupport)
703                         {
704                                 if (typeof NOKIA.emulator.plist.MiniViewEnabled != 'undefined') {
705                                         if (NOKIA.emulator.plist.MiniViewEnabled == 'false') 
706                                                 $('#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>");
707                                         else 
708                                                 $('#HS_Control_Info').html("Supported");
709                                 }
710                                 else
711                                         $('#HS_Control_Info').html("<span id='wrt-help'></span>Not Supported");
712
713                                 $('#HS_Control_Info').show();
714
715                         }
716                         else
717                         {
718                                 $('#HS_Control_Info').html("Not Supported for the selected Device resolution");
719                                 $('#HS_Control_Info').show();
720                         }
721                 },
722
723                 getInfo : function(url, callback)
724                 {
725                         try {
726                                 var xhr = this.ajax();
727                                 
728                                 if ((/AppleWebKit/i.test(navigator.userAgent)))
729                                         xhr.open("GET", url, false);
730                                 else
731                                         xhr.open("GET", url, true);
732                                 
733                                 
734                                 xhr.onreadystatechange = function() 
735                                 {
736                                                 // readyState = 4 ; "complete"
737                                                 if (xhr.readyState==4)
738                                                 {
739                                                         // status = 200 ; "ok"
740                                                         if( (xhr.status == 200) || (!xhr.status) )
741                                                         {
742                                                                 callback(true, xhr);
743                                                         }
744                                                         else
745                                                         { 
746                                                                 callback(false, xhr);
747                                                         }
748                                                 }
749         
750                                 }
751                                 xhr.send(null);
752                         } catch (e) {
753                                 if (e.name == 'NS_ERROR_FILE_NOT_FOUND') {
754                                         callback(false, xhr);
755                                 }                       
756                         }
757                 },
758
759                 getInfoCallback : function(flag, xhr)
760                 {
761                         //      If Info.plis NOT FOUND / FAILED LOAD
762                         //      an ERROR!, unable to proceed further
763                         //      STOP there
764                         if(!flag)
765                         {
766                                 if(!NOKIA.helper.infoPlistCounter)
767                                 {
768                                         NOKIA.helper.infoPlistCounter = true;
769                                         NOKIA.helper.getInfo('info.plist', NOKIA.helper.getInfoCallback);
770                                         return false;
771                                 }
772
773                                 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');
774                                 return false;
775                         }
776                         else{
777                                 
778                                 var xmlString = xhr.responseText;
779                                 
780                                 // do some cheating here
781                                 xmlString = xmlString.replace(/<\s*true\s*\/>/gi, "<string>true</string>");
782                                 xmlString = xmlString.replace(/<\s*false\s*\/>/gi, "<string>false</string>");
783         
784                         /*
785                          *      DomParser Logic
786                                 var appXml = new DOMParser();
787                                 var xmlobject = appXml.parseFromString(xmlString, "text/xml");
788                          */
789                         
790                                 //      return the JSON Object
791                                 NOKIA.helper.validate(xml2json.parser(xmlString));
792                         }
793                         
794                 },
795                 
796                 getIconCallback : function(flag, xhr)
797                 {
798                         
799                         if(!flag)
800                         {
801                                 if(!NOKIA.helper.IconFileCounter)
802                                 {
803                                         NOKIA.helper.IconFileCounter = true;
804                                         NOKIA.helper.getInfo('icon.png', NOKIA.helper.getIconCallback);
805                                         return false;   
806                                 }
807                         }
808                         else
809                                 NOKIA.emulator.iconFile =  (NOKIA.helper.IconFileCounter) ? "icon.png" : "Icon.png";
810                 },
811                 
812
813                 validate : function(xmlObject)
814                 {
815                         window.xmlObject = xmlObject;
816                         
817                         //      <plist>
818                         if(typeof xmlObject.plist != 'object' || xmlObject.plist == 'undefined')
819                         {
820                                 NOKIA.helper.error('Corrupted Info.plist file');
821                                 return false;
822                         }
823                         //      <dict>
824                         xmlObject = xmlObject.plist;
825                         if(typeof xmlObject.dict != 'object' || xmlObject.dict == 'undefined')
826                         {
827                                 NOKIA.helper.error('Corrupted Info.plist file');
828                                 return false;
829                         }
830
831                         //      <key>
832                         xmlObject = xmlObject.dict;
833                         if(typeof xmlObject.key != 'object' || xmlObject.key == 'undefined')
834                         {
835                                 NOKIA.helper.error('Corrupted Info.plist file');
836                                 return false;
837                         }
838
839                         //      <string>
840                         if(typeof xmlObject.string != 'object' || xmlObject.string == 'undefined')
841                         {
842                                 NOKIA.helper.error('Corrupted Info.plist file');
843                                 return false;
844                         }
845
846                         //      num of <key> = num of <string>
847                         if(xmlObject.key.length != xmlObject.string.length)
848                         {
849                                 NOKIA.helper.error('Corrupted Info.plist file');
850                                 return false;
851                         }
852
853                         for(var val in xmlObject.key)
854                         {
855                                 if(NOKIA.emulator.plist[xmlObject.key[val]] != 'undefined'){
856                                         NOKIA.emulator.plist[xmlObject.key[val]] = xmlObject.string[val].toString(); 
857                                 }
858                         }
859
860                         try {
861                                 if(typeof NOKIA.emulator.plist.DisplayName != 'undefined'){
862                                         document.title = NOKIA.emulator.plist.DisplayName + ' - ' + document.title;
863                                 }
864                         } catch (e) {}
865
866                         //      Add UI-Event listeners
867                         NOKIA.helper.addListeners();
868                         NOKIA.layout.init();
869                         NOKIA.emulator.render();
870                 },
871
872
873                 ajax : function() 
874                 {
875                         //      xmlHttpRequest object   
876                         var request = null;
877                 
878                     // branch for native XMLHttpRequest object
879                     if(window.XMLHttpRequest && !(window.ActiveXObject)) {
880                         try 
881                                 {
882                                         request = new XMLHttpRequest();
883                                         try
884                                         {
885                                                 //      attach the Bypass code, if the browser is firefox
886                                                 if(netscape.security.PrivilegeManager.enablePrivilege)
887                                                 {
888                                                         //      duplicate the function
889                                                         request._open = request.open;
890                                                         
891                                                         //      redefine the function definition
892                                                         request.open = function(method, url, flag)
893                                                         {
894                                                                 try
895                                                                 {
896                                                                         // Enable Universal Browser Read
897                                                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
898                 
899                                                                         //      call the native XmlHttpRequest.open method
900                                                                         this._open(method, url, flag);
901                                                                 }catch(e)
902                                                                 {
903                                                                         //      call the native XmlHttpRequest.open method
904                                                                         this._open(method, url, flag);
905                                                                 }
906                                                         }
907                                                 }
908                                         }
909                                         catch(e)
910                                         {
911                                                 //      eatup all exceptions
912                                         }
913                                 } 
914                                 catch(e) {
915                                         request = null;
916                         }
917                     // branch for IE/Windows ActiveX version
918                     } else if(window.ActiveXObject) {
919                         try {
920                                 request = new ActiveXObject("Msxml2.XMLHTTP");
921                         } catch(e) {
922                                 try {
923                                         request = new ActiveXObject("Microsoft.XMLHTTP");
924                                 } catch(e) {
925                                         alert('Failed to create XmlHttprequest');
926                                                 return null;
927                                 }
928                                 }
929                     }
930                         
931                         return (request);
932                 },
933
934                 error : function(msg)
935                 {
936                         if(NOKIA.menu.enable_log)
937                                 NOKIA.layout.log("log", msg);
938                         
939                         $("#Dialog").html(msg);
940                         $("#Dialog").dialog('open');
941                 },
942
943                 createCookie : function(name,value) 
944                 {
945                         var days = 240000;
946                     if (days) {
947                                 var date = new Date();
948                                 date.setTime(date.getTime()+(days*24*60*60*1000));
949                                 var expires = "; expires="+date.toGMTString();
950                         }
951                         else var expires = "";
952                         var value = "Nokia_WRT#"+NOKIA.helper.path+"#"+name+"="+value;
953                         document.cookie = value+expires+"; Emulator.path=/"
954                 },
955                 
956                 readCookie : function(name) 
957                 {
958                         name = "Nokia_WRT#" + NOKIA.helper.path + "#" + name;           
959                         var nameEQ = name + "=";
960                         var ca = document.cookie.split(';');
961                         for(var i=0;i < ca.length;i++) {
962                                 var c = ca[i];
963                                 while (c.charAt(0)==' ') c = c.substring(1,c.length);
964                                 if (c.indexOf(nameEQ) == 0) {
965                                         return c.substring(nameEQ.length,c.length);
966                                 }
967                         }
968                         return undefined;
969                 },
970
971                 toggle : function(ele)
972                 {
973                         if (NOKIA.emulator.orientationSupports()) {
974 //                              var mode = (NOKIA.mode == 'portrait') ? 'landscape' : 'portrait';
975                                 NOKIA.emulator.setMode(ele.value);
976                         }
977                         else
978                         {       
979                                 ele.checked = false;
980                                 if(ele.value == 'portrait')
981                                         $("#input_landscape")[0].checked = true;
982                                 else
983                                         $("#input_portrait")[0].checked = true;
984                         }
985                 },
986
987                 version : function(ele)
988                 {
989                         if (confirm('Would you like to reload the widget to apply the changes on the Version settings?')) 
990                         {
991                                 NOKIA.helper.createCookie('_WRT_VERSION', ele.value);
992                                 $("#loaderDiv").html("Applying the " + ele.value + ", please wait...");
993                                 $("#loaderDiv").show();
994                                 $("#loaderDiv")[0].className = 'green';
995                                 
996                                 $("#PreferencesTab").dialog('close');
997                                 
998                                 window.setTimeout(function(){
999                                         document.location = document.location;
1000                                 }, 3000);
1001                         }
1002                         else
1003                         {
1004                                 ele.checked = false;
1005                                 if(ele.value != 'WRT 1.0')
1006                                         $("#wrt_version_1_0")[0].checked = true;
1007                                 else
1008                                         $("#wrt_version_1_1")[0].checked = true;
1009                         }
1010                 },
1011
1012                 addListeners : function()
1013                 {
1014                         /*
1015                          * Render Emulator for Interaction
1016                          */
1017                         NOKIA.helper.prefDailog = $("#PreferencesTab").dialog({
1018                                         width: 550,     minWidth: 550, minHeight: 350, height: 350, autoOpen: false, position : top, title : '&nbsp;',
1019                                         buttons : {
1020                                                 Close : function(){
1021                                                         $("#PreferencesTab").dialog('close');
1022
1023                                                         //      Hack for Mac firefox
1024                                                         if(/Mac/i.test(navigator.userAgent))
1025                                                         {
1026                                                                 $("#WidgetArea iframe").css({overflow:'auto'});
1027                                                         }
1028                                                         
1029                                                         //      select index : 0 tab selected
1030                                                         $('#tabs').tabs( 'select' , 0);
1031                                                 }
1032                                         }
1033                                 });
1034                                 
1035                         $('#PreferencesBtn').click(function(){
1036                                 //      Load preferences
1037                                 NOKIA.helper.loadPreferences();
1038                                 $('#PreferencesTab').dialog('open');
1039
1040                                 //      Hack for Mac firefox
1041                                 if(/Mac/i.test(navigator.userAgent))
1042                                 {
1043                                         $("#WidgetArea iframe").css({overflow:'hidden'});
1044                                 }
1045                         });
1046                         
1047                         $('#input_portrait').change(function(){
1048                                 NOKIA.helper.toggle(this);
1049                         });
1050
1051                         $('#input_landscape').change(function(){
1052                                 NOKIA.helper.toggle(this);
1053                         });
1054
1055                         $('#resOptions').change(function(ele){
1056                                 ele = ele.target || this;
1057                                 
1058                                 NOKIA.currentDevice = ele.options[ele.selectedIndex].text;
1059                                 $("#resSupportLink")[0].href = ele.value;
1060                 
1061                                 //      SAVE the device DATA
1062                                 NOKIA.helper.createCookie('NOKIA_EMULATOR_DEVICE', NOKIA.currentDevice);
1063                 
1064                                 NOKIA.emulator.render();
1065                                 NOKIA.helper.loadPreferences();
1066                         });
1067
1068                         //      Hack for Mac firefox
1069                         if (/Mac/i.test(navigator.userAgent)) {
1070                                 if (!(/AppleWebKit/i.test(navigator.userAgent))) {
1071                                         $("#resOptions")[0].size = '4';
1072                                 }
1073                         }
1074
1075
1076                         //      WRT Version controls
1077                         $('#wrt_version_1_0').change(function(){
1078                                 NOKIA.helper.version(this);
1079                         });
1080                         
1081                         $('#wrt_version_1_1').change(function(){
1082                                 NOKIA.helper.version(this);
1083                         });
1084
1085
1086                         $("#orientationIcon").click(function(){
1087                                 var mode = (NOKIA.mode == 'portrait') ? 'landscape' : 'portrait';
1088                                 NOKIA.emulator.setMode(mode);
1089                                 $("#WidgetArea")[0].className = 'hs_'+NOKIA.mode;
1090                         });
1091
1092
1093                         $("#iframeMask").click(function(){
1094
1095                                 $("#PreferencesBtn").show();
1096                                 $("#orientationIcon").hide();
1097                                 $("#iframeMask").hide();
1098                                 $("#loaderDiv").hide();
1099
1100                                 NOKIA.menu.is_dimmed = false;
1101                                 
1102                                 $("#WidgetArea")[0].className = '';
1103                                 
1104                                 NOKIA.menu.softkeys_visibility = true;
1105                                 NOKIA.menu.showSoftKeys();
1106
1107                         });
1108
1109
1110                         //      MenuItems DIV events
1111                         $("#MenuItemsArea").mouseover(function(){
1112                                 if(NOKIA.helper.intervalId)
1113                                         clearInterval(NOKIA.helper.intervalId);
1114
1115                                 $("#MenuItemsArea").show();
1116                         });
1117
1118                         $("#MenuItemsArea").mouseout(function(){
1119                                 if(NOKIA.helper.intervalId)
1120                                         clearInterval(NOKIA.helper.intervalId);
1121
1122                                 NOKIA.helper.intervalId = setTimeout(function(){
1123                                         NOKIA.menu.cancel()
1124                                 }, 500);
1125                         });
1126
1127
1128                         // Tabs
1129                         $('#tabs').tabs({
1130                                 select : function(event, ui){
1131                                         if(parseInt(ui.index) == 1)
1132                                         {
1133                                                 $("#event-icons").show();
1134                                                 $("#event-battery-info").hide();
1135                                                 $("#event-messaging-info").hide();
1136                                                 $("#event-memory-info").hide();
1137                                                 
1138                                                 //      WRT versionn check
1139                                                 if(NOKIA.version == 'WRT 1.1')
1140                                                 {
1141                                                         $("#event-messaging")[0].className = 'active';
1142                                                         $("#event-memory")[0].className = 'active';
1143                                                 }else
1144                                                 {
1145                                                         $("#event-messaging")[0].className = 'inactive';
1146                                                         $("#event-memory")[0].className = 'inactive';
1147                                                 }
1148                                                 $("#event-battery")[0].className = 'active';
1149                                         }else if(parseInt(ui.index) == 0)
1150                                         {
1151                                                 $("#settings-view").show();
1152                                                 $("#mini-view-info").hide();
1153                                         }
1154                                 }
1155                         });
1156
1157                         
1158                         /*      
1159                          *      Event triggering
1160                          */
1161                         
1162                         //      for battery
1163                         $("#event-battery").click(function(event){
1164                                 if(event.target.className == 'active')
1165                                 {
1166                                         $("#event-icons").hide();
1167                                         $("#event-battery-info").show();
1168
1169 /*
1170                                 $('#slider').slider('option', 'value', NOKIA.emulator.child._BRIDGE_REF.helper.getBatteryStrength());
1171                                 NOKIA.emulator.child._BRIDGE_REF.helper.getBatteryStrength()
1172                                 $('#slider').slider('option', 'value', 10);
1173                                 $('#slider').slider();
1174 */
1175                                 }
1176                         });
1177
1178                         $("#event-battery-back").click(function(event){
1179                                 $("#event-icons").show();
1180                                 $("#event-battery-info").hide();
1181                         });
1182
1183
1184                         //      for messaging
1185                         $("#event-messaging").click(function(event){
1186                                 if(event.target.className == 'active')
1187                                 {
1188                                         $("#event-icons").hide();
1189                                         $("#event-messaging-info").show();
1190                                 }
1191                         });
1192
1193                         $("#event-messaging-back").click(function(event){
1194                                 $("#event-icons").show();
1195                                 $("#event-messaging-info").hide();
1196                         });
1197
1198
1199                         //      for memory
1200                         $("#event-memory").click(function(event){
1201                                 if(event.target.className == 'active')
1202                                 {
1203                                         $("#event-icons").hide();
1204                                         $("#event-memory-info").show();
1205                                 }
1206                         });
1207
1208                         $("#event-memory-back").click(function(event){
1209                                 $("#event-icons").show();
1210                                 $("#event-memory-info").hide();
1211                         });
1212
1213
1214                         //      for minView more info
1215                         $("#mini-view-back").click(function(event){
1216                                 $("#settings-view").show();
1217                                 $("#mini-view-info").hide();
1218                         });
1219
1220
1221                         // Slider
1222                         $('#slider').slider({
1223                                 range: true,
1224                                 min : 0,
1225                                 max : 100,
1226                                 step : 1,
1227                                 value : 10,
1228                                 animate: true,
1229                                 slide: function(event, ui) {
1230                                         $("#slider-value-panel > span").html(ui.value.toString());
1231                                 }
1232                                 });
1233
1234                         //      Bind Buttons to trigger values to WRT 1.0 / 1.1 bindings
1235                         
1236                         $("#connect-charger").click(NOKIA.helper.triggerEvents);
1237                         $("#disconnect-charger").click(NOKIA.helper.triggerEvents);
1238                         $("#update-batter-strength").click(NOKIA.helper.triggerEvents);
1239
1240                         $("#send-sms").click(NOKIA.helper.triggerEvents);
1241                         $("#send-mms").click(NOKIA.helper.triggerEvents);
1242
1243                         $("#connect-memory-card").click(NOKIA.helper.triggerEvents);
1244                         $("#disconnect-memory-card").click(NOKIA.helper.triggerEvents);
1245                         
1246                 },
1247                 
1248                 setHomeScreen : function()
1249                 {
1250                         //      HomeScreen Support
1251                         if (NOKIA.deviceList[NOKIA.currentDevice].homeScreenSupport) {
1252
1253                                 if (typeof NOKIA.emulator.plist.MiniViewEnabled != 'undefined') {
1254                                         if (NOKIA.emulator.plist.MiniViewEnabled != 'false') 
1255                                         {
1256                                                 $("#WidgetArea")[0].className = 'hs_' + NOKIA.mode;
1257                                                 
1258                                                 //      menu handlining
1259                                                 NOKIA.menu.softkeys_visibility = false;
1260                                                 NOKIA.menu.cancel();
1261                                                 NOKIA.menu.is_dimmed = true;
1262                                                 
1263
1264                                                 $("#loaderDiv").html("Click on widget for Return to Full view");
1265                                                 $("#loaderDiv")[0].className = 'green';
1266                                                 $("#loaderDiv").show();
1267
1268                                                 $("#iframeMask").show();
1269                                                 $("#orientationIcon").show();
1270                                                 $("#PreferencesBtn").hide();
1271
1272                                                 $("#PreferencesTab").dialog('close');
1273                                                 return true;
1274                                         }
1275                                 }
1276                         }
1277                         return false;                   
1278                 },
1279                 
1280                 getElementsLengthInObject : function(items){
1281                         var count = 0;
1282                         for (var i in items) 
1283                         {
1284                                 if(!items[i].isDimmed)
1285                                         count++;
1286                         }
1287                         
1288                         return count;
1289                 },
1290                 
1291                 triggerEvents : function(event)
1292                 {
1293                         if(typeof event.target.id == 'undefined')
1294                         return false;
1295                         
1296                         switch(event.target.id)
1297                         {
1298                                 //      for battery
1299                                 case 'connect-charger': 
1300                                                                                 NOKIA.helper.trigger("power", "chargerconnected", 1);
1301                                                                                 if(NOKIA.version == 'WRT 1.1')
1302                                                                                         NOKIA.helper.triggerSapi("Service.SysInfo", "Battery.ChargingStatus", {Status: 1});
1303                                                                                 break;
1304
1305                                 case 'disconnect-charger': 
1306                                                                                 NOKIA.helper.trigger("power", "chargerconnected", 0);
1307                                                                                 if(NOKIA.version == 'WRT 1.1')
1308                                                                                         NOKIA.helper.triggerSapi("Service.SysInfo", "Battery.ChargingStatus", {Status: 0});
1309                                                                                 break;
1310
1311                                 case 'update-batter-strength': 
1312                                                                                 var chargeValue = parseInt($('#slider').slider('value'));
1313                                                                                 NOKIA.helper.trigger("power", "chargelevel", chargeValue);
1314                                                                                 if(NOKIA.version == 'WRT 1.1')
1315                                                                                         NOKIA.helper.triggerSapi("Service.SysInfo", "Battery.BatteryStrength", {Status: chargeValue});
1316                                                                                 break;
1317
1318                                 //      for messaging
1319                                 case 'send-sms': 
1320                                                                                 if(NOKIA.version == 'WRT 1.1')
1321                                                                                         NOKIA.helper.triggerSapi("Service.Messaging", "NewMessage", {MessageType: 'SMS'});
1322                                                                                 break;
1323                                 case 'send-mms': 
1324                                                                                 if(NOKIA.version == 'WRT 1.1')
1325                                                                                         NOKIA.helper.triggerSapi("Service.Messaging", "NewMessage", {MessageType: 'MMS'});
1326                                                                                 break;
1327
1328                                 //      for memory
1329                                 case 'connect-memory-card': 
1330                                                                                 if(NOKIA.version == 'WRT 1.1')
1331                                                                                         NOKIA.helper.triggerSapi("Service.SysInfo", "Memory.MemoryCard", {Status: 1});
1332                                                                                 break;
1333                                 case 'disconnect-memory-card': 
1334                                                                                 if(NOKIA.version == 'WRT 1.1')
1335                                                                                         NOKIA.helper.triggerSapi("Service.SysInfo", "Memory.MemoryCard", {Status: 0});
1336                                                                                 break;
1337                         }
1338                 },      
1339
1340                 triggerSapi : function(provider, eventType, data){
1341                         NOKIA.emulator.child.device.implementation.triggerListener(provider, eventType, data);
1342                 },      
1343
1344                 trigger : function(provider, eventType, data){
1345                         NOKIA.emulator.child.widget.triggerListener(provider, eventType, data);
1346                 },
1347                 
1348                 showMiniviewHelp : function(){
1349                         $("#settings-view").hide();
1350                         $("#mini-view-info").show();
1351                 },
1352                 
1353                 checkDependencies : function(){
1354                         
1355                         for(var key in NOKIA.scriptsLoaded)
1356                         {
1357                                 if(!NOKIA.scriptsLoaded[key])
1358                                         return false;
1359                         }
1360
1361                         //      for LSK
1362                         NOKIA.menu.setLsk(NOKIA.emulator.child.menu.show);
1363                 
1364                         //      for RSK
1365                         NOKIA.menu.setRsk(NOKIA.menu.exit);
1366
1367                         return true;
1368                 }
1369         };
1370         
1371
1372         /*
1373          * NOKIA.layout functions
1374          */
1375         NOKIA.namespace('layout');
1376         NOKIA.layout = {
1377                 _console_minimized : true,
1378                 _console_enabled : false,
1379                 _consoleWindowHeight : 200,
1380                 _consoleHeaderHeight : 31,
1381
1382                 init : function(){
1383                         
1384                         //      Toggle console window
1385                         $('#Console-Toggle-Button').click(function(){
1386                                 
1387                                 NOKIA.layout._console_minimized = (NOKIA.layout._console_minimized) ? false : true;
1388                                 NOKIA.layout.render();
1389                         });
1390                         
1391                         // clear Log
1392                         $("#Console-Clear-Button").click(function(){
1393                                 $("#preview-ui-bottom-body")[0].innerHTML = '';
1394                         });
1395
1396
1397                         $('#preview-ui-bottom').show();
1398                         NOKIA.layout.render();
1399                 },
1400                 
1401                 log : function(type, msg){
1402                         var p = document.createElement('p');
1403                         p.className = type;
1404                         p.innerHTML = msg;
1405                         var divBody = $('#preview-ui-bottom-body')
1406                         divBody.append(p);
1407                         divBody[0].scrollTop = divBody[0].scrollHeight;
1408                 },
1409                 
1410                 
1411                 render : function(){
1412                         var _width = parseInt(window.innerWidth);
1413                         var _height = parseInt(window.innerHeight);
1414                         
1415                         if(!NOKIA.layout._console_enabled)
1416                         {
1417                                 $('#preview-ui-bottom').css({
1418                                         display: 'none'
1419                                 });
1420                                 
1421                                 $('#preview-ui-top').css({
1422                                         height: _height+'px'
1423                                 });
1424
1425                                 return false;
1426                         }
1427                         
1428                         
1429                         if(!NOKIA.layout._console_minimized)
1430                         {
1431                                 $('#Console-Toggle-Button')[0].className = 'open';
1432                                 
1433                                 //      set STYLE details for TOP window
1434                                 $('#preview-ui-top').css({
1435                                         height: parseInt(_height - NOKIA.layout._consoleWindowHeight) + 'px'
1436                                 });
1437                                 
1438                                 //      set STYLE details for Bottom window
1439                                 $('#preview-ui-bottom').css({
1440                                         height: NOKIA.layout._consoleWindowHeight + 'px',
1441                                         display : 'block'
1442                                 });
1443
1444                                 $('#preview-ui-bottom-header').css({
1445                                         height: NOKIA.layout._consoleHeaderHeight + 'px'
1446                                 });
1447
1448                                 $('#preview-ui-bottom-body').css({
1449                                         height: parseInt(NOKIA.layout._consoleWindowHeight - NOKIA.layout._consoleHeaderHeight) + 'px',
1450                                         display : 'block'
1451                                 });
1452                                 
1453                                 // Auto scroll when console window opened from MINIMIZED => MAXIMIZED state
1454                                 window.setTimeout(function(){
1455                                         $('#preview-ui-bottom-body')[0].scrollTop = $('#preview-ui-bottom-body')[0].scrollHeight;
1456                                 }, 100);
1457                                 
1458                         }else{
1459                                 $('#Console-Toggle-Button')[0].className = 'close';
1460
1461                                 //      set STYLE details for TOP window
1462                                 $('#preview-ui-top').css({
1463                                         height: parseInt(_height - NOKIA.layout._consoleHeaderHeight) + 'px'
1464                                 });
1465                                 
1466                                 //      set STYLE details for Bottom window
1467                                 $('#preview-ui-bottom').css({
1468                                         height: NOKIA.layout._consoleHeaderHeight + 'px',
1469                                         display : 'block'
1470                                 });
1471
1472                                 $('#preview-ui-bottom-header').css({
1473                                         height: NOKIA.layout._consoleHeaderHeight + 'px',
1474                                         display : 'block'
1475                                 });
1476
1477                                 $('#preview-ui-bottom-body').css({
1478                                         display : 'none'
1479                                 });
1480                         }
1481                 }
1482                 
1483         };
1484 }
1485
1486 $(document).ready(function () {
1487         NOKIA.init();   
1488 });
1489
1490 window.onresize = NOKIA.layout.render;