/*
	DESCRIPTION

	REQUIRES

	TO DO
*/

/*ScruncherSettings Mappings="=c" LineCompacting="TRUE"*/

(function () {
	/*** Variables for Scruncher Optimization ***/
		var
			_true = true,
			_false = false,
			_Uize_Node = Uize.Node,
			_Uize_Widget = Uize.Widget
		;

	/*** Object Constructor ***/
		var
			_superclass = _Uize_Widget,
			_class = _superclass.MustSeeJanTv = _superclass.subclass (
				null,
				function () {
					var 
						_this = this,
						_widgets = _this.widgets
					;

					/*** Private Instance Properties ***/
						_this._commObject = new Uize.Comm.Ajax();
						
						_this._channels = {
							1:{ name:'GAME', src:'pong.html', img:'s.gif', scroll:false, backgroundColor:'#000000'},
							2:{ name:'Ch Guide', src:'tvguide.php', img:'s.gif', scroll:true, backgroundColor:'#000000'},
							3:{ name:'About Jan', src:'bio.html', img:'s.gif', scroll:true},
							4:{ name:'Jan\'s Resume', src:'resume_content.html', img:'s.gif', scroll:true},
							5:{ name:'NO SIGNAL', src:'', img:'static.gif'},
							6:{ name:'NO SIGNAL', src:'', img:'static.gif'},
							7:{ name:'NO SIGNAL', src:'', img:'static.gif'},
							8:{ name:'eBay', src:'ebay.html', img:'s.gif', scroll:true},
							9:{ name:'Cisco', src:'cisco.html', img:'s.gif', scroll:true},
							10:{ name:'midi.org', src:'midi.html', img:'s.gif', scroll:true},
							11:{ name:'Kyler', src:'kyler.html', img:'s.gif', scroll:true},
							12:{ name:'NO SIGNAL', src:'', img:'static.gif'},
							13:{ name:'NO SIGNAL', src:'', img:'ColorBars2.gif'}
						}
					
						_this.channelFade = new Uize.Fade ({
							deceleration:1,
							duration:500
						});
						
						_this._screen = _widgets.add('screen',new Uize.Widget.AutoScroll());
						_this._vhfDial = _widgets.add('vhf',new Uize.Widget.Dial({
							value:1,
							minValue:1,
							steps:13
						}));
						
					/*** connect the dial to the PIP channel notifier thingy ***/
						_this._vhfDial.addEventHandlers({
							'Dialing':function () {
								_this.displayNode('pip',_true);
							},
							'Dialed':function () {
								_this.displayNode('pip',_false);
							},
							'Abort':function () {
								_this.displayNode('pip',_false);
							},
							'Changed.tempValue':function () {
								var _theValue = _this._vhfDial.get('tempValue');
								_this.setNodeInnerHtml('pipChannel',_theValue);
								_this.setNodeInnerHtml('pipChannelName',_this._channels[_theValue].name);
							},
							'Changed.value':function () {
								var 
									_channel = _this._channels[_this._vhfDial.get('value')],
									_url = _channel.src
								;
								_this._screen.set({enabled:_channel.scroll != null ? _channel.scroll : true });
								_this.getNode('screenBackground').style.backgroundColor=_channel.backgroundColor||'#000099';
								_this.getNode('screenBackgroundImage').src = _channel.img;
								if( _url != '' ) {
									_this._commObject.request({
										url:_url,
										returnType:'text',
										requestMethod:'GET',
										callback: function( _resultMarkup ) {
											_this._screen.setContents(_resultMarkup);
											_this._screen.set({enabled:_channel.scroll, scrolling:_channel.scroll});
										}
									});
								} else {
									_this._screen.setContents('');
								}
							}
						});

				}
			),
			_classPrototype = _class.prototype
		;

	/*** Private Instance Methods ***/

	/*** Public Instance Methods ***/

		_classPrototype.wireUi = function () {
			var _this = this;
			if (!_this.wired ()) {
				
				/*** default page is the channel guide ***/
					_this._vhfDial.set({value:2});
				
				/*** randomize the background color ***/
					var
						_colors = [0x01,0x33,0x01],
						_direction = 1,
						_colorChanging = 0
					;
					function _randomizeBackgroundColor () {
						if(_colors[_colorChanging] == 1 || _colors[_colorChanging] == 0x33) {
							_colorChanging = Math.floor(Math.random()*3);
							_direction = _colors[_colorChanging] == 1 ? 1 : -1;
						}
						_colors[_colorChanging] += _direction;
						
						var _newColor = (_colors[0]<<16) + (_colors[1]<<8) + _colors[2];
						var _newColorString = '#'+(_newColor < 0x100000 ? (_newColor < 0x010000 ? '00' : '0') : '') + _newColor.toString(16);
						document.body.style.backgroundColor = _newColorString;
						setTimeout(_randomizeBackgroundColor,200);
					}
					setTimeout(_randomizeBackgroundColor,200);
				
				_superclass.prototype.wireUi.call (_this);
			}
		};

}) ();


