function SceneVolumeSpeaker(options) {
	this.options = options;
	
	this.VolumeSpeakerView=null;
	this.VolumeSpeakerDim=null;
	
	this.TitleBar = null;
	
	this.SpeakerIcon= null;
	this.ProgressBarBg = null;
	this.ProgressBar = null;
	this.VolumeValue = null;
	
	this.current_volume_value = 0;
	
	this.VolumeSpeakerHelpBar = null;
	
	this.VolumeSpeakerTimer = false;
}

SceneVolumeSpeaker.prototype.initialize = function () {
	alert("SceneVolumeSpeaker.initialize()");
	// this function will be called only once when the scene manager show this scene first time
	// initialize the scene controls and styles, and initialize your variables here 
	// scene HTML and CSS will be loaded before this function is called
    
   
   this.create();
}

SceneVolumeSpeaker.prototype.handleShow = function () {
	alert("SceneVolumeSpeaker.handleShow()");
	// this function will be called when the scene manager show this scene 
	this.VolumeSpeakerDim.show();
	
    this.updateVolume();
	
	this.startTimer();
}

SceneVolumeSpeaker.prototype.handleHide = function () {
	alert("SceneVolumeSpeaker.handleHide()");
	// this function will be called when the scene manager hide this scene  
    this.VolumeSpeakerDim.hide();
	if (this.VolumeSpeakerTimer ==true)
    {
        this.stopTimer();
    }
}

SceneVolumeSpeaker.prototype.handleFocus = function () {
	alert("SceneVolumeSpeaker.handleFocus()");
	// this function will be called when the scene manager focus this scene

}

SceneVolumeSpeaker.prototype.handleBlur = function () {
	alert("SceneVolumeSpeaker.handleBlur()");
	// this function will be called when the scene manager move focus to another scene from this scene
}

SceneVolumeSpeaker.prototype.handleKeyDown = function (keyCode) {
	alert("SceneVolumeSpeaker.handleKeyDown(" + keyCode + ")");
	PluginAPIMgr.PlayAudio(keyCode);
	// TODO : write an key event handler when this scene get focued
	if(ProcMgr.checkWidgetHighlight()==false){
		return;
	}
	switch (keyCode) {
        case sf.key.LEFT:
			this.resetTimer();
           this.processVolumeDownKey();
           	break;
                   
		case sf.key.RIGHT:
			this.resetTimer();
             this.processVolumeUpKey();		
			break;
            
		case sf.key.VOL_DOWN:
        case sf.key.PANEL_VOL_DOWN:
		case sf.key.VOL_UP:
        case sf.key.PANEL_VOL_UP:
		case sf.key.UP:
		case sf.key.DOWN:
			break;

		case sf.key.ENTER:
            this.processReturnKey();        
			break;
			
        case sf.key.RETURN:
        case sf.key.EXIT:
            this.processReturnKey();
            sf.key.block(event);
			break;

        case 147:  //infolink
        case 261:  //contents
        case 115:  //wiselink
            ProcMgr.processInfolinkKey(); 
			break;
    }
}

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

SceneVolumeSpeaker.prototype.create = function(){
    alert("SceneVolumeSpeaker.create()");
    this.VolumeSpeakerView = new View("VolumeSpeaker");
    this.VolumeSpeakerView.SetBgImage(g_Image.IMAGE_VOLUME_BG);
	
	this.VolumeSpeakerDim = new DimBg("VolumeSpeakerDim", "VolumeSpeaker"); 
    
    this.TitleBar = new Label(null,"volume_speaker_title");
    this.TitleBar.SetTextStyle("volume_speaker_title_style");
    this.TitleBar.SetText(TV_SID_SPEAKER_VOL);
    
    this.SpeakerIcon= new Label("volume_speaker_icon", null);
    this.SpeakerIcon.SetBgImage(g_Image.IMAGE_VOLUME_SPEAKER_ICON);
    
    this.ProgressBarBg= new Label("volume_speaker_progress_bar_bg", null);
    this.ProgressBarBg.SetBgImage(g_Image.IMAGE_VOLUME_PROGRESS_BAR_BG);
    
    this.ProgressBar= new Label("volume_speaker_progress_bar", null);
    this.ProgressBar.SetBgImage(g_Image.IMAGE_VOLUME_PROGRESS_BAR);

    this.VolumeValue = new Label(null,"volume_speaker_value");
    this.VolumeValue.SetTextStyle("volume_speaker_value_style");

    this.VolumeSpeakerHelpBar = new HelpBar(HelpBarIndex.VOLUME_SPEAKER, "VolumeSpeaker");
    this.VolumeSpeakerHelpBar.SetOnClickCallbackFunc(1, function(){this_.processReturnKey();});
    
    this.VolumeSpeakerView.registHelpBar( this.VolumeSpeakerHelpBar);
    
}

SceneVolumeSpeaker.prototype.updateVolume= function(){
	var value = PluginAPIMgr.GetSpeakerVolume();
	
	var max_width = 254;
	
	var progress_bar_width_i = (max_width /100) * value;
	var progress_bar_width = String(progress_bar_width_i);
	
	$("#volume_speaker_progress_bar").width(progress_bar_width+"px");
	this.VolumeValue.SetText(String(value));
	
	alert("SceneVolumeSpeaker.updateVolume() --> value: " + value+ " width : " + progress_bar_width);
}


SceneVolumeSpeaker.prototype.processVolumeDownKey = function(){
    alert("SceneVolumeSpeaker.processVolumeDownKey() ");
   this.current_volume_value = PluginAPIMgr.GetSpeakerVolume();
   
    var min_volume =0;
    this.current_volume_value --;
    
    if(this.current_volume_value < min_volume)
    {
        this.current_volume_value = min_volume;
    }
    
    PluginAPIMgr.SetSpeakerVolume(this.current_volume_value );
    this.updateVolume();    
}

SceneVolumeSpeaker.prototype.processVolumeUpKey = function(){
    alert("SceneVolumeSpeaker.processVolumeUpKey() ");
    this.current_volume_value = PluginAPIMgr.GetSpeakerVolume();
   
    var max_volume =100;
    this.current_volume_value ++;
    
    if(this.current_volume_value >  max_volume)
    {
        this.current_volume_value = max_volume;
    }
    
    PluginAPIMgr.SetSpeakerVolume(this.current_volume_value );
    this.updateVolume();    
}

SceneVolumeSpeaker.prototype.processReturnKey = function(){
    alert("SceneVolumeSpeaker.processReturnKey() ");
    StateMgr.Stop_Volume_Speaker_State(true);
}

SceneVolumeSpeaker.prototype.startTimer = function()
{
    alert("SceneVolumeSpeaker.startTimer() ");

	this.VolumeSpeakerTimer = true;
	PluginAPIMgr.StartOSDTimer("2000" , function() { sf.scene.get('VolumeSpeaker').popupTimerCallback();}, ENUM_TIMER_TYPE.POPUP_WND);
}

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

	if(this.VolumeSpeakerTimer == true)
	{
		PluginAPIMgr.RestartOSDTimer("1000" ,ENUM_TIMER_TYPE.POPUP_WND);

	}
}

SceneVolumeSpeaker.prototype.stopTimer = function()
{
    alert("SceneVolumeSpeaker.stopTimer() ");

	this.VolumeSpeakerTimer = false;
	PluginAPIMgr.StopOSDTimer(ENUM_TIMER_TYPE.POPUP_WND);
}

SceneVolumeSpeaker.prototype.popupTimerCallback = function()
{
	if(this.VolumeSpeakerTimer==false)
	{
		return;	
	}
	
   alert("SceneVolumeSpeaker.popupTimerCallback() ");
   StateMgr.Stop_Volume_Speaker_State(true);
}




