function SceneVolumeMic(options) {
	this.options = options;
    
    this.VolumeMicView=null;
	this.VolumeMicDim=null;
    
    this.TitleBar = null;
    
    this.MicIcon= null;
    this.ProgressBarBg = null;
    this.ProgressBar = null;
    this.VolumeValue = null;
            
    this.VolumeMicHelpBar = null;
    this.AutoVolumeMicHelpBar = null;
    
    this.AutoAdjustCheckBox= null;
	
	this.VolumeMicTimer = false;
	
    this.current_volume_value = 23;
    this.prev_volume_value = 23;	
	
	//flag
	this.flag_AutoVolume = null;
	this.flag_prev_AutoVolume = null;
	
	 this.LeftArrow = null;
	 this.RightArrow = null;			
}

SceneVolumeMic.prototype.initialize = function () {
	alert("SceneVolumeMic.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();
}

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

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

SceneVolumeMic.prototype.handleFocus = function () {
	alert("SceneVolumeMic.handleFocus() ");
	// this function will be called when the scene manager focus this scene
    
	if(this.flag_AutoVolume == true)
	{
		this.highlight(this.AutoAdjustCheckBox);
	}
	else
	{
		this.highlight(this.ProgressBarBg);
	}
}

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

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

		case sf.key.ENTER:
			this.resetTimer();
            this.processEnterKey();
			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;
    }
}

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

SceneVolumeMic.prototype.create = function(){
    alert("SceneVolumeMic.create()");
    this.VolumeMicView = new View("VolumeMic");
    this.VolumeMicView.SetBgImage(g_Image.IMAGE_VOLUME_BG);
	
	this.VolumeMicDim = new DimBg("VolumeMicDim", "VolumeMic"); 
    
    this.TitleBar = new Label(null,"volume_mic_title");
    this.TitleBar.SetTextStyle("volume_mic_title_style");
    this.TitleBar.SetText(TV_SID_MIC_VOL);
    
    this.MicIcon= new Label("volume_mic_icon", null);
    this.MicIcon.SetBgImage(g_Image.IMAGE_VOLUME_MIC_ICON);
    
    var this_ = sf.scene.get("VolumeMic");
	var clickCF =  function(obj){this_.processClickEvent(obj);};
    
	this.ProgressBarBg = new Button();
    this.ProgressBarBg.SetImageObjId("volume_mic_progress_bar_bg");
	this.ProgressBarBg.SetBgImage(BtnImgIndex.BTN_NORMAL_IMG, g_Image.IMAGE_VOLUME_PROGRESS_BAR_BG);
    this.ProgressBarBg.SetBgImage(BtnImgIndex.BTN_NORMAL_FOCUS_IMG, g_Image.IMAGE_VOLUME_PROGRESS_BAR_BG_SEL);
    this.ProgressBarBg.SetBgImage(BtnImgIndex.BTN_DIM_IMG, g_Image.IMAGE_VOLUME_PROGRESS_BAR_BG);	
    this.ProgressBarBg.SetOnClickCallbackFunc(clickCF);
    
    this.ProgressBar= new Label("volume_mic_progress_bar", null);
   	this.ProgressBar.SetOnClickCallbackFunc(clickCF);
    
    this.VolumeValue = new Label(null,"volume_mic_value");
    this.VolumeValue.SetTextStyle("volume_mic_value_style");
   
    this.AutoAdjustCheckBox=new CheckBox();
    this.AutoAdjustCheckBox.SetImageObjId("volume_mic_check_box");
    this.AutoAdjustCheckBox.SetBgImage(CBoxImgIndex.CB_NORMAL_IMG,  g_Image.IMAGE_VOLUME_MIC_CHECK_BOX_NORMAL);
    this.AutoAdjustCheckBox.SetBgImage(CBoxImgIndex.CB_NORMAL_FOCUS_IMG,  g_Image.IMAGE_VOLUME_MIC_CHECK_BOX_NORMALFOCUS);
    this.AutoAdjustCheckBox.SetTextObjId("volume_mic_check_box_text");
    this.AutoAdjustCheckBox.SetText(IDWS_MOIP_AUTOMATIC_MIC_SETTING);
    this.AutoAdjustCheckBox.SetTextStyle("volume_mic_check_box_style");
    this.AutoAdjustCheckBox.AppendFgImage("volume_mic_check_box_selected_icon","0px","0px","29px","29px");
    this.AutoAdjustCheckBox.SetFgImage(g_Image.IMAGE_VOLUME_MIC_CHECK_BOX_SELECTED);
    this.AutoAdjustCheckBox.SetOnClickCallbackFunc(clickCF);
   
    this.VolumeMicHelpBar = new HelpBar(HelpBarIndex.VOLUME_MIC, "VolumeMic");
    this.VolumeMicHelpBar.SetOnClickCallbackFunc(2, function(){this_.processReturnKey();});
    
    this.AutoVolumeMicHelpBar = new HelpBar(HelpBarIndex.VOLUME_MIC_AUTO, "VolumeMic");
    this.AutoVolumeMicHelpBar.SetOnClickCallbackFunc(1, function(){this_.processReturnKey();});
    
    this.ProgressBarBg.registHelpBar( this.VolumeMicHelpBar);
	this.AutoAdjustCheckBox.registHelpBar( this.AutoVolumeMicHelpBar);
	
	this.LeftArrow= new Label("volume_mic_left_arrow", null);
    this.LeftArrow.SetBgImage(g_Image.IMAGE_VOLUME_ALLOW_LEFT_NOR);
    this.LeftArrow.SetOnClickCallbackFunc(clickCF);
    this.LeftArrow.SetOnMouseOutOverImage(g_Image.IMAGE_VOLUME_ALLOW_LEFT_NOR, g_Image.IMAGE_VOLUME_ALLOW_LEFT_OVER);

    this.RightArrow= new Label("volume_mic_right_arrow", null);
    this.RightArrow.SetBgImage(g_Image.IMAGE_VOLUME_ALLOW_RIGHT_NOR);
    this.RightArrow.SetOnClickCallbackFunc(clickCF);
    this.RightArrow.SetOnMouseOutOverImage(g_Image.IMAGE_VOLUME_ALLOW_RIGHT_NOR, g_Image.IMAGE_VOLUME_ALLOW_RIGHT_OVER);  
    
}


SceneVolumeMic.prototype.syncData = function()
{
	
	if(PluginAPIMgr.GetAutoVolumeControl() == "1")
	{
		this.flag_AutoVolume = true;
		this.flag_prev_AutoVolume = false;
	} 
	else{
		this.flag_AutoVolume = false;
		this.flag_prev_AutoVolume = true;
	}
	
	this.current_volume_value = PluginAPIMgr.GetMicVolume();

	this.prev_volume_value = -1;
		
}

SceneVolumeMic.prototype.highlight=function(obj)
{
    this.VolumeMicView.setCurrenHighlight(obj);
	
	if(obj==this.AutoAdjustCheckBox)
	{
		if(this.AutoAdjustCheckBox.GetFlagSelect()==true)
		{
			this.AutoAdjustCheckBox.changeHelpBar( this.AutoVolumeMicHelpBar);
		}
		else
		{
			this.AutoAdjustCheckBox.changeHelpBar( this.VolumeMicHelpBar);
		}
	}
}

SceneVolumeMic.prototype.updateVolume= function(){

	alert("SceneVolumeMic.updateVolume()");	
	
	this.setCheckBox(this.flag_AutoVolume);	
	this.setProgressAndText(this.current_volume_value);
}


SceneVolumeMic.prototype.setCheckBox = function(autoVolume)
{  

	alert("SceneVolumeMic.setCheckBox(" + autoVolume + ")");	
	
    if(autoVolume == true)
    {
        this.AutoAdjustCheckBox.SetFlagSelect(true);
        this.ProgressBar.SetBgImage(g_Image.IMAGE_VOLUME_PROGRESS_BAR_DIM);
        this.ProgressBar.SetEnableOnClick(false);
        this.ProgressBarBg.SetFlagDim(true);
        
        this.LeftArrow.hiddenObj();
    	this.RightArrow.hiddenObj();
    }
    else
    {
        this.AutoAdjustCheckBox.SetFlagSelect(false);
        this.ProgressBar.SetBgImage(g_Image.IMAGE_VOLUME_PROGRESS_BAR);
        this.ProgressBar.SetEnableOnClick(true);
        this.ProgressBarBg.SetFlagDim(false);
        
        //this.toggleArrow();
    }
}

SceneVolumeMic.prototype.toggleArrow = function()
{
	if(this.flag_AutoVolume == true)
	{
		return;	
	}
	
	var min_volume = 0;
	var max_volume = 100;
	
	if(this.current_volume_value==min_volume)
	{
		this.LeftArrow.hiddenObj();
	}
	else
	{
		this.LeftArrow.visibleObj();
	}
    
    if(this.current_volume_value==max_volume)
    {
    	this.RightArrow.hiddenObj();
    }
    else
    {
    	this.RightArrow.visibleObj();
    }	
}

SceneVolumeMic.prototype.setProgressAndText = function(volume)
{            
    var max_width = 254;  
    var progress_bar_width_i  = 0;    
    progress_bar_width_i = (max_width /100) * volume;

    var progress_bar_width = String(progress_bar_width_i);
    
    $("#volume_mic_progress_bar").width(progress_bar_width+"px");
    this.VolumeValue.SetText(String(volume));
    
     alert("SceneVolumeMic.setProgressAndText() --> value: " + volume+ " width : " + progress_bar_width);
     
     this.toggleArrow();
}



SceneVolumeMic.prototype.processLeftKey = function(){
    alert("SceneVolumeMic.processLeftKey() ");
    
    if(this.AutoAdjustCheckBox.GetFlagSelect() == true)
    {
            return;
    }
    
	var currentHighlight =  this.VolumeMicView.getCurrentHighlight();
	if (currentHighlight != this.ProgressBarBg)
	{
		this.highlight(this.ProgressBarBg);
		currentHighlight =  this.VolumeMicView.getCurrentHighlight();
	}
	
	if (currentHighlight == this.ProgressBarBg) 
	{
		// this.current_volume_value = PluginAPIMgr.GetMicVolume();
		this.prev_volume_value = this.current_volume_value;
		
		var min_volume = 0;
		this.current_volume_value--;
		
		if (this.current_volume_value < min_volume)
		{
			this.current_volume_value = min_volume;
		}
		else
		{
			PluginAPIMgr.SetMicVolume(this.current_volume_value);
			this.updateVolume();			
		}
		
		//this.toggleArrow();
	} 
}

SceneVolumeMic.prototype.processRightKey = function(){
    alert("SceneVolumeMic.processRightKey() ");
    
     if(this.AutoAdjustCheckBox.GetFlagSelect() == true)
    {
            return;
    }
    
	var currentHighlight =  this.VolumeMicView.getCurrentHighlight();
	if (currentHighlight != this.ProgressBarBg)
	{
		this.highlight(this.ProgressBarBg);
		currentHighlight =  this.VolumeMicView.getCurrentHighlight();
	}
	
	if(currentHighlight == this.ProgressBarBg )
	{
		// this.current_volume_value = PluginAPIMgr.GetMicVolume();
		this.prev_volume_value = this.current_volume_value;
			   
	    var max_volume = 100;
	    this.current_volume_value++;
	    
	    if(this.current_volume_value >  max_volume)
	    {
	        this.current_volume_value = max_volume;
	    }
	    else{
		    PluginAPIMgr.SetMicVolume(this.current_volume_value);
		    this.updateVolume(); 	
	    }
	    
	    //this.toggleArrow();	    
	}
   
}

SceneVolumeMic.prototype.processUpDownKey = function(){
	alert("SceneVolumeMic.processUpDownKey() ");
	var currentHighlight =  this.VolumeMicView.getCurrentHighlight();
	
	switch(currentHighlight)
	{
		case this.ProgressBarBg:
			this.highlight(this.AutoAdjustCheckBox)
			break;
			
		case this.AutoAdjustCheckBox:
		    if(this.AutoAdjustCheckBox.GetFlagSelect() == true)
		    {
		       return;
		    }
			this.highlight(this.ProgressBarBg);
			break;
	}	
}
/*
SceneVolumeMic.prototype.processProgressBarClick = function(){
	this.resetTimer();
	
	var currentHighlight =  this.VolumeMicView.getCurrentHighlight();
	if(currentHighlight != this.ProgressBarBg)
	{
		this.highlight(this.ProgressBarBg);
	}
}

SceneVolumeMic.prototype.processAutoAdjustCheckBoxClick = function(){
	
	this.resetTimer();
	
	var currentHighlight =  this.VolumeMicView.getCurrentHighlight();
	if(currentHighlight != this.AutoAdjustCheckBox)
	{
		this.highlight(this.AutoAdjustCheckBox);
	}

	this.toggleAutoVolume();

}*/

SceneVolumeMic.prototype.processClickEvent = function(obj){
	alert("SceneVolumeMic.processClickEvent() ");
	
	this.resetTimer();
	
	if(obj == this.LeftArrow || obj == this.RightArrow)
	{
		if(obj == this.LeftArrow)
		{
			this.processLeftKey();
		}
		else
		{
			this.processRightKey();
		}
		
		return;
	}	
	
	if(obj==this.ProgressBar)
	{
		obj=this.ProgressBarBg;
	}
	
	var currentHighlight =  this.VolumeMicView.getCurrentHighlight();
    if(currentHighlight != obj)
    {
    	this.highlight(obj);
    }
	
	this.processEnterKey();
}


SceneVolumeMic.prototype.processEnterKey = function(){
    alert("SceneVolumeMic.processEnterKey() ");
    
    var currentHighlight =  this.VolumeMicView.getCurrentHighlight();
    
    if(currentHighlight == this.AutoAdjustCheckBox)
    {
       this.toggleAutoVolume();
    }	
}

SceneVolumeMic.prototype.toggleAutoVolume = function(){
	
	    this.flag_prev_AutoVolume = this.flag_AutoVolume;
    	
        if(this.flag_AutoVolume == true)
        {
             PluginAPIMgr.SetAutoVolumeControl(false);
             this.flag_AutoVolume = false;
			 this.AutoAdjustCheckBox.changeHelpBar( this.VolumeMicHelpBar);
			 
			 //sync volume
			 this.current_volume_value = PluginAPIMgr.GetMicVolume();
        }
        else
        {
            PluginAPIMgr.SetAutoVolumeControl(true);
            this.flag_AutoVolume = true;
			this.AutoAdjustCheckBox.changeHelpBar( this.AutoVolumeMicHelpBar);           
        }
        
        this.updateVolume(); 	
}

SceneVolumeMic.prototype.processReturnKey = function(){
    alert("SceneVolumeMic.processReturnKey() ");
    StateMgr.Stop_Volume_Mic_State(true);
}

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

	this.VolumeMicTimer = true;
	PluginAPIMgr.StartOSDTimer("60000" , function() { sf.scene.get('VolumeMic').popupTimerCallback();}, ENUM_TIMER_TYPE.POPUP_WND);
}

SceneVolumeMic.prototype.resetTimer = function()
{
    alert("SceneVolumeMic.resetTimer() ");
	
	if(this.VolumeMicTimer == true)
	{
		PluginAPIMgr.RestartOSDTimer("60000" ,ENUM_TIMER_TYPE.POPUP_WND);
	}
}

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

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

SceneVolumeMic.prototype.popupTimerCallback = function()
{
   alert("SceneVolumeMic.popupTimerCallback() ");
   if(this.VolumeMicTimer == false)
   {
   		return;
   }
   
   this.VolumeMicTimer = false;
   
   StateMgr.Stop_Volume_Mic_State(true);
}




