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

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

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

//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();

        if(ClientData.serviceOpt_copy_text() == 'Y') {
        	$('#copytext').bind('click', CONTENTVIEW_EVENTS.showCopyText);
            $('#copytext').removeClass();
        } else {
        	$('#copytext').unbind('click');
        	$('#copytext').removeClass();
            $('#copytext').addClass('copy_off');
        }
       // sessionStorage.removeItem('copy_text');
       // $('#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.showDialog = function(modal) {

	if(ClientData.isStreamingMode() || CONTENTVIEW_GENERAL.avwUserEnvObj.isMobile()){
		$("#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();
};

$(function () {
	//CONTENTVIEW_GENERAL.ready();
});

CONTENTVIEW_GENERAL.animateTypeKeys = {
	    Type_Slide : 0,
	    Type_FadeIn : 1
};

CONTENTVIEW_GENERAL.ready = function(initContentId){

	/* init variable */
	CONTENTVIEW_GENERAL.pageImages = '';
	CONTENTVIEW_GENERAL.totalPage = 0;
	CONTENTVIEW_GENERAL.pageObjects = [];
	CONTENTVIEW_GENERAL.pageObjectsData = [];
	CONTENTVIEW_GENERAL.tool = undefined;
	CONTENTVIEW_GENERAL.isFullScreen = false;
	CONTENTVIEW_GENERAL.ctrlMode = false;
	CONTENTVIEW_GENERAL.dataWebContentPage;
	CONTENTVIEW_GENERAL.dataPageTitle = undefined;
	CONTENTVIEW_GENERAL.dataJsonType4 = undefined;
	CONTENTVIEW_GENERAL.dataJsonType5 = undefined;

	//オーサリングプレビュー対応
	if(initContentId != null && initContentId != undefined){
		CONTENTVIEW_GENERAL.contentID = initContentId;
	} else {
		CONTENTVIEW_GENERAL.contentID = undefined;
	}
	CONTENTVIEW_GENERAL.isOpenPopUpText = false;
	CONTENTVIEW_GENERAL.isOpenPopUpMemo = true;
	CONTENTVIEW_GENERAL.objEditMemo = undefined;
	CONTENTVIEW_GENERAL.isCopyMemo = false;
	//CONTENTVIEW_GENERAL.isExistCopyMemo = false;
	CONTENTVIEW_GENERAL.posXPopupMemo = 0;
	CONTENTVIEW_GENERAL.posYPopupMemo = 0;
	CONTENTVIEW_GENERAL.contentName = '';
	CONTENTVIEW_GENERAL.nCountObjectLoad = new Array(3);
	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 = undefined;
	CONTENTVIEW_GENERAL.sy = undefined;
	CONTENTVIEW_GENERAL.imgDrawingTemp = undefined;
	CONTENTVIEW_GENERAL.imgMarkerTemp = undefined;
	//CONTENTVIEW_GENERAL.isSizingDrawCanvas = false;
	CONTENTVIEW_GENERAL.isDisplayBookMarkList = false;
	CONTENTVIEW_GENERAL.avwUserEnvObj = new UserEnvironment();
	CONTENTVIEW_GENERAL.canvas_marker = undefined;
	CONTENTVIEW_GENERAL.context_marker = undefined;
	CONTENTVIEW_GENERAL.canvas_draw = undefined;
	CONTENTVIEW_GENERAL.context_draw = undefined;
	CONTENTVIEW_GENERAL.canvas_main = undefined;
	CONTENTVIEW_GENERAL.context_main = undefined;
	CONTENTVIEW_GENERAL.canvas_offscreen = undefined;
	CONTENTVIEW_GENERAL.context_offscreen = undefined;
	CONTENTVIEW_GENERAL.isAddingMarking = undefined;
	CONTENTVIEW_GENERAL.penSize = undefined;
	CONTENTVIEW_GENERAL.penColor = undefined;
	CONTENTVIEW_GENERAL.makerSize = undefined;
	CONTENTVIEW_GENERAL.makerColor = undefined;
	CONTENTVIEW_GENERAL.eraseSize = undefined;
	CONTENTVIEW_GENERAL.markingType = undefined;
	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.isStopBGM = false;
	CONTENTVIEW_GENERAL.isJumpNotFromFirstPage = false;
	CONTENTVIEW_GENERAL.standardRatio = 1; //未使用
	CONTENTVIEW_GENERAL.currentRatio = 1; //未使用
	CONTENTVIEW_GENERAL.resourceImage = new Image();
	CONTENTVIEW_GENERAL.number = 0;
	CONTENTVIEW_GENERAL.positonX = undefined;
	CONTENTVIEW_GENERAL.positonY = undefined;
	CONTENTVIEW_GENERAL.newpositionX = undefined;
	CONTENTVIEW_GENERAL.newpositionY = undefined;

	//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 = undefined;
	CONTENTVIEW_GENERAL.pyVideo = undefined;
	CONTENTVIEW_GENERAL.wVideo = undefined;
	CONTENTVIEW_GENERAL.hVideo = undefined;
	CONTENTVIEW_GENERAL.videoScale = undefined; //未使用

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

	CONTENTVIEW_GENERAL.contentType = undefined;

	CONTENTVIEW_GENERAL.imageTypeData = undefined;

	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.animateType = undefined;
	CONTENTVIEW_GENERAL.animatePeriod = undefined;

	//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;

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

	//panoPageNo
	CONTENTVIEW_GENERAL.panoPageNo = null;
	
	//オーサリングプレビュー対応
	if(initContentId != null && initContentId != undefined){
		CONTENTVIEW_GENERAL.pid = initContentId;
	} else {
		CONTENTVIEW_GENERAL.pid = '';
	}
};


