// 2 is Call
// 1 is Tv


function SceneminiVolume(options) {
	this.options = options;
    
    this.VolumeView = null;

	this.current_highlight = null;

	this.CloseTimer = false;

	this.caution_label = null;

	this.tv_volume_slider			= null;
	this.tv_volume_name_lable		= null;
	this.tv_volume_value_lable		= null;
    this.tv_volume_value			= -1;
    
    
	this.call_volume_slider			= null;
	this.call_volume_name_lable		= null;
	this.call_volume_value_lable	= null;
    this.call_volume_value			= -1;
 
}

SceneminiVolume.prototype.initialize = function () {
	alert("SceneminiVolume.initialize()"); 
	this.create();
}

SceneminiVolume.prototype.handleShow = function () {
	alert("SceneminiVolume.handleShow()");
		
	$("#miniVolume_id").show();
	$("#skype_default_dim").show();

    this.update();

	this.startTimer();
}

SceneminiVolume.prototype.handleHide = function () {
	alert("SceneminiVolume.handleHide()");

	$("#miniVolume_id").hide();
	$("#skype_default_dim").hide();
	
	this.stopTimer();
}

SceneminiVolume.prototype.handleFocus = function () {
	alert("SceneminiVolume.handleFocus() ");

	this.highlight(1);
}

SceneminiVolume.prototype.handleBlur = function () {
	alert("SceneminiVolume.handleBlur()");
	
	this.highlight(0);
		
}

SceneminiVolume.prototype.handleKeyDown = function (keyCode) {
	alert("SceneminiVolume.handleKeyDown(" + keyCode + ")");
	
	switch (keyCode) {
		case $.sfKey.VOL_DOWN:
        case $.sfKey.PANEL_VOL_DOWN:
		case $.sfKey.LEFT:
			this.resetTimer();
			this.processVolume(false);
			break;
			
		case $.sfKey.VOL_UP:
        case $.sfKey.PANEL_VOL_UP:
		case $.sfKey.RIGHT:
			this.resetTimer();
			this.processVolume(true);
			break;
			
		case $.sfKey.UP:
		case $.sfKey.DOWN:
			this.resetTimer();
			this.processUpDownKey();
			break;

		case $.sfKey.ENTER:
			this.resetTimer();
			break;
			
        case $.sfKey.RETURN:
        case $.sfKey.EXIT:
            this.processReturnKey();
            this.stopTimer();
			$.sfKey.block(event);            
			break;
            
         case 147:  //infolink
         case 261:  //contents
         case 115:  //wiselink
            ProcMgr.processInfolinkKey(); 
			break;
    }
    if(Flag_Hidden_State==false)
		event.stopPropagation();
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////

SceneminiVolume.prototype.create = function(){
    alert("SceneminiVolume.create()");
    
    this.VolumeView = new View("Volume");
        
    this.VolumeView.CreatePopupBG(0,'volume_popup_style');
	this.VolumeView.SetTitleTextofPopupBG(SID_VOLUME);
	
	var dataInfo = {
		'leftright' : TV_SID_VOLUME_DOWN_UP,
		'return' : SID_RETURN
	};
	this.VolumeView.SetHelpbarContentsOfPopupBG(dataInfo);

	this.current_highlight = 0;

	this.caution_label = new Label(null,"volume_caution_label");
	this.caution_label.SetText(TV_SID_LOWERING_YOUR_TV_VOLUME_MAY_IMPROVE_MSG);

	//////////////////////  call  /////////////////////////////////

	this.tv_volume_name_lable	= new Label(null,"volume_tv_name");
	this.tv_volume_name_lable.SetText(TV_SID_TV_VOLUME);
	
	this.tv_volume_value_lable	= new Label(null,"volume_tv_value");

	this.CreateCallVolume();

	//////////////////////  tv  /////////////////////////////////
			
	this.call_volume_name_lable	= new Label(null,"volume_call_name");
	this.call_volume_name_lable.SetText(TV_SID_CALL_VOLUME);
	
	this.call_volume_value_lable= new Label(null,"volume_call_value");
	
	this.CreateTvVolume();


	////////////////////set  click event //////////////////////////////////
	var this_ = $.sfScene.get({id:'miniVolume',scope:WIDGET.id});
	document.getElementById('volume_tv_click').onclick = function(){this_.processTVClick();};
	document.getElementById('volume_call_click').onclick = function(){this_.processCallClick();};
		
}

SceneminiVolume.prototype.highlight = function(type){
	alert("SceneminiVolume.highlight()");

	if(this.current_highlight == type)
	{
		return;
	}

	if(this.current_highlight == 1)
	{
		this.BlurTvVolume();
	}	
	else if(this.current_highlight == 2)
	{
		this.BlurCallVolume();
	}

	if(type == 1)
	{
		this.FocusTvVolume();
	}
	else if(type == 2)
	{
		this.FocusCallVolume();
	}
	
	this.current_highlight = type;
}

SceneminiVolume.prototype.update= function(){
	alert("SceneminiVolume.update()");
			
    this.tv_volume_value	= PluginAPIMgr.GetTVMixVolume();
    this.call_volume_value	= PluginAPIMgr.GetCallMixVolume();

	this.tv_volume_value_lable.SetText(this.tv_volume_value);
    this.call_volume_value_lable.SetText(this.call_volume_value);
			
	this.SetCallVolume(this.call_volume_value);
	this.SetTvVolume(this.tv_volume_value);
	
	$.sfScene.get({id:WIDGET.name, scope:WIDGET.id}).PrintKPILog(TV_SID_LOWERING_YOUR_TV_VOLUME_MAY_IMPROVE_MSG);
}

SceneminiVolume.prototype.processVolume = function(Increase){
    alert("SceneminiVolume.processLeftKey() ");   
    
	if(this.current_highlight == 2)
	{
		if(Increase)
		{
			this.call_volume_value++;
			if(this.call_volume_value > 100)
				this.call_volume_value = 100;
		}	
		else
		{
			this.call_volume_value--;
			if(this.call_volume_value < 0)
				this.call_volume_value = 0;			
		}
		
	    this.call_volume_value_lable.SetText(this.call_volume_value);		
	    PluginAPIMgr.SetCallMixVolume(this.call_volume_value );	
	    		
	    this.SetCallVolume(this.call_volume_value);
	   
	}	
	else if(this.current_highlight == 1)
	{
		if(Increase)
		{
			this.tv_volume_value++;
			if(this.tv_volume_value > 100)
				this.tv_volume_value = 100;
		}	
		else
		{
			this.tv_volume_value--;
			if(this.tv_volume_value < 0)
				this.tv_volume_value = 0;			
		}
	
		this.tv_volume_value_lable.SetText(this.tv_volume_value);
	   	PluginAPIMgr.SetTVMixVolume(this.tv_volume_value);
		    
	    this.SetTvVolume(this.tv_volume_value);
	}
}


SceneminiVolume.prototype.processUpDownKey = function(){
	alert("SceneminiVolume.processUpDownKey() ");

	if(this.current_highlight == 1)
	{
		this.highlight(2);
	}	
	else if(this.current_highlight == 2)
	{
		this.highlight(1);
	}
}
	    	
SceneminiVolume.prototype.processReturnKey = function(){
	alert("SceneminiVolume.processReturnKey() ");

	StateMgr.Stop_Volume_Speaker_State(true);
}	
	
	
SceneminiVolume.prototype.CreateCallVolume = function(){
	alert("SceneminiVolume.CreateCallVolume() ");

	this.call_volume_slider = new CompBase(); 
	this.call_volume_slider.CreateBG("volume_call_slider_bg");	
	this.call_volume_slider.AddImageLayer("volume_call_slider_progress_left");
	this.call_volume_slider.AddJPGImageLayer("volume_call_slider_progress_center");			
	this.call_volume_slider.AddImageLayer("volume_call_slider_handle");

	this.call_volume_slider.SetImageLayer(0,g_Image.IMAGE_SLIDER_BG);
	this.call_volume_slider.SetImageLayer(1,g_Image.IMAGE_PROGRESS_NORMAL_LEFT);
	this.call_volume_slider.SetImageLayer(2,g_Image.IMAGE_PROGRESS_NORMAL_CENTER);
	this.call_volume_slider.SetImageLayer(3,g_Image.IMAGE_HANDLE_NORMAL);

}

SceneminiVolume.prototype.SetCallVolume = function(value){
	alert("SceneminiVolume.SetCallVolume()");

	var val_left = 0;
	var val_width = 1;
	
	if(value > 0)
	{
		val_left = parseInt(value*235/100);
		val_width = val_left + 20;
	}
	 
	var widthPosition = val_width+'px';
	var leftPosition = val_left+'px';
	
	$('#volume_call_slider_progress_center').css('width',widthPosition);
	$('#volume_call_slider_handle').css('left',leftPosition);
}
	
SceneminiVolume.prototype.FocusCallVolume = function(){
	alert("SceneminiVolume.FocusCallVolume() ");
	
	this.call_volume_slider.SetImageLayer(1,g_Image.IMAGE_PROGRESS_NORMALFOCUS_LEFT);
	this.call_volume_slider.SetImageLayer(2,g_Image.IMAGE_PROGRESS_NORMALFOCUS_CENTER);
	this.call_volume_slider.SetImageLayer(3,g_Image.IMAGE_HANDLE_NORMALFOCUS);
}

SceneminiVolume.prototype.BlurCallVolume = function(){
	alert("SceneminiVolume.BlurCallVolume() ");

	this.call_volume_slider.SetImageLayer(1,g_Image.IMAGE_PROGRESS_NORMAL_LEFT);
	this.call_volume_slider.SetImageLayer(2,g_Image.IMAGE_PROGRESS_NORMAL_CENTER);
	this.call_volume_slider.SetImageLayer(3,g_Image.IMAGE_HANDLE_NORMAL);
}

SceneminiVolume.prototype.CreateTvVolume = function(){
	alert("SceneminiVolume.CreateTvVolume() ");

	this.tv_volume_slider = new CompBase(); 
	this.tv_volume_slider.CreateBG("volume_tv_slider_bg");
	this.tv_volume_slider.AddImageLayer("volume_tv_slider_progress_left");
	this.tv_volume_slider.AddJPGImageLayer("volume_tv_slider_progress_center");		
	this.tv_volume_slider.AddImageLayer("volume_tv_slider_handle");

	this.tv_volume_slider.SetImageLayer(0,g_Image.IMAGE_SLIDER_BG);
	this.tv_volume_slider.SetImageLayer(1,g_Image.IMAGE_PROGRESS_NORMAL_LEFT);
	this.tv_volume_slider.SetImageLayer(2,g_Image.IMAGE_PROGRESS_NORMAL_CENTER);
	this.tv_volume_slider.SetImageLayer(3,g_Image.IMAGE_HANDLE_NORMAL);

}

SceneminiVolume.prototype.SetTvVolume = function(value){
	alert("SceneminiVolume.SetTvVolume()");

	var val_left = 0;
	var val_width = 1;
	
	if(value > 0)
	{
		val_left = parseInt(value*235/100);
		val_width = val_left + 20;
	}

	var widthPosition = val_width+'px';
	var leftPosition = val_left+'px';
		
	$('#volume_tv_slider_progress_center').css('width',widthPosition);
	$('#volume_tv_slider_handle').css('left',leftPosition);

}

SceneminiVolume.prototype.FocusTvVolume = function(){
	alert("SceneminiVolume.FocusTvVolume()");

	this.tv_volume_slider.SetImageLayer(1,g_Image.IMAGE_PROGRESS_NORMALFOCUS_LEFT);
	this.tv_volume_slider.SetImageLayer(2,g_Image.IMAGE_PROGRESS_NORMALFOCUS_CENTER);
	this.tv_volume_slider.SetImageLayer(3,g_Image.IMAGE_HANDLE_NORMALFOCUS);
}

SceneminiVolume.prototype.BlurTvVolume = function(){
	alert("SceneminiVolume.BlurTvVolume()");

	this.tv_volume_slider.SetImageLayer(1,g_Image.IMAGE_PROGRESS_NORMAL_LEFT);
	this.tv_volume_slider.SetImageLayer(2,g_Image.IMAGE_PROGRESS_NORMAL_CENTER);
	this.tv_volume_slider.SetImageLayer(3,g_Image.IMAGE_HANDLE_NORMAL);
}

SceneminiVolume.prototype.startTimer = function()
{
    alert("SceneminiVolume.startTimer() ");
	
	if(this.CloseTimer == false)
	{
		PluginAPIMgr.StartOSDTimer("10000", function() { $.sfScene.get({id:'miniVolume',scope:WIDGET.id}).popupTimerCallback();}, ENUM_TIMER_TYPE.POPUP_WND);
		this.CloseTimer = true;
	}
}

SceneminiVolume.prototype.resetTimer = function()
{
    alert("SceneminiVolume.resetTimer() ");

	if(this.CloseTimer == true)
	{
		PluginAPIMgr.RestartOSDTimer("10000" ,ENUM_TIMER_TYPE.POPUP_WND);
	}
}

SceneminiVolume.prototype.stopTimer = function()
{
    alert("SceneminiVolume.stopTimer() ");
	
	if(this.CloseTimer == true)
	{
		PluginAPIMgr.StopOSDTimer(ENUM_TIMER_TYPE.POPUP_WND);
		this.CloseTimer = false;
	}
}

SceneminiVolume.prototype.popupTimerCallback = function()
{
	alert("SceneminiVolume.popupTimerCallback() ");
   
	if(this.CloseTimer == false)
	{
		return
	}
	this.CloseTimer = false;

	StateMgr.Stop_Volume_Speaker_State(true);

}


SceneminiVolume.prototype.processTVClick = function()
{
	this.resetTimer();

	var pos_x = event.clientX - 381;
	var volume_x = parseInt(pos_x*100/276);
		
	alert("mini_volume_x: " + volume_x);
	
	this.tv_volume_value = volume_x;
    this.highlight(1);	
	this.tv_volume_value_lable.SetText(volume_x);
    this.SetTvVolume(volume_x);
    PluginAPIMgr.SetTVMixVolume(volume_x);
}

SceneminiVolume.prototype.processCallClick = function()
{
	this.resetTimer();

	var pos_x = event.clientX - 381;
	var volume_x = parseInt(pos_x*100/276);

	alert("mini_volume_x: " + volume_x);
		
	this.call_volume_value = volume_x;
	this.highlight(2);
	this.call_volume_value_lable.SetText(volume_x);
    this.SetCallVolume(volume_x);
    PluginAPIMgr.SetCallMixVolume(volume_x);
}
