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

/* init const */
//CONTENTVIEW_GENERAL.WIDTH_DIALOG_BOOKMARK = 300;
//CONTENTVIEW_GENERAL.HEIGHT_DIALOG_BOOKMARK = 700;
//CONTENTVIEW_GENERAL.HEIGHT_DIALOG_BOOKMARK_NO_BOOKMARK = 200;

//CONTENTVIEW_GENERAL.WIDTH_DIALOG_INDEX = 300;
//CONTENTVIEW_GENERAL.HEIGHT_DIALOG_INDEX = 700;
//CONTENTVIEW_GENERAL.HEIGHT_DIALOG_INDEX_NO_INDEX = 200;

//CONTENTVIEW_GENERAL.WIDTH_DIALOG_SEARCH = 300;
//CONTENTVIEW_GENERAL.HEIGHT_DIALOG_SEARCH = 700;
//CONTENTVIEW_GENERAL.HEIGHT_DIALOG_SEARCH_NO_SEARCH = 200;

//CONTENTVIEW_GENERAL.WIDTH_DIALOG_COPYTEXT = 300;
//CONTENTVIEW_GENERAL.HEIGHT_DIALOG_COPYTEXT = 500;
//CONTENTVIEW_GENERAL.HEIGHT_DIALOG_COPYTEXT_NO_COPYTEXT = 200;

/* init variable */
CONTENTVIEW_GENERAL.pageImages = '';
CONTENTVIEW_GENERAL.totalPage = 0;
CONTENTVIEW_GENERAL.pageObjects = [];
CONTENTVIEW_GENERAL.pageObjectsData = [];
CONTENTVIEW_GENERAL.tool;
CONTENTVIEW_GENERAL.isFullScreen = false;
CONTENTVIEW_GENERAL.ctrlMode = false;
CONTENTVIEW_GENERAL.dataWebContentPage;
CONTENTVIEW_GENERAL.dataPageTitle;
CONTENTVIEW_GENERAL.dataJsonType4;
CONTENTVIEW_GENERAL.dataJsonType5;
CONTENTVIEW_GENERAL.contentID;
CONTENTVIEW_GENERAL.isOpenPopUpText = false;
CONTENTVIEW_GENERAL.isOpenPopUpMemo = true;
CONTENTVIEW_GENERAL.objEditMemo;
CONTENTVIEW_GENERAL.isCopyMemo = false;
//CONTENTVIEW_GENERAL.isExistCopyMemo = false;
CONTENTVIEW_GENERAL.posXPopupMemo = 0;
CONTENTVIEW_GENERAL.posYPopupMemo = 0;
CONTENTVIEW_GENERAL.contentName = '';
CONTENTVIEW_GENERAL.nCountObjectLoad = 0;
CONTENTVIEW_GENERAL.nAjaxLoad = 0;
CONTENTVIEW_GENERAL.isClearDrawing = false;
CONTENTVIEW_GENERAL.isDrawing = false;
CONTENTVIEW_GENERAL.mediaType4_changeImage = 0;
CONTENTVIEW_GENERAL.isLoadingObject = false;
CONTENTVIEW_GENERAL.isFirstLoad = true;
CONTENTVIEW_GENERAL.nPositionCanvas = [];
CONTENTVIEW_GENERAL.arrImage = [];
//CONTENTVIEW_GENERAL.posTxtSearch = [];
CONTENTVIEW_GENERAL.sx;
CONTENTVIEW_GENERAL.sy;
CONTENTVIEW_GENERAL.imgDrawingTemp;
CONTENTVIEW_GENERAL.imgMarkerTemp;
//CONTENTVIEW_GENERAL.isSizingDrawCanvas = false;
CONTENTVIEW_GENERAL.isDisplayBookMarkList = false;
CONTENTVIEW_GENERAL.avwUserEnvObj = new UserEnvironment();
CONTENTVIEW_GENERAL.canvas_marker;
CONTENTVIEW_GENERAL.context_marker;
CONTENTVIEW_GENERAL.canvas_draw;
CONTENTVIEW_GENERAL.context_draw;
CONTENTVIEW_GENERAL.canvas_main;
CONTENTVIEW_GENERAL.context_main;
CONTENTVIEW_GENERAL.canvas_offscreen;
CONTENTVIEW_GENERAL.context_offscreen;
CONTENTVIEW_GENERAL.isAddingMarking;
CONTENTVIEW_GENERAL.penSize;
CONTENTVIEW_GENERAL.penColor;
CONTENTVIEW_GENERAL.makerSize;
CONTENTVIEW_GENERAL.makerColor;
CONTENTVIEW_GENERAL.eraseSize;
CONTENTVIEW_GENERAL.markingType;
CONTENTVIEW_GENERAL.isDisplayCopyText = false;
CONTENTVIEW_GENERAL.isDisplayListIndex = false;
CONTENTVIEW_GENERAL.isChangeSizeScreen = false; //実質未使用
CONTENTVIEW_GENERAL.widthContentImage = 0;
CONTENTVIEW_GENERAL.heightContentImage = 0;
CONTENTVIEW_GENERAL.widthEachPage = 0;
CONTENTVIEW_GENERAL.heightEachPage = 0;
CONTENTVIEW_GENERAL.px = 0;
CONTENTVIEW_GENERAL.py = 0;
CONTENTVIEW_GENERAL.isPressLeftMouse = false;
CONTENTVIEW_GENERAL.isMoveOutDrawCanvas = false;
CONTENTVIEW_GENERAL.typeSelectMemo = 0;
CONTENTVIEW_GENERAL.arrThumbnailsLoaded = [];
CONTENTVIEW_GENERAL.isSendingData = true;
CONTENTVIEW_GENERAL.isPlayBGMUnlock = false; //未使用
CONTENTVIEW_GENERAL.isJumpNotFromFirstPage = false;
CONTENTVIEW_GENERAL.standardRatio = 1; //未使用
CONTENTVIEW_GENERAL.currentRatio = 1; //未使用
CONTENTVIEW_GENERAL.resourceImage = new Image();

//START TRB00097 - Editor: Long - Date: 09/30/2013 - Summary : Get All Page size of content
//Array of pages size
CONTENTVIEW_GENERAL.contentPageSizeArr = [];
CONTENTVIEW_GENERAL.widthEachNextPage = 0;
CONTENTVIEW_GENERAL.heightEachNextPage = 0;
CONTENTVIEW_GENERAL.widthEachPrevPage = 0;
CONTENTVIEW_GENERAL.heightEachPrevPage = 0;
//END TRB00097 - Editor: Long - Date: 09/30/2013 - Summary : Get All Page size of content

//#11478
CONTENTVIEW_GENERAL.widthEachPageApi = 0;
CONTENTVIEW_GENERAL.heightEachPageApi = 0;
CONTENTVIEW_GENERAL.widthEachNextPageApi = 0;
CONTENTVIEW_GENERAL.heightEachNextPageApi = 0;
CONTENTVIEW_GENERAL.widthEachPrevPageApi = 0;
CONTENTVIEW_GENERAL.heightEachPrevPageApi = 0;
//#11478

/* zoom video */
CONTENTVIEW_GENERAL.pxVideo;
CONTENTVIEW_GENERAL.pyVideo;
CONTENTVIEW_GENERAL.wVideo;
CONTENTVIEW_GENERAL.hVideo;
CONTENTVIEW_GENERAL.videoScale; //未使用

//Start Function: No.12
//Content's types

CONTENTVIEW_GENERAL.contentType;

CONTENTVIEW_GENERAL.imageTypeData;

CONTENTVIEW_GENERAL.nextPageImage = '';
CONTENTVIEW_GENERAL.nextPageObjects = [];
CONTENTVIEW_GENERAL.nextContent = new CONTENTVIEW_CREATEOBJECT.Content();
CONTENTVIEW_GENERAL.prevPageObjects = [];
CONTENTVIEW_GENERAL.prevPageImage = '';
CONTENTVIEW_GENERAL.prevContent = new CONTENTVIEW_CREATEOBJECT.Content();
CONTENTVIEW_GENERAL.animateTypeKeys = {
    Type_Slide : 0,
    Type_FadeIn : 1
};

CONTENTVIEW_GENERAL.animateType;
CONTENTVIEW_GENERAL.animatePeriod;

CONTENTVIEW_GENERAL.getNextContent = function(){
    return CONTENTVIEW_GENERAL.nextContent;    
};

CONTENTVIEW_GENERAL.getPrevContent = function(){
    return CONTENTVIEW_GENERAL.prevContent;  
};


//End Function: No.12


//Start Function : No.20
//CONTENTVIEW_GENERAL._moveFlag = false;
CONTENTVIEW_GENERAL._moveNum = false;
CONTENTVIEW_GENERAL._isPageNaviTouch = false;
CONTENTVIEW_GENERAL._isPageZoomTouch = false;
CONTENTVIEW_GENERAL._clickFirstPos = null;
CONTENTVIEW_GENERAL._clickLastPos = null;
CONTENTVIEW_GENERAL._touchFirstPos = null;
CONTENTVIEW_GENERAL._touchLastPos = null;
CONTENTVIEW_GENERAL.touchStartedTime = null;
CONTENTVIEW_GENERAL._touchMoveTimePeriod = 0; // 0 s
CONTENTVIEW_GENERAL._touchMoveTimePeriodInvalid = 5000; // 5 s
//CONTENTVIEW_GENERAL._bHasNext = false; 
//CONTENTVIEW_GENERAL._bHasPrev = false; 
CONTENTVIEW_GENERAL._startPoints = [];
CONTENTVIEW_GENERAL._bufferPoints = [];
//CONTENTVIEW_GENERAL._bImageMainReload = true;   // to not run onload again on the next time on set src value 
//CONTENTVIEW_GENERAL._bImageMainPreReload = true;    // to not run onload again on the next time on set src value
//CONTENTVIEW_GENERAL._bImageMainNextReload = true;   // to not run onload again on the next time on set src value
CONTENTVIEW_GENERAL._lastDist = 0;
CONTENTVIEW_GENERAL._lastScaleDelta = 0;

CONTENTVIEW_GENERAL._bWin8TouchEnabled = false;
CONTENTVIEW_GENERAL._bTransitionEnable = true;
CONTENTVIEW_GENERAL._bTouchDeviceEnabled = false;

//End Function : No.20


//Start Function : No.9 
CONTENTVIEW_GENERAL._object3DImageArr = [];

//End Function : No.9
/*disable all control on page */
CONTENTVIEW_GENERAL.disableAllControl = function() {
    /* set cursor pointer*/
    $("#imgHome").css('cursor', 'default');
    $("#imgBack").css('cursor', 'default');
    $("#listbookmark").css('cursor', 'default');
    $("#imgbookmark").css('cursor', 'default');
    $("#listindex").css('cursor', 'default');
    $("#copytext").css('cursor', 'default');
    $("#imgmemo").css('cursor', 'default');
    $("#imgaddmemo").css('cursor', 'default');
    $("#imgmarking").css('cursor', 'default');
    $("#imgmarkingtoolbar").css('cursor', 'default');
    $("#firstpage").css('cursor', 'default');
    $("#prevpage").css('cursor', 'default');
    $("#nextpage").css('cursor', 'default');
    $("#lastpage").css('cursor', 'default');
    $("#zoomfit").css('cursor', 'default');
    $("#zoomin").css('cursor', 'default');
    $("#zoomout").css('cursor', 'default');
    $("#control_screen").css('cursor', 'default');
    $("#control_screen_2").css('cursor', 'default');
    $("#slider_page").css('cursor', 'default');
    $(".ui-slider-handle").css('cursor', 'default');

    $('#imgHome').unbind('click');
    $('#imgHome').removeClass();
    $('#imgHome').addClass('home_off');

    /* back button */
    $('#imgBack').unbind('click');
    $('#imgBack').removeClass();
    $('#imgBack').addClass('back_off');

    /*list bookmark */
    $('#listbookmark').unbind('click');
    $('#listbookmark').removeClass();
    $('#listbookmark').addClass('bmList_off');

    $('#imgbookmark').unbind('click');
    $('#imgbookmark').removeClass();
    $('#imgbookmark').addClass('bmAdd_off');

    $('#listindex').unbind('click');
    $('#listindex').removeClass();
    $('#listindex').addClass('index_off');

    $('#copytext').unbind('click');
    $('#copytext').removeClass();
    $('#copytext').addClass('copy_off');

    /* imgage display memo */
    $('#imgmemo').unbind('click');
    $('#imgmemo').removeClass();
    $('#imgmemo').addClass('memoDisplay_off');

    /* image add memo */
    $('#imgaddmemo').unbind('click');
    $('#imgaddmemo').removeClass();
    $('#imgaddmemo').addClass('memoAdd_off');

    $('#imgmarking').unbind('click');
    $('#imgmarking').removeClass();
    $('#imgmarking').addClass('marking_off');

    $('#imgmarkingtoolbar').unbind('click');
    $('#imgmarkingtoolbar').removeClass();
    $('#imgmarkingtoolbar').addClass('markingToolbar_off');

    $('#firstpage').unbind('click');
    $('#firstpage').removeClass();
    $('#firstpage').addClass('begin_off');
    $('#prevpage').unbind('click');
    $('#prevpage').removeClass();
    $('#prevpage').addClass('prev_off');
    $('#nextpage').unbind('click');
    $('#nextpage').removeClass();
    $('#nextpage').addClass('next_off');
    $('#lastpage').unbind('click');
    $('#lastpage').removeClass();
    $('#lastpage').addClass('last_off');

    $('#zoomfit').unbind('click');
    $('#zoomfit').removeClass();
    $('#zoomfit').addClass('fit_off');
    $('#zoomin').unbind('click');
    $('#zoomin').removeClass();
    $('#zoomin').addClass('expansion_off');
    $('#zoomout').unbind('click');
    $('#zoomout').removeClass();
    $('#zoomout').addClass('reduction_off');
    if (CONTENTVIEW_GENERAL.avwUserEnvObj.isAndroid() == false) {
        $("#slider_page").slider("option", "disabled", true);
    }

    COMMON.disable('#txtSearch', '#txtSlider');

    $('#button_next_canvas').css('display', 'none');
    $('#button_pre_canvas').css('display', 'none');

};

/*enable all control on page */
CONTENTVIEW_GENERAL.enableAllControl = function() {
	CONTENTVIEW_GENERAL.disableAllControl();

    /* set cursor pointer*/
    $("#imgHome").css('cursor', 'pointer');
    $("#imgBack").css('cursor', 'pointer');
    $("#listbookmark").css('cursor', 'pointer');
    $("#imgbookmark").css('cursor', 'pointer');

    //Start Function: No.12
    if (CONTENTVIEW_GENERAL.contentType == COMMON.ContentTypeKeys.Type_PDF) {
        $("#listindex").css('cursor', 'pointer');
        $("#copytext").css('cursor', 'pointer');
    }
    //End Function: No.12

    $("#imgmemo").css('cursor', 'pointer');
    $("#imgaddmemo").css('cursor', 'pointer');
    $("#imgmarking").css('cursor', 'pointer');
    $("#imgmarkingtoolbar").css('cursor', 'pointer');
    $("#firstpage").css('cursor', 'pointer');
    $("#prevpage").css('cursor', 'pointer');
    $("#nextpage").css('cursor', 'pointer');
    $("#lastpage").css('cursor', 'pointer');
    $("#zoomfit").css('cursor', 'pointer');
    // $("#zoomin").css('cursor', 'pointer');
    // $("#zoomout").css('cursor', 'pointer');
    $("#control_screen").css('cursor', 'pointer');
    $("#control_screen_2").css('cursor', 'pointer');

    //Start Function: No.12
    if (CONTENTVIEW_GENERAL.contentType == COMMON.ContentTypeKeys.Type_PDF || CONTENTVIEW_GENERAL.contentType == COMMON.ContentTypeKeys.Type_NoFile) {
        $("#slider_page").css('cursor', 'pointer');
        $(".ui-slider-handle").css('cursor', 'pointer');
    }
    //End Function: No.12

    $("#liAddMemo").css('cursor', 'pointer');
    $("#liCopyMemo").css('cursor', 'pointer');
    $("#liDeleteMemo").css('cursor', 'pointer');

    $("#control_screen").removeClass();
    $("#control_screen_2").removeClass();

    $('#imgHome').bind('click', CONTENTVIEW_EVENTS.imgHome_click);
    $('#imgHome').removeClass();

    $('#imgBack').bind('click', CONTENTVIEW_EVENTS.imgBack_click);
    $('#imgBack').removeClass();

    /*list bookmark */
    $('#listbookmark').bind('click', CONTENTVIEW_EVENTS.showListBookMark);
    $('#listbookmark').removeClass();


    $('#imgbookmark').bind('click', CONTENTVIEW.bookmarkPage);
    $('#imgbookmark').removeClass();

    //Start Function: No.12
    if (CONTENTVIEW_GENERAL.contentType == COMMON.ContentTypeKeys.Type_PDF) {
        $('#listindex').bind('click', CONTENTVIEW_EVENTS.showListPageIndex);
        $('#listindex').removeClass();

        $('#copytext').bind('click', CONTENTVIEW_EVENTS.showCopyText);
        $('#copytext').removeClass();
    }
    //End Function: No.12

    /* image memo */
    $('#imgmemo').bind('click', CONTENTVIEW.handleMemo);
    $('#imgmemo').removeClass();

    /* image add memo */
    $('#imgaddmemo').bind('click', CONTENTVIEW_EVENTS.handleAddMemo);
    $('#imgaddmemo').removeClass();

    $('#imgmarking').bind('click', CONTENTVIEW_EVENTS.imgmarking_click);
    $('#imgmarking').removeClass();

    if (ClientData.serviceOpt_marking() == 'Y') {
        $('#imgmarkingtoolbar').bind('click', CONTENTVIEW.handleDrawCanvas);
        $('#imgmarkingtoolbar').removeClass();
    }

    CONTENTVIEW.checkDisableButtonZoom();
    //Start Function: No.12
    if (CONTENTVIEW_GENERAL.contentType == COMMON.ContentTypeKeys.Type_PDF || CONTENTVIEW_GENERAL.contentType == COMMON.ContentTypeKeys.Type_NoFile) {
        $("#slider_page").slider("option", "disabled", false);
        
        if(CONTENTVIEW_GENERAL.contentType == COMMON.ContentTypeKeys.Type_PDF){
            COMMON.enable('#txtSearch', '#txtSlider'); 
        }        
        else if(CONTENTVIEW_GENERAL.contentType == COMMON.ContentTypeKeys.Type_NoFile){
            COMMON.enable('#txtSlider');
        }               
    }
   
    
    if (CONTENTVIEW_GENERAL.avwUserEnvObj.isIos() == false && CONTENTVIEW_GENERAL.avwUserEnvObj.isAndroid() == false) {
        $('#button_next_canvas').css('display', 'block');
        $('#button_pre_canvas').css('display', 'block');
    }

    if (COMMON.isTouchDevice() == true) {/* set css for device */
        $('#imgHome').addClass('home_device');
        $('#imgBack').addClass('back_device');

        $("#control_screen").addClass('toolbar_device');
        //$("#control_screen_2").addClass('toolbar_device');
        $("#control_screen_2").addClass('toolbar_close_device');

        var nBookmarkId = CONTENTVIEW.isExistBookmark();
        if (nBookmarkId == -1) {
            $('#imgbookmark').addClass('bmAdd_device');
        } else {
            $('#imgbookmark').addClass('bmAdd_hover');
        }

        if (CONTENTVIEW_GENERAL.isDisplayBookMarkList == true) {
            $('#listbookmark').addClass('bmList_hover');
        } else {
            $('#listbookmark').addClass('bmList_device');
        }

        if (CONTENTVIEW_GENERAL.isDisplayCopyText == true) {
            $('#copytext').addClass('copy_hover');
        } else {
            $('#copytext').addClass('copy_device');
        }

        if (CONTENTVIEW_GENERAL.isDisplayListIndex == true) {
            $('#listindex').addClass('index_hover');
        } else {
            $('#listindex').addClass('index_device');
        }

        if (ClientData.IsDisplayMemo() == true) {
            $('#imgmemo').addClass('memoDisplay_hover');
        } else {
            $('#imgmemo').addClass('memoDisplay_device');
        }

        if (ClientData.IsAddingMemo() == true) {
            $('#imgaddmemo').addClass('memoAdd_hover');
        } else {
            $('#imgaddmemo').addClass('memoAdd_device');
        }

        if (ClientData.IsDisplayMarking() == true) {
            $('#imgmarking').addClass('marking_hover');
        } else {
            $('#imgmarking').addClass('marking_device');
        }
        if (ClientData.serviceOpt_marking() == 'Y') {
            if (ClientData.IsAddingMarking() == true) {
                $('#imgmarkingtoolbar').addClass('markingToolbar_hover');
            } else {
                $('#imgmarkingtoolbar').addClass('markingToolbar_device');
            }
        }
    } else { /* set css for PC */
        $('#imgHome').addClass('home');
        $('#imgBack').addClass('back');
        $("#control_screen").addClass('toolbar');
        $("#control_screen_2").addClass('toolbar_close');

        var nBookmarkId = CONTENTVIEW.isExistBookmark();
        if (nBookmarkId == -1) {
            $('#imgbookmark').addClass('bmAdd');
        } else {
            $('#imgbookmark').addClass('bmAdd_hover');
        }

        if (CONTENTVIEW_GENERAL.isDisplayBookMarkList == true) {
            $('#listbookmark').addClass('bmList_hover');
        } else {
            $('#listbookmark').addClass('bmList');
        }

        if (CONTENTVIEW_GENERAL.isDisplayCopyText == true) {
            $('#copytext').addClass('copy_hover');
        } else {
            $('#copytext').addClass('copy');
        }

        if (CONTENTVIEW_GENERAL.isDisplayListIndex == true) {
            $('#listindex').addClass('index_hover');
        } else {
            $('#listindex').addClass('index');
        }

        if (ClientData.IsDisplayMemo() == true) {
            $('#imgmemo').addClass('memoDisplay_hover');
        } else {
            $('#imgmemo').addClass('memoDisplay');
        }

        if (ClientData.IsAddingMemo() == true) {
            $('#imgaddmemo').addClass('memoAdd_hover');
        } else {
            $('#imgaddmemo').addClass('memoAdd');
        }

        if (ClientData.IsDisplayMarking() == true) {
            $('#imgmarking').addClass('marking_hover');
        } else {
            $('#imgmarking').addClass('marking');
        }
        if (ClientData.serviceOpt_marking() == 'Y') {
            if (ClientData.IsAddingMarking() == true) {
                $('#imgmarkingtoolbar').addClass('markingToolbar_hover');
            } else {
                $('#imgmarkingtoolbar').addClass('markingToolbar');
            }
        }
    }
    
    if( ClientData.isGetitsMode() == true ){
        $('#imgHome').unbind('click');
        $('#imgHome').removeClass();
        $('#imgHome').addClass('home_off');

        /* back button */
        $('#imgBack').unbind('click');
        $('#imgBack').removeClass();
        $('#imgBack').addClass('back_off');
    }
    
    CONTENTVIEW.checkExistNextPrePage();
};

/*
Clear canvas
*/
CONTENTVIEW_GENERAL.clearCanvas = function(targetCanvas) {
    targetCanvas.width = targetCanvas.width;
};

//CONTENTVIEW_GENERAL.encode = function(data) {
//    var str = String.fromCharCode.apply(null, data);
//    return btoa(str).replace(/.{76}(?=.)/g, '$&\n');
//};

CONTENTVIEW_GENERAL.showDialog = function(modal) {
	
	if(ClientData.isStreamingMode()){
		$("#dialog").css('z-index', 998);
		$("#dialog").fadeIn(300);
	} else {
	    $("#overlay").show();
	    $("#dialog").fadeIn(300);
	
	    if (modal) {
	        $("#overlay").unbind("click");
	    }
	    else {
	        $("#overlay").click(function (e) {
	        	CONTENTVIEW_GENERAL.hideDialog();
	        });
	    }
	}
    
};

CONTENTVIEW_GENERAL.hideDialog = function() {
    $("#overlay").hide();
    $("#dialog").fadeOut(200);
    $('#dialog').children().remove();
};
