/// コンテンツ閲覧画面_消しゴム書式オーバーレイ
/// ===============================================================================================
/// Eraser group [start]
/// ===============================================================================================

//名前空間用のオブジェクトを用意する
var CONTENTVIEW_GOMU = {};

// Show eraser
CONTENTVIEW_GOMU.ShowEraser = function(targetDiv) {   
    $('#dlgGomu').show();
    $('#dlgGomu').draggable();
    CONTENTVIEW_GOMU.Eraser_SetDefaultValue();
    $('#dlgGomu').center();
};

// Set default value for easer.
CONTENTVIEW_GOMU.Eraser_SetDefaultValue = function() {
    var typeValue = undefined;
    typeValue = ClientData.erase_size();
    if (typeValue == 5) {
        $("#dlgGomu_rdo1").attr('checked', 'checked');
        $("#dlgGomu_rdo1").focus();
    }
    else if (typeValue == 12.5) {
        $("#dlgGomu_rdo2").attr('checked', 'checked');
        $("#dlgGomu_rdo2").focus();
    }
    else if (typeValue == 25) {
        $("#dlgGomu_rdo3").attr('checked', 'checked');
        $("#dlgGomu_rdo3").focus();
    }
    else if (typeValue == 50) {
        $("#dlgGomu_rdo4").attr('checked', 'checked');
        $("#dlgGomu_rdo4").focus();
    }
    else {
        typeValue = 5;
        $("#dlgGomu_rdo1").attr('checked', 'checked');
        $("#dlgGomu_rdo1").focus();
    }
    CONTENTVIEW_GOMU.dlgGomu_chooseType(typeValue);
};
// Choose type of eraser, and draw to canvas
CONTENTVIEW_GOMU.dlgGomu_chooseType = function(typeValue) {

	var canvas = document.getElementById('dlgGomu_cvMain');
	var gomuLL = document.getElementById('text_dlgGomu_rdo4').getElementsByTagName('img')[0];
	var gomuL = document.getElementById('text_dlgGomu_rdo3').getElementsByTagName('img')[0];
	var gomuM = document.getElementById('text_dlgGomu_rdo2').getElementsByTagName('img')[0];
	var gomuS = document.getElementById('text_dlgGomu_rdo1').getElementsByTagName('img')[0];

	switch(typeValue){
		case 5:
			gomuS.setAttribute("style", "border: 1px solid #ff0000");
			gomuM.removeAttribute("style");
			gomuL.removeAttribute("style");
			gomuLL.removeAttribute("style");
			break;

		case 12.5:
			gomuS.removeAttribute("style");
			gomuM.setAttribute("style", "border: 1px solid #ff0000");
			gomuL.removeAttribute("style");
			gomuLL.removeAttribute("style");	
			break;

		case 25:
			gomuS.removeAttribute("style");
			gomuM.removeAttribute("style");
			gomuL.setAttribute("style", "border: 1px solid #ff0000");
			gomuLL.removeAttribute("style");
			break;

		case 50:
			gomuS.removeAttribute("style");
			gomuM.removeAttribute("style");
			gomuL.removeAttribute("style");
			gomuLL.setAttribute("style", "border: 1px solid #ff0000");
			break;
	}

    if (canvas.getContext) {
        
        // use getContext to use the canvas for drawing
        var context = canvas.getContext('2d');
 
        //Start : Apply new Css - Editor : Long - Date : 09/06/2013 - Summary : Edit for new gomu panel
        context.clearRect(0, 0, canvas.width, canvas.height);
        var imageObj = new Image();
            imageObj.onload = function() {
                var pattern = context.createPattern(imageObj, 'repeat');
        
                context.rect(0, 0, canvas.width, canvas.height);
                context.fillStyle = pattern;
                context.fill();
                
                context.beginPath();
                     
                context.arc(canvas.width/2, canvas.height/2, typeValue, 0, 2 * Math.PI, true);
                context.stroke();               
            };
         imageObj.src = 'img/viewer/canvas_l.png';
        //End : Apply new Css - Editor : Long - Date : 09/06/2013 - Summary : Edit for new gomu panel

    }
};

CONTENTVIEW_GOMU.dlgGomu_rdo1_click = function() {
	CONTENTVIEW_GOMU.dlgGomu_chooseType(5);
};
CONTENTVIEW_GOMU.dlgGomu_rdo2_click = function() {
	CONTENTVIEW_GOMU.dlgGomu_chooseType(12.5);
};
CONTENTVIEW_GOMU.dlgGomu_rdo3_click = function() {
	CONTENTVIEW_GOMU.dlgGomu_chooseType(25);
};
CONTENTVIEW_GOMU.dlgGomu_rdo4_click = function() {
	CONTENTVIEW_GOMU.dlgGomu_chooseType(50);
};

// Event of button OK
CONTENTVIEW_GOMU.dlgGomu_dspOK_click = function() {

    // Set selected value to local storage
    var typeValue = undefined;

    if ($("#dlgGomu_rdo1").attr('checked') == 'checked') {
        typeValue = 5;
    }
    else if ($("#dlgGomu_rdo2").attr('checked') == 'checked') {
        typeValue = 12.5;
    }
    else if ($("#dlgGomu_rdo3").attr('checked') == 'checked') {
        typeValue = 25;
    }
    else if ($("#dlgGomu_rdo4").attr('checked') == 'checked') {
        typeValue = 50;
    }

    // Set value to local
    ClientData.erase_size(typeValue);
    CONTENTVIEW_GENERAL.eraseSize = typeValue;

    // Close dialog
    //$("#dlgGomu").dialog('close');
	/*$("#dlgGomu").fadeOut('medium', function(){
		//COMMON.unlockLayout();
	});*/
	$("#dlgGomu").hide();
	
	/*enable button */
	CONTENTVIEW_MARKING.enableButtonMarking();
	ClientData.IsAddingMarking(true);
	CONTENTVIEW_GENERAL.isAddingMarking = ClientData.IsAddingMarking();
	
	/* unlock dialog overlay */
	$("#overlay").hide();
	
	$('#dlgMarking_imgEraserOption').removeClass();
	$('#dlgMarking_imgEraserOption').addClass('eraser_option_hover');
};
// Event of button cancel
CONTENTVIEW_GOMU.dlgGomu_dspCancel_click = function() {

    // Close dialog
	$("#dlgGomu").hide();
	
	/*enable button */
	CONTENTVIEW_MARKING.enableButtonMarking();
	ClientData.IsAddingMarking(true);
	CONTENTVIEW_GENERAL.isAddingMarking = ClientData.IsAddingMarking();
	
	/* unlock dialog overlay */
	$("#overlay").hide();
	
	$('#dlgMarking_imgEraserOption').removeClass();
	$('#dlgMarking_imgEraserOption').addClass('eraser_option_hover');
};

CONTENTVIEW_GOMU.dlgGomu_rdo1_text_click = function(){
	$('#dlgGomu_rdo1').attr('checked','checked');
	$('#dlgGomu_rdo2').removeAttr('checked');
	$('#dlgGomu_rdo3').removeAttr('checked');
	$('#dlgGomu_rdo4').removeAttr('checked');
	CONTENTVIEW_GOMU.dlgGomu_rdo1_click();
};

CONTENTVIEW_GOMU.dlgGomu_rdo2_text_click = function(){
	$('#dlgGomu_rdo1').removeAttr('checked');
	$('#dlgGomu_rdo2').attr('checked','checked');
	$('#dlgGomu_rdo3').removeAttr('checked');
	$('#dlgGomu_rdo4').removeAttr('checked');
	CONTENTVIEW_GOMU.dlgGomu_rdo2_click();
};

CONTENTVIEW_GOMU.dlgGomu_rdo3_text_click = function(){
	$('#dlgGomu_rdo1').removeAttr('checked');
	$('#dlgGomu_rdo2').removeAttr('checked');
	$('#dlgGomu_rdo3').attr('checked','checked');
	$('#dlgGomu_rdo4').removeAttr('checked');
	CONTENTVIEW_GOMU.dlgGomu_rdo3_click();
};

CONTENTVIEW_GOMU.dlgGomu_rdo4_text_click = function(){
	$('#dlgGomu_rdo1').removeAttr('checked');
	$('#dlgGomu_rdo2').removeAttr('checked');
	$('#dlgGomu_rdo3').removeAttr('checked');
	$('#dlgGomu_rdo4').attr('checked','checked');
	CONTENTVIEW_GOMU.dlgGomu_rdo4_click();
};
/*
----------------------------------------------------------------------------
Event groups [start]
----------------------------------------------------------------------------
*/


/*
----------------------------------------------------------------------------
Event groups [ end ]
----------------------------------------------------------------------------
*/


CONTENTVIEW_GOMU.touchStart_BtnOk_Gomu = function(e){
	e.preventDefault();
	$('#dlgGomu').draggable("destroy");
	
	CONTENTVIEW_GOMU.dlgGomu_dspOK_click();
	
};

CONTENTVIEW_GOMU.touchStart_BtnCancel_Gomu = function(e){
	e.preventDefault();
	$('#dlgGomu').draggable("destroy");
	
	CONTENTVIEW_GOMU.dlgGomu_dspCancel_click();
};

// Setting dialog
$(function () {
	//CONTENTVIEW_GOMU.ready();
});

CONTENTVIEW_GOMU.ready = function(){
    // ---------------------------------
    // Setup for easer [start]
    // ---------------------------------
	if(COMMON.isTouchDevice() == true){
		if ($('#dlgGomu_dspOK').length) {
			document.getElementById('dlgGomu_dspOK').addEventListener('touchstart',CONTENTVIEW_GOMU.touchStart_BtnOk_Gomu,false);
		}
		if ($('#dlgGomu_dspCancel').length) {
			document.getElementById('dlgGomu_dspCancel').addEventListener('touchstart',CONTENTVIEW_GOMU.touchStart_BtnCancel_Gomu,false);
		}
	}
		
    //$("#dlgGomu_dspOK").click(CONTENTVIEW_GOMU.dlgGomu_dspOK_click);
    $("#dlgGomu_dspOK").on({
    	'click touchend': function(ev){
    		CONTENTVIEW_GOMU.dlgGomu_dspOK_click(ev);
            return false;
    	},
    	'touchstart touchmove': function(){
    		//これを入れないと次にダイアログを開くと表示位置が大きくズレる
    		return false;
    	}
    });
    
    //$("#dlgGomu_dspCancel").click(CONTENTVIEW_GOMU.dlgGomu_dspCancel_click);
    $("#dlgGomu_dspCancel").on({
    	'click touchend': function(ev){
    		CONTENTVIEW_GOMU.dlgGomu_dspCancel_click(ev);
            return false;
    	},
    	'touchstart touchmove': function(){
    		//これを入れないと次にダイアログを開くと表示位置が大きくズレる
    		return false;
    	}
    });
    
    
    //$("#text_dlgGomu_rdo1").click(CONTENTVIEW_GOMU.dlgGomu_rdo1_text_click);
    $("#text_dlgGomu_rdo1").on({
    	'click touchend': function(ev){
    		CONTENTVIEW_GOMU.dlgGomu_rdo1_text_click(ev);
            return false;
    	},
    	'touchstart touchmove': function(){
    		//これを入れないと次にダイアログを開くと表示位置が大きくズレる
    		return false;
    	}
    });
    
    //$("#text_dlgGomu_rdo2").click(CONTENTVIEW_GOMU.dlgGomu_rdo2_text_click);
    $("#text_dlgGomu_rdo2").on({
    	'click touchend': function(ev){
    		CONTENTVIEW_GOMU.dlgGomu_rdo2_text_click(ev);
            return false;
    	},
    	'touchstart touchmove': function(){
    		//これを入れないと次にダイアログを開くと表示位置が大きくズレる
    		return false;
    	}
    });
    
    //$("#text_dlgGomu_rdo3").click(CONTENTVIEW_GOMU.dlgGomu_rdo3_text_click);
    $("#text_dlgGomu_rdo3").on({
    	'click touchend': function(ev){
    		CONTENTVIEW_GOMU.dlgGomu_rdo3_text_click(ev);
            return false;
    	},
    	'touchstart touchmove': function(){
    		//これを入れないと次にダイアログを開くと表示位置が大きくズレる
    		return false;
    	}
    });
    
    //$("#text_dlgGomu_rdo4").click(CONTENTVIEW_GOMU.dlgGomu_rdo4_text_click);
    $("#text_dlgGomu_rdo4").on({
    	'click touchend': function(ev){
    		CONTENTVIEW_GOMU.dlgGomu_rdo4_text_click(ev);
            return false;
    	},
    	'touchstart touchmove': function(){
    		//これを入れないと次にダイアログを開くと表示位置が大きくズレる
    		return false;
    	}
    });
};


/// ===============================================================================================
/// Eraser group [ end ]
/// ===============================================================================================