/* ----------------------------------- Create memo --------------------------------*/

var memoObjects = [];

/* constructor */
var MemoObject = function (id, text, x, y, width, heigth, imageUrl, action) {

};

/* setup each properties */
MemoObject.prototype.setup = function (id, text, x, y, w, h, imageUrl) {
    this.text = text;
    this.id = id;
    this.x = x;
    this.y = y;
    this.width = w;
    this.height = h;
    this.imageUrl = imageUrl;
};

/* prototype hitTest */
MemoObject.prototype.hitTest = function (px, py) {

    //#11478
    var canvasWidth = $('#offscreen').width();
    var canvasHeight = $('#offscreen').height();
    var tempRatioWidth = canvasWidth / widthEachPageApi;
    if( tempRatioWidth < 1 ){
        tempRatioWidth = 1;
    }
    var tempRatioHeight = canvasHeight / heightEachPageApi;
    if( tempRatioHeight < 1 ){
        tempRatioHeight = 1;
    }
    var tmpX = this.x * tempRatioWidth;
    var tmpY = this.y * tempRatioHeight;
    var tmpW = this.width * tempRatioWidth;
    var tmpH = this.height * tempRatioHeight;

    if (tmpX <= px && px <= (tmpX + tmpW)) {
        if (tmpY <= py && py <= (tmpY + tmpH)) {
            return true;
        }
    }
    //if (this.x <= px && px <= (this.x + this.width)) {
    //    if (this.y <= py && py <= (this.y + this.height)) {
    //        return true;
    //    }
    //}
    return false;
};

/* draw Memo */
MemoObject.prototype.drawMemo = function (context, opt) {

    //#1478
    var canvasWidth = $('#offscreen').width();
    var canvasHeight = $('#offscreen').height();
    var tempRatioWidth = canvasWidth / widthEachPageApi;
    if( tempRatioWidth < 1 ){
        tempRatioWidth = 1;
    }
    var tempRatioHeight = canvasHeight / heightEachPageApi;
    if( tempRatioHeight < 1 ){
        tempRatioHeight = 1;
    }
    
    var posX = this.x * tempRatioWidth;
    var posY = this.y * tempRatioHeight;
    var objWidth = this.width * tempRatioWidth;
    var objHeigth = this.height * tempRatioHeight;
    //var posX = this.x;
    //var posY = this.y;
    //var objWidth = this.width;
    //var objHeigth = this.height;
    var imageObj = new Image();

    imageObj.onload = function () {
        context.drawImage(imageObj, posX, posY, objWidth, objHeigth);
        flip(opt);
    };
    imageObj.src = this.imageUrl;

};

/* create memo object */
var memo = function (id, text, x, y, w, h, imageUrl) {
    this.setup(id, text, x, y, w, h, imageUrl);
    this.action = function () {
        EditMemo(id, 0, 0, $('#divDialogMemo'), function () {
            /*set flag change memo */
            ClientData.isChangedMemo(true);
        });
    };
};

memo.prototype = new MemoObject();

/*click showEditMemo() */
function showEditMemo() {
    objEditMemo.action();
};

/*click copyMemo() */
function copyMemo() {
    //isCopyMemo = true;
    ClientData.memo_copyText(objEditMemo.text);
    //disableControlsCopyMemo();
    $("#pop_up_memo").hide();
};


/* ----------------------------------- End create memo -----------------------------*/


/* ----------------------------------- Create webGetContentType4 --------------------------------*/

var webGetContentType4Objects = [];

/* constructor */
var WebGetContentTyp4Object = function (id, x, y, width, heigth, imageUrl, action) {

};

/* setup each properties */
WebGetContentTyp4Object.prototype.setup = function (id, x, y, w, h, imageUrl) {
    this.id = id;
    this.x = x;
    this.y = y;
    this.width = w;
    this.height = h;
    this.imageUrl = imageUrl;
};

/* prototype hitTest */
WebGetContentTyp4Object.prototype.hitTest = function (px, py) {

    //#11478
    var canvasWidth = $('#offscreen').width();
    var canvasHeight = $('#offscreen').height();
    var tempRatioWidth = canvasWidth / widthEachPageApi;
    if( tempRatioWidth < 1 ){
        tempRatioWidth = 1;
    }
    var tempRatioHeight = canvasHeight / heightEachPageApi;
    if( tempRatioHeight < 1 ){
        tempRatioHeight = 1;
    }
    var tmpX = this.x * tempRatioWidth;
    var tmpY = this.y * tempRatioHeight;
    var tmpW = this.width * tempRatioWidth;
    var tmpH = this.height * tempRatioHeight;

    if (tmpX <= px && px <= (tmpX + tmpW)) {
        if (tmpY <= py && py <= (tmpY + tmpH)) {
            return true;
        }
    }
    return false;
};

/* draw Memo */
WebGetContentTyp4Object.prototype.drawObject = function (context, opt) {
    
    //#11478
    var canvasWidth = $('#offscreen').width();
    var canvasHeight = $('#offscreen').height();
    var tempRatioWidth = canvasWidth / widthEachPageApi;
    if( tempRatioWidth < 1 ){
        tempRatioWidth = 1;
    }
    var tempRatioHeight = canvasHeight / heightEachPageApi;
    if( tempRatioHeight < 1 ){
        tempRatioHeight = 1;
    }
    
    var posX = this.x * tempRatioWidth;
    var posY = this.y * tempRatioHeight;
    var objWidth = this.width * tempRatioWidth;
    var objHeigth = this.height * tempRatioHeight;
    var imageObj = new Image();
    imageObj.onload = function () {
        context.globalAlpha = 0.4;

        context.drawImage(imageObj, posX, posY, objWidth, objHeigth);
        
        //Start Function : No.4 - Editor: Long - Date : 08/14/2013 - Summary : handle lazy loading
        flip(opt);
       //Start Function : No.4 - Editor: Long - Date : 08/14/2013 - Summary : handle lazy loading   
        context.globalAlpha = 1;
    };
    imageObj.src = this.imageUrl;

};

/* create memo object */
var webContentType4 = function (id, x, y, w, h, imageUrl, linkKind, destURI, destPageNumber) {
    this.setup(id, x, y, w, h, imageUrl);
    this.action = function () {
        if (linkKind == "1") {
            //START TRB00070
            window.onbeforeunload = null;
            //window.open(destURI, "_blank", "new window");
            window.open(destURI, "_self");
            
            setTimeout(function(){COMMON.ToogleLogoutNortice();}, 200);
            
            //END TRB00070
            
        } 
        else if (linkKind == "0") {
            changePage(changePageNo(destPageNumber));
        }
    };
};
webContentType4.prototype = new WebGetContentTyp4Object();

/* ----------------------------------- End create webGetContentType4 -----------------------------*/

/**
* PageObject Class Definition 
*/

/* constructor */
var PageObject = function (id, imageUrl, x, y, w, h, visible, actionFunction, displayBorder) {
};

/* setup each properties */
PageObject.prototype.setup = function (mediaType, actionType, id, imageUrl, x, y, w, h, visible, actionFunction, displayBorder, objectId) {

    this.mediaType = mediaType;
    this.actionType = actionType;
    this.id = id;
    this.x = x;
    this.y = y;
    this.width = w;
    this.height = h;
    this.displayBorder = displayBorder;
    this.visible = visible;
    this.imageUrl = imageUrl;
    this.image = new Image();
    this.image.src = this.imageUrl;
    
    this.objectId = objectId;
    
};

/* prototype hitTest */
PageObject.prototype.hitTest = function (px, py) {

    //#11478
    var canvasWidth = $('#offscreen').width();
    var canvasHeight = $('#offscreen').height();
    var tempRatioWidth = canvasWidth / widthEachPageApi;
    if( tempRatioWidth < 1 ){
        tempRatioWidth = 1;
    }
    var tempRatioHeight = canvasHeight / heightEachPageApi;
    if( tempRatioHeight < 1 ){
        tempRatioHeight = 1;
    }
    var tmpX = this.x * tempRatioWidth;
    var tmpY = this.y * tempRatioHeight;
    var tmpW = this.width * tempRatioWidth;
    var tmpH = this.height * tempRatioHeight;
    
    if ( tmpX <= px && px <= (tmpX + tmpW)) {
        if (tmpY <= py && py <= (tmpY + tmpH)) {
            return true;
        }
    }
    //if (this.x <= px && px <= (this.x + this.width)) {
    //    if (this.y <= py && py <= (this.y + this.height)) {
    //        return true;
    //    }
    //}
    return false;
};
var check;
/* draw page Object */
//Start Function: No.4 - Editor : Long - Date: 08/09/2013 - Summary : Edit function to draw object on next page
PageObject.prototype.drawPageObject = function (context, opt) {
    
    var nObjectCnt = 0;
    //#11478
    var tempRatioWidth = 1;
    var tempRatioHeight = 1;
    var canvasWidth = 0;
    var canvasHeight = 0;
    
    //Check which pageObject to be count
    if(opt == null || opt == 0){
        nObjectCnt = pageObjects.length;
        
        //#11478
        canvasWidth = $('#offscreen').width();
        canvasHeight = $('#offscreen').height();
        tempRatioWidth = canvasWidth / widthEachPageApi;
        if( tempRatioWidth < 1 ){
            tempRatioWidth = 1;
        }
        var tempRatioHeight = canvasHeight / heightEachPageApi;
        if( tempRatioHeight < 1 ){
            tempRatioHeight = 1;
        }
        
    }
    else if(opt == 1){
        nObjectCnt = nextPageObjects.length;
        
        //#11478
        canvasWidth = $('#offscreenNext').width();
        canvasHeight = $('#offscreenNext').height();
        tempRatioWidth = canvasWidth / widthEachNextPageApi;
        if( tempRatioWidth < 1 ){
            tempRatioWidth = 1;
        }
        var tempRatioHeight = canvasHeight / heightEachNextPageApi;
        if( tempRatioHeight < 1 ){
            tempRatioHeight = 1;
        }
        
    }
    else if(opt == 2){
        nObjectCnt = prevPageObjects.length;
        
        //#11478
        canvasWidth = $('#offscreenPre').width();
        canvasHeight = $('#offscreenPre').height();
        tempRatioWidth = canvasWidth / widthEachPrevPageApi;
        if( tempRatioWidth < 1 ){
            tempRatioWidth = 1;
        }
        var tempRatioHeight = canvasHeight / heightEachPrevPageApi;
        if( tempRatioHeight < 1 ){
            tempRatioHeight = 1;
        }
        
    }
    
    if (this.visible) {
        /* init data */
        var mediaType = this.mediaType;
        var displayBorder = this.displayBorder;
        
        //#11478
        var x = this.x * tempRatioWidth;
        var y = this.y * tempRatioHeight;
        var w = this.width * tempRatioWidth;
        var h = this.height * tempRatioHeight;
        
        var tempUrl = this.imageUrl;
        var isUsedTempImg = false;
        
        //START TRB00046 - Editor : Long - Date: 09/19/2013 - Summary : Fix for draw video object at center
        if(mediaType == '6' && tempUrl == 'img/iPad_video.png'){
            isUsedTempImg = true;
        }
        //END TRB00046 - Editor : Long - Date: 09/19/2013 - Summary : Fix for draw video object at center
        
        if (mediaType == '5') {
            nCountObjectLoad++;
            context.strokeStyle = "black";
            context.lineWidth = "1";
            context.strokeRect(x, y, w, h);
            
            flip(opt);
        }

        if (this.imageUrl != '') {
            /* init image  */
            var img = new Image();

            img.onload = function () {
                nCountObjectLoad++;


                /* create object store value image */
                var objTemp = [];
                objTemp.mediaType = mediaType;
                objTemp.img = img;
                objTemp.x = x;
                objTemp.y = y;
                objTemp.w = w;
                objTemp.h = h;
                objTemp.displayBorder = displayBorder;

                /* push to array */
                arrImage.push(objTemp);

                if (mediaType == '2') {/*  media */
                    img.width = 50;
                    img.height = 50;

                    if (img.width > w) {
                        context.drawImage(img, x, y, w, h);
                    } else {
                        /*draw image and border */
                        context.drawImage(img, x + ((w - img.width) / 2), y + ((h - img.height) / 2), img.width, img.height);
                        if (displayBorder == '1') {/* draw border */
                            context.strokeStyle = "black";
                            context.lineWidth = "1";
                            context.strokeRect(x, y, w, h);
                        }
                    }

                } 
                else if (mediaType == '3') {/* audio */
                    img.width = 50;
                    img.height = 50;
                    
                    //START TRB00035 - Editor : Long - Date: 09/17/2013 - Summary : Fix for draw audio object at center
                    context.drawImage(img, x + (w/2 - img.width/2), y + (h/2 - img.height/ 2), img.width, img.height);                 
                    //END TRB00035 - Editor : Long - Date: 09/17/2013 - Summary : Fix for draw audio object at center                                      
                    
                }
                else if(mediaType == '6' && isUsedTempImg){
                    img.width = 50;
                    img.height = 50;
                    
                    //START TRB00046 - Editor : Long - Date: 09/19/2013 - Summary : Fix for draw video object at center
                    context.drawImage(img, x + (w/2 - img.width/2), y + (h/2 - img.height/ 2), img.width, img.height);   
                                        
                    isUsedTempImg = false;              
                    //END TRB00046 - Editor : Long - Date: 09/19/2013 - Summary : Fix for draw video object at center  

                }
                else {
                    context.drawImage(img, x, y, w, h);
                }
                
                flip(opt);
                
                if (nCountObjectLoad >= nObjectCnt) {                       

                    /* draw marking */
                    drawMarkingOnScreen(opt);

                    /*set status is loading page */
                    //Start Function : No.4 - Summary : make sure all page is loaded
                    if(contentType == COMMON.ContentTypeKeys.Type_PDF || contentType == COMMON.ContentTypeKeys.Type_NoFile){
                        if(totalPage > 1){
                            if(opt != 0 && opt != null){
                                isLoadingObject = false;
                            }
                        }
                        else{
                            isLoadingObject = false;
                        }                                          
                    }
                    else{
                         isLoadingObject = false;
                    }
                    //End Function : No.4 - Summary : make sure all page is loaded

                    /* enable controls in page */
                    if (ClientData.IsAddingMarking() == true) {
                        disableAllControl();
                        //Start Function : No.4 - Summary : make sure all page is loaded
                        if(contentType == COMMON.ContentTypeKeys.Type_PDF || contentType == COMMON.ContentTypeKeys.Type_NoFile){
                            if(totalPage > 1){
                                if(opt != 0 && opt != null){
                                    enableButtonMarking();
                                }   
                            }
                            else{
                                enableButtonMarking();
                            }                     
                        }
                        else{
                             enableButtonMarking();
                        }
                        //End Function : No.4 - Summary : make sure all page is loaded                       
                    } 
                    else {
                        //Start Function : No.4 - Summary : make sure all page is loaded
                        if(contentType == COMMON.ContentTypeKeys.Type_PDF || contentType == COMMON.ContentTypeKeys.Type_NoFile){
                            if(totalPage > 1){
                                if(opt != 0 && opt != null){
                                    enableAllControl();
                                }
                            }
                            else{
                                enableAllControl();
                            }                     
                        }
                        else{
                             enableAllControl();
                        }
                        //End Function : No.4 - Summary : make sure all page is loaded  
                    }

                    /*finish loading */
                     //Start Function : No.4 - Summary : make sure all page is loaded
                    if(contentType == COMMON.ContentTypeKeys.Type_PDF || contentType == COMMON.ContentTypeKeys.Type_NoFile){
                        if(totalPage > 1){
                            if(opt != 0 && opt != null){
                                 $('#divImageLoading').css('display', 'none');
                            }
                        }
                        else{
                            $('#divImageLoading').css('display', 'none');
                        }                                                  
                    }
                    else{
                          $('#divImageLoading').css('display', 'none');
                    }
                    //End Functi

                    /* set pos video */
                    zoomVideo();
                }
            };
            img.src = this.imageUrl;
        } 
        else {
            if (nCountObjectLoad >= nObjectCnt) {
                /* draw marking */
                drawMarkingOnScreen(opt);

                /*set status is loading page */
                isLoadingObject = false;
                /* enable controls in page */
                if (ClientData.IsAddingMarking() == true) {
                    disableAllControl();
                     //Start Function : No.4 - Summary : make sure all page is loaded
                    if(contentType == COMMON.ContentTypeKeys.Type_PDF || contentType == COMMON.ContentTypeKeys.Type_NoFile){
                        if(totalPage > 1){
                            if(opt != 0 && opt != null){
                                 enableButtonMarking();
                            }
                        }
                        else{
                            enableButtonMarking();
                        }                       
                    }
                    else{
                          enableButtonMarking();
                    }
                    //End Function : No.4 - Summary : make sure all page is loaded  
                } else {
                    //Start Function : No.4 - Summary : make sure all page is loaded
                    if(contentType == COMMON.ContentTypeKeys.Type_PDF || contentType == COMMON.ContentTypeKeys.Type_NoFile){
                        if(totalPage > 1){
                            if(opt != 0 && opt != null){
                                 enableAllControl();
                            }     
                        }
                        else{
                           enableAllControl(); 
                        }                   
                    }
                    else{
                          enableAllControl();
                    }
                    //End Function : No.4 - Summary : mak
                }

                /*finish loading */ 
                //Start Function : No.4 - Summary : make sure all page is loaded
                if(contentType == COMMON.ContentTypeKeys.Type_PDF || contentType == COMMON.ContentTypeKeys.Type_NoFile){
                    if(totalPage > 1){
                        if(opt != 0 && opt != null){
                             $('#divImageLoading').css('display', 'none');
                        }    
                    }
                    else{
                        $('#divImageLoading').css('display', 'none');
                    }                    
                }
                else{
                      $('#divImageLoading').css('display', 'none');
                }
                //End Func
                /* set pos video */
                zoomVideo();
            }
        }
    }
};
//End Function: No.4 - Editor : Long - Date: 08/09/2013 - Summary : Edit function to draw object on next page

//Start Function : No.9

/*mediaType = 8 3d object*/
var _isEnableRotate = false;
var object3d = function (mediaType, actionType, id, imageUrl, x, y, w, h, hCnt, vCnt, visible, imageObjects, objectId){
    
    this.setup(mediaType, actionType, id, imageUrl, x, y, w, h, visible, null, null, objectId);
    this.action = function (imagePt){      
                    
        //abe
        //alert("object3d");
        
        //#11478
        var canvasWidth = $('#offscreen').width();
        var canvasHeight = $('#offscreen').height();
        var tempRatioWidth = canvasWidth / widthEachPageApi;
        if( tempRatioWidth < 1 ){
            tempRatioWidth = 1;
        }
        var tempRatioHeight = canvasHeight / heightEachPageApi;
        if( tempRatioHeight < 1 ){
            tempRatioHeight = 1;
        }
        var tmpX = x *  tempRatioWidth;
        var tmpY = y * tempRatioHeight;
        var tmpW = w *  tempRatioWidth;
        var tmpH = h * tempRatioHeight;
        
       if(_3dAction == _3dActionType.TouchStart_MouseDown){
           OnMouseDown3D(id, imagePt, tmpX, tmpY);
       }
       else if(_3dAction == _3dActionType.TouchMove_MouseMove){
           OnMouseMove3D(id, imagePt, tmpX, tmpY, tmpW, tmpH, hCnt, vCnt);
       }
       else if(_3dAction == _3dActionType.TouchEnd_MouseUp){
           OnMouseEnd3D(id, hCnt, vCnt);
           
            //詳細ログ作成
            var objectLog = new ObjectLogEntity();
            objectLog.contentid = contentID;
            objectLog.pageNo = getPageIndex() + 1; //0始まりのページ番号
            objectLog.objectId = objectId;
            objectLog.resourceId = "";
            objectLog.mediaType = mediaType;
            objectLog.actionType = actionType;
            objectLog.actionValue = "";
            objectLog.actionTime = "0";
            objectLog.locationX = x;
            objectLog.locationY = y;
            objectLog.locationHeight = h;
            objectLog.locationWidth = w;
            COMMON.SetObjectLog(contentID, objectLog);
            //---
           
       }              
    };
};
object3d.prototype = new PageObject();

//End Function : No.9

/* mediaType = 7 write text object*/
var text = function (mediaType, actionType, id, x, y, w, h, visible, actionFunction, content, objectId) {
    //var imageUrl = displayText(x,y,w,h,id,content);
    var imageUrl = TEXTOBJECT.getTextObjectImage(w, h, content);
    this.setup(mediaType, actionType, id, imageUrl, x, y, w, h, visible, actionFunction, null, objectId);
    this.action = function () {
    };
};
text.prototype = new PageObject();

/* mediaType=4  list image object : extends PageObject */
var listImage = function (mediaType, id, imageUrl, x, y, w, h, visible, imageObjects, triggerType, objectId) {
    this.setup(mediaType, null, id, imageUrl, x, y, w, h, visible, null, null, objectId);
    this.action = function () {
    
        if (triggerType == '1') {
        
            //abe
            //alert("listImage triggerType=1");
        
            //詳細ログ作成
            var objectLog = new ObjectLogEntity();
            objectLog.contentid = contentID;
            objectLog.pageNo = getPageIndex() + 1; //0始まりのページ番号
            objectLog.objectId = objectId;
            //objectLog.resourceId = "";
            objectLog.mediaType = mediaType;
            objectLog.actionType = "";
            objectLog.actionValue = "";
            objectLog.actionTime = "0";
            objectLog.locationX = x;
            objectLog.locationY = y;
            objectLog.locationHeight = h;
            objectLog.locationWidth = w;
            //COMMON.SetObjectLog(contentID, objectLog);
            //---
        
            mediaType4_changeImage++;

            /* check index bigger than length object */
            if (mediaType4_changeImage > (imageObjects.length - 1)) {
                mediaType4_changeImage = 0;
            }

            //リソースIDセット
            objectLog.resourceId = imageObjects[mediaType4_changeImage].resourceId;
            COMMON.SetObjectLog(contentID, objectLog);

            /* draw image */
            var imageObj = new Image();
            imageObj.onload = function () {
                var canvasObject = document.getElementById("offscreen");
                var contextObject = canvasObject.getContext("2d");
                
                //#11478
                var canvasWidth = $('#offscreen').width();
                var canvasHeight = $('#offscreen').height();
                var tempRatioWidth = canvasWidth / widthEachPageApi;
                if( tempRatioWidth < 1 ){
                    tempRatioWidth = 1;
                }
                var tempRatioHeight = canvasHeight / heightEachPageApi;
                if( tempRatioHeight < 1 ){
                    tempRatioHeight = 1;
                }
                var tmpX = x *  tempRatioWidth;
                var tmpY = y * tempRatioHeight;
                var tmpW = w *  tempRatioWidth;
                var tmpH = h * tempRatioHeight;
                
                contextObject.drawImage(imageObj, tmpX, tmpY, tmpW, tmpH);
                flip();
            };
            imageObj.src = imageObjects[mediaType4_changeImage].fileName;
            
        }
    };
};
listImage.prototype = new PageObject();

/* mediaType=5 Replace Video object : extends PageObject */
var listVideo = function (mediaType, id, imageUrl, x, y, w, h, visible, videoObjects, objectId) {
    this.setup(mediaType, null, id, imageUrl, x, y, w, h, visible, null, null, objectId);
    this.action = function () {
        //abe 
        //alert("listVideo");
    };
};
listVideo.prototype = new PageObject();

/* mediaType=6 Trigger object : extends PageObject */
var trigger = function (mediaType, actionType, id, imageUrl, x, y, w, h, index, target, visible, actionFunction, objectId) {
    this.setup(mediaType, actionType, id, imageUrl, x, y, w, h, visible, actionFunction, null, objectId);
    this.action = function () {
        // draw object      

        //abe
        //alert("trigger:" + + getPageIndex() + " id:" + id);

        //詳細ログ作成
        var objectLog = new ObjectLogEntity();
        objectLog.contentid = contentID;
        objectLog.pageNo = getPageIndex() + 1; //0始まりのページ番号
        objectLog.objectId = objectId;
        objectLog.resourceId = "";
        objectLog.mediaType = mediaType;
        objectLog.actionType = actionType;
        objectLog.actionValue = "";
        objectLog.actionTime = "0";
        objectLog.locationX = x;
        objectLog.locationY = y;
        objectLog.locationHeight = h;
        objectLog.locationWidth = w;

        for (var nIndex = 0; nIndex < objType4_5.length; nIndex++) {
            for (var nIndex1 = 0; nIndex1 < objType4_5[nIndex].dataObjects.length; nIndex1++) {
                if (objType4_5[nIndex].dataObjects[nIndex1].index == index
                    && objType4_5[nIndex].id == target) {
                    if (objType4_5[nIndex].mediaType == '4') {  /*image*/
                        changeImageType4(objType4_5, nIndex, nIndex1);
                        //詳細ログ用 画像なので0セット
                        objectLog.actionTime = "0";
                        //リソースID
                        objectLog.resourceId = objType4_5[nIndex].dataObjects[nIndex1].resourceId;
                    } else {   /* video */
                        stopAllAudio();
                        showVideoObject(objType4_5[nIndex].x, objType4_5[nIndex].y, objType4_5[nIndex].width, objType4_5[nIndex].height, objType4_5[nIndex].dataObjects[nIndex1].fileName, false);
                        //詳細ログ用 動画なのでダミーで1以上
                        objectLog.actionTime = "1";
                        //リソースID
                        objectLog.resourceId = objType4_5[nIndex].dataObjects[nIndex1].resourceId;
                    }
                    break;
                }
            }
        }
        
        //詳細ログ格納
        COMMON.SetObjectLog(contentID, objectLog);
        //---
        
    };
};
trigger.prototype = new PageObject();

//Start Function : No.9 - Editor : Long - Date: 08/16/2013 - Summary : 
var htmlLinkButton = function (mediaType, actionType, id, imageUrl, x, y, w, h, visible, resourceUrl, objectId) {

    this.setup(mediaType, actionType, id, imageUrl, x, y, w, h, visible, null, null, objectId);
    this.action = function () {
    
        //abe
        //alert("htmlLinkButton");
    
        /*stop audio on page */
        stopAllAudio();
        
        if (resourceUrl != "") {
        
            //詳細ログ作成
            var objectLog = new ObjectLogEntity();
            objectLog.contentid = contentID;
            objectLog.pageNo = getPageIndex() + 1; //0始まりのページ番号
            objectLog.objectId = objectId;
            objectLog.resourceId = "";
            objectLog.mediaType = mediaType;
            objectLog.actionType = actionType;
            objectLog.actionValue = "";
            objectLog.actionTime = "0";
            objectLog.locationX = x;
            objectLog.locationY = y;
            objectLog.locationHeight = h;
            objectLog.locationWidth = w;
            COMMON.SetObjectLog(contentID, objectLog);
            //---
        
            showHtml(resourceUrl, objectId );
            showDialog(true);
        }        
    };
};
htmlLinkButton.prototype = new PageObject();
function showHtml(url, objectId ){

    //abe
    //alert("showHtml");

    var $container = $('#dialog');
    
    $container.html('');
    $container.attr('style', 'background-color: white; width:100%; left:0% !important'); 
                 
   //START TRB00076 - EDITOR : Long - Date : 09/24/2013 - Summary : Fix for scrolling on ipad
    if(avwUserEnvObj.os == "ipad"){       
        $container.html(
          '<h1>' 
        + '<img src="img/viewer/x.png" style="margin:3px 3px 0px 21px" id="btnClose" class="align_right" ></img>' 
        + '</h1>'
        + '<div id="html-wrap" style="height: 95%; position: absolute; width: 100%;">'
        + '<iframe src="'+ url +'" style="position: absolute; width: 100%; height: 100%; ">'
        + '</iframe>'
        + '</div>'
        );
        
        $('#html-wrap').css('overflow', 'scroll');
        $('#html-wrap').css('-webkit-overflow-scrolling', 'touch');
    }
    else{
        $container.html(
          '<h1>' 
        + '<img src="img/viewer/x.png" style="margin:3px 3px 0px 21px" id="btnClose" class="align_right" ></img>' 
        + '</h1>'
        + '<iframe src="'+ url +'" style="position: absolute; width: 100%; height: 95%; ">'
        + '</iframe>'
        );
    }
    //END TRB00076 - EDITOR : Long - Date : 09/24/2013 - Summary : Fix for scrolling on ipad 
    
    $('#dialog h1 img').click(function(){
    
        var dateEnd = new Date();
        var actionTime = dateEnd.subtractBySeconds(dateStart);
        //alert("actionTime:" + actionTime);
        COMMON.SetObjectLogActionTime( contentID, objectId, actionTime );
    
        $container.removeAttr('style');
        hideDialog();
        
    });
    
    var dateStart = new Date();
    
}

var anket = function (mediaType, actionType, id, imageUrl, x, y, w, h, visible, questionNo, replyLimit, fullscreen, saveAs, resourceId, enquete, objectId) {

    this.setup(mediaType, actionType, id, imageUrl, x, y, w, h, visible, null, null, objectId);
    this.action = function () {
    
        //abe
        //alert("anket");
    
        //詳細ログ作成
        var objectLog = new ObjectLogEntity();
        objectLog.contentid = contentID;
        objectLog.pageNo = getPageIndex() + 1; //0始まりのページ番号
        objectLog.objectId = objectId;
        objectLog.resourceId = resourceId;
        objectLog.mediaType = mediaType;
        objectLog.actionType = actionType;
        objectLog.actionValue = enquete; //objectNameのほうが良かった
        objectLog.actionTime = "0";
        objectLog.locationX = x;
        objectLog.locationY = y;
        objectLog.locationHeight = h;
        objectLog.locationWidth = w;
        COMMON.SetObjectLog(contentID, objectLog);
        //---
    
        /*stop audio on page */
        stopAllAudio();
         
        var url = getURLPageImage("webEnqueteReply/init") + "/?abObjectId="+objectId + "&sid=" + ClientData.userInfo_sid();
        
        var isFullScreen = false;
        if(parseInt(fullscreen) == 1){
            isFullScreen = true;
        }
        
        showAnket(url, isFullScreen, objectId);
        showDialog(true);
           
    };
};
anket.prototype = new PageObject();

//End Function : No.9 - Editor : Long - Date: 08/16/2013 - Summary : 

/* mediaType=3  Audio object : extends PageObject */
var audioType3 = function (mediaType, actionType, id, imageUrl, x, y, w, h, visible, audioFile, audioResourceId, playType, objectId) {

    if (playType == "0") {
        this.setup(mediaType, actionType, id, imageUrl, x, y, w, h, visible, null, null, objectId);
        this.action = function () {
        
            //abe
            //alert("audioType3_0");
    
            //詳細ログ作成
            var objectLog = new ObjectLogEntity();
            objectLog.contentid = contentID;
            objectLog.pageNo = getPageIndex() + 1; //0始まりのページ番号
            objectLog.objectId = objectId;
            objectLog.resourceId = audioResourceId;
            objectLog.mediaType = mediaType;
            objectLog.actionType = actionType;
            objectLog.actionValue = "";
            objectLog.actionTime = "0";
            objectLog.locationX = x;
            objectLog.locationY = y;
            objectLog.locationHeight = h;
            objectLog.locationWidth = w;
            COMMON.SetObjectLog(contentID, objectLog);
            //---
        
            createAudio(audioFile, playType);
        };
    }
    else {
        //START : TRB00028 - Editor: Long - Date: 09/10/2013 - Summary : Fix For Page BGM
        if(playType == '2' || playType == 2){
            //
        }
        else{
        
            //abe
            //alert("audioType3_x");
    
            //詳細ログ作成
            var objectLog = new ObjectLogEntity();
            objectLog.contentid = contentID;
            objectLog.pageNo = getPageIndex() + 1; //0始まりのページ番号
            objectLog.objectId = objectId;
            objectLog.resourceId = audioResourceId;
            objectLog.mediaType = mediaType;
            objectLog.actionType = actionType;
            objectLog.actionValue = "";
            objectLog.actionTime = "0";
            objectLog.locationX = x;
            objectLog.locationY = y;
            objectLog.locationHeight = h;
            objectLog.locationWidth = w;
            COMMON.SetObjectLog(contentID, objectLog);
            //---
        
            createAudio(audioFile, playType);
        }
        //END : TRB00028 - Editor: Long - Date: 09/10/2013 - Summary : Fix For Page BGM
        this.setup(mediaType, actionType, id, null, x, y, w, h, visible, null, null, objectId);
        this.action = function () {
            //
        };
    }
};
audioType3.prototype = new PageObject();

/* mediaType = 1 and actionType = 5 jumpPage object*/
var jumpPage = function (mediaType, actionType, id, imageUrl, x, y, w, h, visible, jumpPage, objectId) {
    this.setup(mediaType, actionType, id, imageUrl, x, y, w, h, visible, null, null, objectId);
    this.action = function () {
    
        //abe
        //alert("jumpPage");
    
        //詳細ログ作成
        var objectLog = new ObjectLogEntity();
        objectLog.contentid = contentID;
        objectLog.pageNo = getPageIndex() + 1; //0始まりのページ番号
        objectLog.objectId = objectId;
        objectLog.resourceId = "";
        objectLog.mediaType = mediaType;
        objectLog.actionType = actionType;
        objectLog.actionValue = jumpPage; //ページ飛び先
        objectLog.actionTime = "0";
        objectLog.locationX = x;
        objectLog.locationY = y;
        objectLog.locationHeight = h;
        objectLog.locationWidth = w;
        COMMON.SetObjectLog(contentID, objectLog);
        //---
    
        if ((Number(jumpPage) - 1) != getPageIndex()) {
            createLockLayout(true);
            changePage(Number(jumpPage) - 1);
        }
    };
};

jumpPage.prototype = new PageObject();

/* mediaType = 1 and actionType = 6 send mail object*/
var sendMail = function (mediaType, actionType, id, imageUrl, x, y, w, h, visible, emailSubject, emailAddress, objectId) {
    this.setup(mediaType, actionType, id, imageUrl, x, y, w, h, visible, null, null, objectId);
    this.action = function () {
    
        //詳細ログ作成
        var objectLog = new ObjectLogEntity();
        objectLog.contentid = contentID;
        objectLog.pageNo = getPageIndex() + 1; //0始まりのページ番号
        objectLog.objectId = objectId;
        objectLog.resourceId = "";
        objectLog.mediaType = mediaType;
        objectLog.actionType = actionType;
        objectLog.actionValue = emailAddress; //メールアドレス
        objectLog.actionTime = "0";
        objectLog.locationX = x;
        objectLog.locationY = y;
        objectLog.locationHeight = h;
        objectLog.locationWidth = w;
        COMMON.SetObjectLog(contentID, objectLog);
        //---
    
        MailTo(emailAddress, emailSubject);
    };
};
sendMail.prototype = new PageObject();

/* mediaType = 1 and actionType = 8 open popup object*/
var openPopUp = function (mediaType, actionType, id, imageUrl, x, y, w, h, visible, content, objectId) {
    this.setup(mediaType, actionType, id, imageUrl, x, y, w, h, visible, null, null, objectId);
    this.action = function () {
    
        //abe
        //alert("openPopUp:" + getPageIndex() + " id:" + objectId);
        
        //詳細ログ作成
        var objectLog = new ObjectLogEntity();
        objectLog.contentid = contentID;
        objectLog.pageNo = getPageIndex() + 1; //0始まりのページ番号
        objectLog.objectId = objectId;
        objectLog.resourceId = "";
        objectLog.mediaType = mediaType;
        objectLog.actionType = actionType;
        objectLog.actionValue = "";
        objectLog.actionTime = "0";
        objectLog.locationX = x;
        objectLog.locationY = y;
        objectLog.locationHeight = h;
        objectLog.locationWidth = w;
        COMMON.SetObjectLog(contentID, objectLog);
        //---
        
        isOpenPopUpText = true;
        var pt1 = imageToScreen(x, y + h / 2);

        if (userScale > 1) {
            OpenPopupText(posXPopupMemo, posYPopupMemo, content, $('#dialogPopUp'), $('#arrow'));
        } else if ($("#header_toolbar").is(":hidden")) {
            OpenPopupText(pt1.x, pt1.y - 65, content, $('#dialogPopUp'), $('#arrow'));
        } else {
            OpenPopupText(pt1.x, pt1.y, content, $('#dialogPopUp'), $('#arrow'));
        }
    };
};
openPopUp.prototype = new PageObject();

var moveContentParam = {};

/* mediaType = 1 and actionType = 10 move to Content object*/
var moveToContent = function (mediaType, actionType, id, imageUrl, x, y, w, h, visible, contentId, pageNo, objectId) {
    this.setup(mediaType, actionType, id, imageUrl, x, y, w, h, visible, null, null, objectId);
    this.action = function () {
    
        //詳細ログ作成
        var objectLog = new ObjectLogEntity();
        objectLog.contentid = contentID;
        objectLog.pageNo = getPageIndex() + 1; //0始まりのページ番号
        objectLog.objectId = objectId;
        objectLog.resourceId = "";
        objectLog.mediaType = mediaType;
        objectLog.actionType = actionType;
        objectLog.actionValue = contentId;
        objectLog.actionTime = "0";
        objectLog.locationX = x;
        objectLog.locationY = y;
        objectLog.locationHeight = h;
        objectLog.locationWidth = w;
        COMMON.SetObjectLog(contentID, objectLog);
        //---
    
        ///* set end log */
        //COMMON.SetEndLog(contentID);
        //COMMON.RegisterLog();
        //START TRB00033 - EDITOR: Long - Date : 09/12/2013 - Summary : limit content
        avwCmsApi(ClientData.userInfo_accountPath(),
             "webGetContent",
             "GET",
             { contentId: contentId, sid: ClientData.userInfo_sid(), getType: 1 },
             function (data) {
                 
                 /* set end log */
                 COMMON.SetEndLog(contentID);
                 COMMON.RegisterLog();
                 
                 if(data.contentData.alertMessageLevel){                    
                     
                     if(data.contentData.alertMessageLevel == alertMessageLevel.ShowAlert){
                         if(data.contentData.alertMessage){                           
                            var oldContent = { oldContentID: contentID, oldPageIndex: getPageIndex() };
                            
                            moveContentParam = {};                          
                            moveContentParam = {
                                'preContentId' : contentId,
                                'prePageNo' : pageNo,
                                'oldContent' : oldContent
                            };   
                                                                                 
                            showContentConfirmDialog(data.contentData.alertMessageLevel, data.contentData.alertMessage);                                                                               
                         }
                     }
                     else if(data.contentData.alertMessageLevel == alertMessageLevel.RequirePassword){
                                                
                            var oldContent = { oldContentID: contentID, oldPageIndex: getPageIndex() };
                            
                            moveContentParam = {};                          
                            moveContentParam = {
                                'preContentId' : contentId,
                                'prePageNo' : pageNo,
                                'oldContent' : oldContent
                            };   
                                                 
                            showContentConfirmDialog(data.contentData.alertMessageLevel);
                     }
                     else if(data.contentData.alertMessageLevel == alertMessageLevel.None){
                            ClientData.common_preContentId(contentId);
                            ClientData.common_prePageNo(pageNo);
                
                            /* store old page */   
                            var oldContent = { oldContentID: contentID, oldPageIndex: getPageIndex() };                                   
                            var dataJump = ClientData.JumpQueue();                
                            dataJump.push(oldContent);               
                            ClientData.JumpQueue(dataJump);                                       
                            avwScreenMove(COMMON.ScreenIds.ContentView);
                     }
                 }
                 //Type 0
                 else{
                        ClientData.common_preContentId(contentId);
                        ClientData.common_prePageNo(pageNo);
                
                        /* store old page */   
                        var oldContent = { oldContentID: contentID, oldPageIndex: getPageIndex() };                                   
                        var dataJump = ClientData.JumpQueue();                
                        dataJump.push(oldContent);               
                        ClientData.JumpQueue(dataJump);  
                        avwScreenMove(COMMON.ScreenIds.ContentView);
                 }
                          
             },
             function (xmlHttpRequest, txtStatus, errorThrown) {
                 if (xmlHttpRequest.status == 404) {
                     showAlertScreen(I18N.i18nText('msgContentNotExist'));
                 }
                 else {
                     // Show system error
                     showSystemError();
                 }
             }
        );
        //END TRB00033 - EDITOR: Long - Date : 09/12/2013 - Summary : limit content                                     
    };
    
};
moveToContent.prototype = new PageObject();
//START TRB00033 - EDITOR: Long - Date : 09/12/2013 - Summary : limit content
var alertMessageLevel = {
    ShowAlert : '1',
    RequirePassword : '2',
    None : '0'  
};

function showContentConfirmDialog(type, msg) {  
    
    if(type == alertMessageLevel.ShowAlert){
        createAlertTypeDialog(msg);
        showDialog(true);
    }
    else if(type == alertMessageLevel.RequirePassword){
        createPwdRequiredTypeDialog();
        showDialog(true);
    }
};

function createAlertTypeDialog(msg){
    var $container = $('#dialog');
    $container.html('');
    $container.addClass('sectionLimitAccess');

    $container.draggable({ handle: "h1" });
    $container.html(
    '  <h1 class="lang" lang="txtContentWarning">'+ I18N.i18nText("txtContentWarning") +'</h1>'
    +'  <p class="message">'
    +       msg     
    +'  </p>'
    +'  <p class="deletebtn">'
    +'      <a lang="dspOK" class="ok lang" id="contentAlertOk">OK</a>'
    +'      <a lang="dspCancel" class="cancel lang" id="contentAlertCancel">キャンセル</a>'
    +'  </p>'
    );               
    $container.center(); 
    $('#dialog a#contentAlertCancel').click(function(){
        hideDialog();        
        var removeTimeOut = setTimeout(function(){
            $container.removeClass('sectionLimitAccess');
        }, 200);      
    });
    
    $('#dialog a#contentAlertOk').click(function(){
        
        ClientData.common_preContentId(moveContentParam.preContentId);
        ClientData.common_prePageNo(moveContentParam.prePageNo);
        
        /* store old page */                                      
        var dataJump = ClientData.JumpQueue();                
        dataJump.push(moveContentParam.oldContent);                      
        ClientData.JumpQueue(dataJump);                  
        avwScreenMove(COMMON.ScreenIds.ContentView);        
    });
};

function createPwdRequiredTypeDialog(){
    var $container = $('#dialog');
    $container.html('');
    $container.addClass('sectionLimitAccess');
    $container.draggable({ handle: "h1" });
    $container.html(
    '  <h1 class="lang" lang="txtContentPWTitle">'+ I18N.i18nText("txtContentPWTitle") +'</h1>'
    +' <p class="message">'
    +'  <label class="text lang" lang="txtContentPWMsg">'+ I18N.i18nText("txtContentPWMsg") +'</label>'
    +'      <input type="password" />'
    +'      <label class="error" id="lblMessageLimitError"></label> '  
    +'  </p>'
    +'  <p class="deletebtn">'
    +'      <a lang="dspOK" class="ok lang" id="contentAlertOk">OK</a>'
    +'      <a lang="dspCancel" class="cancel lang" id="contentAlertCancel">キャンセル</a>'
    +'  </p>'
    );           
    $container.center();       
    
    $('#dialog a#contentAlertCancel').click(function(){
        hideDialog();        
        var removeTimeOut = setTimeout(function(){
            $container.removeClass('sectionLimitAccess');
        }, 200);
        
    });

    
    $('#dialog a#contentAlertOk').click(
        function () {
            var password = $('.sectionLimitAccess .message input').val();
            if (!ValidationUtil.CheckRequiredForText(password)) {
                $('#lblMessageLimitError').html(I18N.i18nText('msgPwdEmpty')).show();
                return;
            }

            // start login
            var params = {
                previousSid: ClientData.userInfo_sid(),
                loginId: ClientData.userInfo_loginId_session(),
                password: password,
                urlpath: ClientData.userInfo_accountPath()
            };
            // Get url to login
            var sysSettings = avwSysSetting();
            var apiLoginUrl = sysSettings.apiLoginUrl;

            avwCmsApiSyncWithUrl(apiLoginUrl, null, 'webClientLogin', 'GET', params,
        function (data) {
            if (data.result == 'success') {                
                ClientData.common_preContentId(moveContentParam.preContentId);
                ClientData.common_prePageNo(moveContentParam.prePageNo);
                
                /* store old page */                                      
                var dataJump = ClientData.JumpQueue();                
                dataJump.push(moveContentParam.oldContent);                      
                ClientData.JumpQueue(dataJump);        
                
                
                // update sid id
                ClientData.userInfo_sid(data.sid);  
                        
                avwScreenMove(COMMON.ScreenIds.ContentView);                                         
            }
            else {
                $('#lblMessageLimitError').html(AVWEB.format(I18N.i18nText('msgLoginErrWrong'), data.errorMessage).toString()).show();
            }
        },
        function (xhr, statusText, errorThrown) {
            var errorCode = 'E001';
            if (xhr.responseText && xhr.status != 0) {
                errorCode = JSON.parse(xhr.responseText).errorMessage;
            }
            $('#lblMessageLimitError').html(AVWEB.format(I18N.i18nText('msgLoginErrWrong'), errorCode).toString()).show();
        });

        }
    );
};
//END TRB00033 - EDITOR: Long - Date : 09/12/2013 - Summary : limit content

/* mediaType=2  Video object : extends PageObject */
var videoType2 = function (mediaType, actionType, id, imageUrl, x, y, w, h, visible, mediaFile, media, embed, objectId) {

    this.setup(mediaType, actionType, id, imageUrl, x, y, w, h, visible, null, embed, objectId);
    this.action = function () {
    
        //abe
        //alert("videoType2:" + getPageIndex());
    
        //詳細ログ作成
        var objectLog = new ObjectLogEntity();
        objectLog.contentid = contentID;
        objectLog.pageNo = getPageIndex() + 1; //0始まりのページ番号
        objectLog.objectId = objectId;
        objectLog.resourceId = media; //mediaにリソースIDが入っている
        objectLog.mediaType = mediaType;
        objectLog.actionType = actionType;
        objectLog.actionValue = "";
        objectLog.actionTime = "1";
        objectLog.locationX = x;
        objectLog.locationY = y;
        objectLog.locationHeight = h;
        objectLog.locationWidth = w;
        COMMON.SetObjectLog(contentID, objectLog);
        //---
    
        /*stop audio on page */
        stopAllAudio();
        if (embed == "1") {
            showVideoObject(x, y, w, h, mediaFile, false);
        } 
        else {
            if (media != '') {
                $('#playvideo').children().remove();

                createVideoFulScreen(mediaFile, id);

                $("#btnCloseVideo").click(function (e) {
                
                    //時間記録
                    
                
                    hideDialog();
                    /*play audio if exist */
                    playAllAudio();
                    
                });

                showDialog(true);
            }
        }
    };
};
videoType2.prototype = new PageObject();

/* mediaType = 1 and actionType = 0 linkURL object*/
var imageNoAction = function (mediaType, actionType, id, imageUrl, x, y, w, h, visible, objectId) {
    this.setup(mediaType, actionType, id, imageUrl, x, y, w, h, visible, null, null, objectId);
    this.action = function () {
        //no action
    };
};
imageNoAction.prototype = new PageObject();

/* mediaType=1  Video object : extends PageObject */
var videoType1 = function (mediaType, actionType, id, imageUrl, x, y, w, h, visible, mediaFile, media, mediaResourceId, objectId) {
    this.setup(mediaType, actionType, id, imageUrl, x, y, w, h, visible, null, null, objectId);
    this.action = function () {
    
        if (media != '') {
        
            //abe
            //alert("videoType1:" + + getPageIndex());
            //詳細ログ作成
            var objectLog = new ObjectLogEntity();
            objectLog.contentid = contentID;
            objectLog.pageNo = getPageIndex() + 1; //0始まりのページ番号
            objectLog.objectId = objectId;
            objectLog.resourceId = mediaResourceId; //リソースID
            objectLog.mediaType = mediaType;
            objectLog.actionType = actionType;
            objectLog.actionValue = media; //リソースファイル名
            objectLog.actionTime = "1";
            objectLog.locationX = x;
            objectLog.locationY = y;
            objectLog.locationHeight = h;
            objectLog.locationWidth = w;
            COMMON.SetObjectLog(contentID, objectLog);
            //---
        
            /* stop all audio on page */
            stopAllAudio();

            createVideoFulScreen(mediaFile, id);

            $("#btnCloseVideo").click(function (e) {
            
                //時間記録
                var dateEnd = new Date();
                var actionTime = dateEnd.subtractBySeconds(dateStart);
                //alert("actionTime:" + actionTime);
                COMMON.SetObjectLogActionTime( contentID, objectId, actionTime );
            
                hideDialog();
                /* play audio  */
                playAllAudio();
            });

            showDialog(true);
            
        }
        
        //時間記録
        var dateStart = new Date();
        
    };
};
videoType1.prototype = new PageObject();

/* mediaType=1 and actionType = 2  Audio object : extends PageObject */
var audioType1 = function (mediaType, actionType, id, imageUrl, x, y, w, h, visible, audioFile, audio, audioResourceId, objectId) {
    this.setup(mediaType, actionType, id, imageUrl, x, y, w, h, visible, null, null, objectId);
    this.action = function () {
    
        //abe
        //alert("audioType1");
        //詳細ログ作成
        var objectLog = new ObjectLogEntity();
        objectLog.contentid = contentID;
        objectLog.pageNo = getPageIndex() + 1; //0始まりのページ番号
        objectLog.objectId = objectId;
        objectLog.resourceId = audioResourceId; //リソースID
        objectLog.mediaType = mediaType;
        objectLog.actionType = actionType;
        objectLog.actionValue = audio;
        objectLog.actionTime = "1";
        objectLog.locationX = x;
        objectLog.locationY = y;
        objectLog.locationHeight = h;
        objectLog.locationWidth = w;
        COMMON.SetObjectLog(contentID, objectLog);
        //---
    
        createAudio(audioFile, "0")
    };
};
audioType1.prototype = new PageObject();

/* mediaType = 1 and actionType = 3 linkURL object*/
var linkURL = function (mediaType, actionType, id, imageUrl, x, y, w, h, visible, actionFunction, linkUrl, browserType, objectId) {
    this.setup(mediaType, actionType, id, imageUrl, x, y, w, h, visible, actionFunction, null, objectId);
    this.action = function () {
    
        //abe
        //alert("linkURL");
        
        //詳細ログ作成
        var objectLog = new ObjectLogEntity();
        objectLog.contentid = contentID;
        objectLog.pageNo = getPageIndex() + 1; //0始まりのページ番号
        objectLog.objectId = objectId;
        objectLog.resourceId = "";
        objectLog.mediaType = mediaType;
        objectLog.actionType = actionType;
        objectLog.actionValue = linkUrl;
        objectLog.actionTime = "0";
        objectLog.locationX = x;
        objectLog.locationY = y;
        objectLog.locationHeight = h;
        objectLog.locationWidth = w;
        COMMON.SetObjectLog(contentID, objectLog);
        //---
        
        var linkUrlTmp = linkUrl;
        //DHカスタム
        if( ClientData.serviceOpt_daihatsu() == 'Y'){
            var apiUrl = AVWEB.getApiUrl(ClientData.userInfo_accountPath());
            linkUrlTmp = linkUrlTmp + "?sid=" + ClientData.userInfo_sid() + "&apiurl=" + apiUrl ;
        }
        
        if( browserType == 0 ){
            showHtml(linkUrlTmp, objectId );
            showDialog(true);
        } else {
            window.open(linkUrlTmp, "_blank", "new window, scrollbars=yes");
        }
        
    };
};
linkURL.prototype = new PageObject();

/* mediaType = 1 and actionType = 4 imagePreview object*/
var imagePreview = function (mediaType, actionType, id, imageUrl, x, y, w, h, visible, imagePreview, imagePreviewResourceIds, objectId) {
    this.setup(mediaType, actionType, id, imageUrl, x, y, w, h, visible, null, null, objectId);
    this.action = function () {

        //abe
        //alert("imagePreview");
        //詳細ログ作成
        var objectLog = new ObjectLogEntity();
        objectLog.contentid = contentID;
        objectLog.pageNo = getPageIndex() + 1; //0始まりのページ番号
        objectLog.objectId = objectId;
        objectLog.resourceId = "";
        objectLog.mediaType = mediaType;
        objectLog.actionType = actionType;
        //objectLog.actionValue = "";
        objectLog.actionTime = "0";
        objectLog.locationX = x;
        objectLog.locationY = y;
        objectLog.locationHeight = h;
        objectLog.locationWidth = w;
        
        //プレビュー画像のリソースIDカンマ区切りでセット
        var actionVal = "";
        if(imagePreviewResourceIds){
            for (var nIndex = 0; nIndex < imagePreviewResourceIds.length; nIndex++) {
                if( nIndex > 0 ){
                    actionVal = actionVal + ",";
                }
                actionVal = actionVal + imagePreviewResourceIds[nIndex];
            }
        }
        objectLog.actionValue = actionVal;
        
        COMMON.SetObjectLog(contentID, objectLog);
        //---

        createImagePreview();

        showImagePreview($('#divImagePreview'), imagePreview);

        $("#btnClose").live('click', function (e) {
        
            //時間記録
            var dateEnd = new Date();
            var actionTime = dateEnd.subtractBySeconds(dateStart);
            //alert("actionTime:" + actionTime);
            COMMON.SetObjectLogActionTime( contentID, objectId, actionTime );
        
            hideDialog();
        });

        showDialog(true);
        
        //時間記録
        var dateStart = new Date();
        
    };
};
imagePreview.prototype = new PageObject();

/* rect object */
var Rect = function (x, y, w, h) {
    this.left = Math.floor(x);
    this.top = Math.floor(y);
    this.right = Math.floor(x + w);
    this.bottom = Math.floor(y + h);
    this.width = w;
    this.height = h;
};
Rect.prototype.add = function (x, y) {
    this.left = Math.floor(this.left + x);
    this.right = Math.floor(this.right + x);
    this.top = Math.floor(this.top + y);
    this.bottom = Math.floor(this.bottom + y);
    this.width = this.right - this.left;
    this.height = this.bottom - this.top;
};
Rect.prototype.center = function () {
    var x = (this.left + this.right) / 2;
    var y = (this.top + this.bottom) / 2;
    return new Point(Math.floor(x), Math.floor(y));
};

/**
* Content Class Definition 
*/
var Content = function () {

    this.pageCount = 0;
    this.pageIndex = 0;
    this.pageImages = null;
    this.pageObjects = null;
    this.currentPage = null;

};

/* ste page images (json data) */
Content.prototype.setPageImages = function (pageCount, imageUrls) {
    this.pageCount = pageCount;
    this.pageImages = imageUrls;
    return this;
};

/* set page objects data (json data) */
Content.prototype.setPageObjects = function (pageObjects) {
    this.pageObjects = pageObjects;
    return this;
};

/* Set up page */
Content.prototype.setUpPage = function (pageIndex, opt) {

    this.currentPage = createPage(
                            this.pageIndex,
                            this.pageImages,
                            this.pageObjects,
                            function () {
                                adjustPage(opt);
                            });
    return this;
};

/* check next page exists */
Content.prototype.hasNextPage = function () {

    if ((this.pageIndex + 1) > (this.pageCount - 1)) {
        return false;
    }
    return true;
};

/* setup next page */
Content.prototype.nextPage = function () {
    this.pageIndex++;
    if (this.pageIndex > (this.pageCount - 1)) {
        
        this.pageIndex = this.pageCount - 1;
    }
    this.setUpPage(this.pageIndex, 1);
    return this;
};

/* check previous page exists */
Content.prototype.hasPreviousPage = function () {
    if ((this.pageIndex - 1) < 0) {
        return false;
    }
    return true;
};

/* setup previous page */
Content.prototype.previousPage = function () {
    this.pageIndex--;
    if (this.pageIndex < 0) {
        this.pageIndex = 0;
    }
    this.setUpPage(this.pageIndex, 2);
    return this;
};

/* setup previous page */
Content.prototype.toPage = function (index) {
    this.pageIndex = eval(index);
    if (this.pageIndex < 0) {
        this.pageIndex = 0;
    }
    this.setUpPage(this.pageIndex);
    
    //START : TRB00028 - Editor: Long - Date: 09/10/2013 - Summary : Fix For Page BGM
    createPageBGM();
    //END : TRB00028 - Editor: Long - Date: 09/10/2013 - Summary : Fix For Page BGM
    return this;
};

/**
* Transition Class Definition 
*/
var Transition = function () { };

//Start Functon : No.4 - Editor : Long - Date : 08/09/2013 - Summary : 
/* Flip Next Page Transition */
Transition.prototype.flipNextPage = function () {
    
    //#12373
    var tmpScale = 1;
    
    var w = $('#canvasWrapper').width();
    removeObject();
    if(animateType == animateTypeKeys.Type_FadeIn){
        $('#mainNext').css('left', marginX + 'px');
        $('#mainNext').css('display', 'block');
        $('#main').css('z-index', '1');
    }
    else{
        $('#mainNext').css('display', 'block');
    }
         
    if (getContent().hasNextPage()) {
       
       tmpScale = userScale;
       userScale = 1;
       flip(1);
       
       if(animateType == animateTypeKeys.Type_Slide){
           $('#canvasWrapper').stop(true).animate(
                { left: '-' + w + 'px' },
                {
                    duration: animatePeriod,
                    complete: function () {                                                                                                                            
                        
                        assignCurrentContentPage(1);
                        
                        //Change id of canvas
                        switchCanvas(1);
                        
                        //restore canvas event
                        setDefaultEvent();
                        
                        //init image bookmark                       
                        initImageBookmark();
                                                                        
                        //Change slider
                        changeSlider(getContent().pageIndex);
                        
                        //Draw marking on current screen
                        //drawMarkingOnScreen();                                            
                        
                        //Correct position of canvas for next flipping
                        correctCanvasPosition();
                       
                       //START : TRB00028 - Editor: Long - Date: 09/10/2013 - Summary : Fix For Page BGM
                       createPageBGM();
                       //END : TRB00028 - Editor: Long - Date: 09/10/2013 - Summary : Fix For Page BGM                             
                        if(getPageIndex() < totalPage - 1){
                            
                            //Get Next Page Object
                            getNextPageObjectsByPageIndex(pageObjectsData, getPageIndex() + 1);
                                                        
                            //Load Next
                            renderNextPage();                                     
                            
                        }else{
                            //Enable all control
                            enableAllControl(); 
                            $('#divImageLoading').css('display', 'none');
                            isLoadingObject = false;
                        }                                                 
                                                                                                        
                        /* init image had draw */
                        initDisplayMarking();
                        
                        /* change title of page */
                        if (dataPageTitle[getContent().pageIndex]) {
                            if (dataPageTitle[getContent().pageIndex] != '') {
                                document.title = contentName + '_' + dataPageTitle[getContent().pageIndex] + ' | ' + I18N.i18nText('sysAppTitle');
                            } else {
                                document.title = contentName + ' | ' + I18N.i18nText('sysAppTitle');
                            }
                        } else {
                            document.title = contentName + ' | ' + I18N.i18nText('sysAppTitle');
                        }
                        /* set end log */
                        COMMON.SetEndLog(contentID);
                        createLockLayout(false);
                        initImageCheckMarking();
                        
                        //#12373
                        //console.log("tmpScale:" + tmpScale);
                        if (tmpScale != 1) {
                            userScale = tmpScale;
                            changeScale(userScale);
                            flip();
                            checkDisableButtonZoom();
                        }
                        
                    }
                });
       }
       else if(animateType == animateTypeKeys.Type_FadeIn){
           $('#main').stop(true).fadeOut(
                {                   
                    duration: animatePeriod,
                    complete: function () {                                                                                                                            
                              
                        assignCurrentContentPage(1);
                                                                                    
                        //Change id of canvas
                        switchCanvas(1);
                        
                        //restore canvas event
                        setDefaultEvent();
                        
                        //init image bookmark                       
                        initImageBookmark();
                                                                        
                        //Change slider
                        changeSlider(getContent().pageIndex);
                        
                        //Draw marking on current screen
                        //drawMarkingOnScreen();                                            
                        
                        //Correct position of canvas for next flipping
                        correctCanvasPosition();
                                        
                                        
                        if(getPageIndex() < totalPage - 1){
                            
                            //Get Next Page Object
                            getNextPageObjectsByPageIndex(pageObjectsData, getPageIndex() + 1);
                                                        
                            //Load Next
                            renderNextPage();
                                         
                        }
                        else{
                            //Enable all control
                            enableAllControl(); 
                            $('#divImageLoading').css('display', 'none');
                            isLoadingObject = false;
                        }                                                
                                 
                        /* init image had draw */
                        initDisplayMarking();
                                      
                        /* change title of page */
                        if (dataPageTitle[getContent().pageIndex]) {
                            if (dataPageTitle[getContent().pageIndex] != '') {
                                document.title = contentName + '_' + dataPageTitle[getContent().pageIndex] + ' | ' + I18N.i18nText('sysAppTitle');
                            } else {
                                document.title = contentName + ' | ' + I18N.i18nText('sysAppTitle');
                            }
                        } else {
                            document.title = contentName + ' | ' + I18N.i18nText('sysAppTitle');
                        }
                        /* set end log */
                        COMMON.SetEndLog(contentID);
                        createLockLayout(false);
                        initImageCheckMarking();
                    }
                });
        }
        initImageCheckMarking();          
    }
};
/* Flip Previous Page Transition */
Transition.prototype.flipPreviousPage = function () {

    //#12373
    var tmpScale = 1;

    var w = $('#canvasWrapper').width();
    removeObject();
    if(animateType == animateTypeKeys.Type_FadeIn){
        $('#mainPre').css('left', marginX + 'px');
        $('#mainPre').css('display', 'block');
        $('#main').css('z-index', '1');
    }
    else{
        $('#mainPre').css('display', 'block');
    }
    if (getContent().hasPreviousPage()) {
    
        tmpScale = userScale;
        userScale = 1;
        flip(2);
    
        if(animateType == animateTypeKeys.Type_Slide){
            $('#canvasWrapper').stop(true).animate(
                { left: w + 'px' },
                {
                    duration: animatePeriod,
                    complete: function () {                                                                                                                            
                              
                        assignCurrentContentPage(2);
                                                                                    
                        //Change id of canvas
                        switchCanvas(2);
                        
                        //restore canvas event
                        setDefaultEvent();
                        
                        //init image bookmark                       
                        initImageBookmark();
                                                                        
                        //Change slider
                        changeSlider(getContent().pageIndex);
                        
                        //Draw marking on current screen
                        //drawMarkingOnScreen();                                            
                        
                        //Correct position of canvas for next flipping
                        correctCanvasPosition();
                        
                        //START : TRB00028 - Editor: Long - Date: 09/10/2013 - Summary : Fix For Page BGM              
                        createPageBGM();
                        //END : TRB00028 - Editor: Long - Date: 09/10/2013 - Summary : Fix For Page BGM
                        if(getPageIndex() > 0){
                            
                            //Get Next Page Object
                            getPrevPageObjectsByPageIndex(pageObjectsData, getPageIndex() - 1);
                                                        
                            //Load Next
                            renderPrevPage();
                        }else{
                            //Enable all control
                            enableAllControl(); 
                            $('#divImageLoading').css('display', 'none');
                            isLoadingObject = false;
                        }                                                                            
                               
                        /* init image had draw */
                        initDisplayMarking();
                        /* change title of page */
                        if (dataPageTitle[getContent().pageIndex]) {
                            if (dataPageTitle[getContent().pageIndex] != '') {
                                document.title = contentName + '_' + dataPageTitle[getContent().pageIndex] + ' | ' + I18N.i18nText('sysAppTitle');
                            } else {
                                document.title = contentName + ' | ' + I18N.i18nText('sysAppTitle');
                            }
                        } else {
                            document.title = contentName + ' | ' + I18N.i18nText('sysAppTitle');
                        }
                        /* set end log */
                        COMMON.SetEndLog(contentID);
                        createLockLayout(false);
                        initImageCheckMarking();
                        
                        //#12373
                        //console.log("tmpScale:" + tmpScale);
                        if (tmpScale != 1) {
                            userScale = tmpScale;
                            changeScale(userScale);
                            flip();
                            checkDisableButtonZoom();
                        }
                        
                        
                    }
                });
        }
        else{
            $('#main').stop(true).fadeOut(
                {
                    duration: animatePeriod,
                    complete: function () {                                                                                                                            
                              
                        assignCurrentContentPage(2);
                                                                                    
                        //Change id of canvas
                        switchCanvas(2);
                        
                        //restore canvas event
                        setDefaultEvent();
                        
                        //init image bookmark                       
                        initImageBookmark();
                                                                        
                        //Change slider
                        changeSlider(getContent().pageIndex);
                        
                        //Draw marking on current screen
                        //drawMarkingOnScreen();                                            
                        
                        //Correct position of canvas for next flipping
                        correctCanvasPosition();
                                        
                                        
                        if(getPageIndex() > 0){
                            
                            //Get Next Page Object
                            getPrevPageObjectsByPageIndex(pageObjectsData, getPageIndex() - 1);
                                                        
                            //Load Next
                            renderPrevPage();
                        }else{
                            //Enable all control
                            enableAllControl(); 
                            $('#divImageLoading').css('display', 'none');
                            isLoadingObject = false;
                        }                                                                        
                                                       
                        /* init image had draw */
                        initDisplayMarking();
     
                        /* change title of page */
                        if (dataPageTitle[getContent().pageIndex]) {
                            if (dataPageTitle[getContent().pageIndex] != '') {
                                document.title = contentName + '_' + dataPageTitle[getContent().pageIndex] + ' | ' + I18N.i18nText('sysAppTitle');
                            } else {
                                document.title = contentName + ' | ' + I18N.i18nText('sysAppTitle');
                            }
                        } else {
                            document.title = contentName + ' | ' + I18N.i18nText('sysAppTitle');
                        }
                        /* set end log */
                        COMMON.SetEndLog(contentID);
                        createLockLayout(false);
                        initImageCheckMarking();
                    }
                });
        }
        
    }
};
//Start Functon : No.4 - Editor : Long - Date : 08/09/2013 - Summary : 
/* Flip  Page Transition */
Transition.prototype.flipToPage = function (index) {

    //#12373
    var tmpScale = userScale;

    var w = $('#main').attr('width');
    
    if (index == getContent().pageIndex) {
        /* init image had draw */
        initDisplayMarking();       
    } else if (index < getContent().pageIndex) {
        context_main.clearRect(0, 0, canvas_main.width, canvas_main.height);
        removeObject();
        $('#main').animate(
                { left: w + 'px' },
                {
                    duration: animatePeriod,
                    complete: function () {
                        $('#main').css('left', -w + 'px');
                        $('#main').animate(
                            { left: marginX + 'px' },
                            { duration: animatePeriod,
                                complete: function () {
                                    isFirstLoad = true;
                                    //screenFit();
                                }
                            });
                        //change pageIndex and image bookmark
                        userScale = 1;
                        userScaleNow = 1;
                        //START TRB00097
                        //changeScale(userScale);   
                        srcRect = new Rect(0, 0, 0, 0);
                        srcRectNext = new Rect(0, 0, 0, 0);
                        srcRectPrev = new Rect(0, 0, 0, 0);
                        
                        destRect = new Rect(0, 0, 0, 0);
                        destRectNext = new Rect(0, 0, 0, 0);
                        destRectPrev = new Rect(0, 0, 0, 0);
                        
                        //END TRB00097                  
                        checkDisableButtonZoom();
                        getContent().toPage(index);                      
                        
                        if(index > 0){
                            prevContent.pageIndex = getPageIndex();
                            getPrevPageObjectsByPageIndex(pageObjectsData, index - 1);               
                            renderPrevPage();
            
                        }
                        
                        if(index < totalPage - 1){
                            nextContent.pageIndex = getPageIndex();
                            getNextPageObjectsByPageIndex(pageObjectsData, index + 1);
                            renderNextPage();
                        }
                    
                        initImageBookmark();
                        checkExistNextPrePage();
                        changeSlider(index);
                        /* init image had draw */
                        initDisplayMarking();
                        /* change title of page */
                        if (dataPageTitle[index]) {                         
                            if (dataPageTitle[index] != '') {
                                document.title = contentName + '_' + dataPageTitle[index] + ' | ' + I18N.i18nText('sysAppTitle');
                            } else {
                                document.title = contentName + ' | ' + I18N.i18nText('sysAppTitle');
                            }
                        } else {
                            document.title = contentName + ' | ' + I18N.i18nText('sysAppTitle');
                        }
                        /* set end log */
                        COMMON.SetEndLog(contentID);
                        initImageCheckMarking();
                        
                        createLockLayout(false);
                        
                        //#12373
                        //console.log("tmpScale:" + tmpScale);
                        if (tmpScale != 1) {
                            userScale = tmpScale;
                            changeScale(userScale);
                            flip();
                        }
                        
                    }
                }
             );
    } 
    else {
        context_main.clearRect(0, 0, canvas_main.width, canvas_main.height);
        removeObject();
        $('#main').animate(
                { left: '-' + w + 'px' },
                {
                    duration: animatePeriod,
                    complete: function () {
                        $('#main').css('left', w + 'px');
                        $('#main').animate(
                            { left: marginX + 'px' },
                            { duration: animatePeriod,
                                complete: function () {
                                    isFirstLoad = true;
                                    //screenFit();
                                }
                            });
                        //change pageIndex and image bookmark
                        userScale = 1;
                        //START TRB00097
                        //changeScale(userScale);   
                        srcRect = new Rect(0, 0, 0, 0);
                        srcRectNext = new Rect(0, 0, 0, 0);
                        srcRectPrev = new Rect(0, 0, 0, 0);
                        
                        destRect = new Rect(0, 0, 0, 0);
                        destRectNext = new Rect(0, 0, 0, 0);
                        destRectPrev = new Rect(0, 0, 0, 0);
                        
                        //END TRB00097  
                        checkDisableButtonZoom();
                        getContent().toPage(index);    
                        
                        if(index > 0){
                            prevContent.pageIndex = getPageIndex();
                            getPrevPageObjectsByPageIndex(pageObjectsData, index - 1);                
                            renderPrevPage();
            
                        }
                        
                        if(index < totalPage - 1){
                            nextContent.pageIndex = getPageIndex();
                            getNextPageObjectsByPageIndex(pageObjectsData, index + 1);
                            renderNextPage();
                        }

                        initImageBookmark();
                        checkExistNextPrePage();
                        changeSlider(index);
                        /* init image had draw */
                        initDisplayMarking();
                        /* change title of page */
                        if (dataPageTitle[index]) {
                            if (dataPageTitle[index] != '') {
                                document.title = contentName + '_' + dataPageTitle[index] + ' | ' + I18N.i18nText('sysAppTitle');
                            } else {
                                document.title = contentName + ' | ' + I18N.i18nText('sysAppTitle');
                            }
                        } else {
                            document.title = contentName + ' | ' + I18N.i18nText('sysAppTitle');
                        }
                        /* set end log */
                        COMMON.SetEndLog(contentID);
                        initImageCheckMarking();
                        
                        createLockLayout(false);
                        
                        //#12373
                        //console.log("tmpScale:" + tmpScale);
                        if (tmpScale != 1) {
                            userScale = tmpScale;
                            changeScale(userScale);
                            flip();
                        }
                        
                    }
                });
    }   
    
};

function createTextConfirmAudio() {
    var text = I18N.i18nText('msgBGMPlayConfirm');
    $('#txtAudio').html(text);

    var text = I18N.i18nText('msgBGMPagePlayConfirm');
    $('#txtAudio_page').html(text);
};

/* create page */
function createPage(pageNumber, pageImage, pageObjects, onCompleteFunc) {

	//abe 次のページを作成している
	//alert("CreateObj_createPage:" + pageNumber);

    var page = new ContentPage(pageNumber, pageImage);
    /* add page Object */
    //Start Function: No.12
    if (contentType == COMMON.ContentTypeKeys.Type_PDF || contentType == COMMON.ContentTypeKeys.Type_NoFile) {
        page.addPageObjects(pageObjects);
    }
    //End Function: No.12
    /* load page */
    page.load(onCompleteFunc);

    return page;
};

function createImagePreview() {
    $('#dialog').prepend(
        '<h1>' +
        '<img src="img/viewer/x.png" style="margin:3px 3px 0px 21px" id="btnClose" class="align_right" ></img>' +
        '</h1>' +
        '<div id="divImagePreview" class="content_image_preview">' +
        '</div>'
    );
    $('#dialog').css('box-shadow', '0px 0px 3px 1px #666');
    $('#dialog').css('border', 'solid 1px #666');

    $('#dialog').draggable({ handle: "h1" });
};

/* create video on page */
function createVideoFulScreen(video, id) {
    $('#dialog').css('box-shadow', '0px 0px 3px 1px #666');
    $('#dialog').css('border', 'solid 1px #666');
    $('#dialog').draggable({ handle: "h1" });

    $('#dialog').children().remove();
    if (ClientData.userOpt_videoMode() == "1") {/* loop video */
        $('#dialog').html(
            '<h1>' +
            '   <img src="img/viewer/x.png" style="margin:3px 3px 0px 21px" id="btnCloseVideo" class="align_right" ></img>' +
            '</h1>' +
            '       <div id="videoMedia' + id + '">' +
            '           <video style="height:90%; width:100%;" class="mov" id="videoOnPopUp" autoplay controls loop>' +
            '            <source src="' + video + '" type="video/mp4"> ' +
            '    </video>' +
            '       </div>'
            );
    } else {
        $('#dialog').html(
            '<h1>' +
            '   <img src="img/viewer/x.png" style="margin:3px 3px 0px 21px" id="btnCloseVideo" class="align_right" width=25px" ></img>' +
            '</h1>' +
            '       <div id="videoMedia' + id + '">' +
            '           <video style="height:90%; width:100%;" id="videoOnPopUp" class="mov" autoplay controls>' +
            '            <source src="' + video + '" type="video/mp4"> ' +
            '    </video>' +
            '       </div>'
            );
    }
    $('#videoOnPopUp').css('height', ($('#dialog').height() - 25) + "px");
    //showControlsVideo($('#videoOnPopUp'));
};

/* create audio on page */
function createAudio(audio, type) {
    // if(avwUserEnvObj.browser == 'firefox'){
    // audio =  audio.replace("webResourceDownload/", "webResourceDownload");
    // }

    if (audio != '') {
        if (type == "0") { /* play when click */
            stopAllAudio();

            TypeAudio0 = type;
            srcAudioType0 = audio;

            if (ClientData.userOpt_musicMode() == "1") {
                if (avwUserEnvObj.browser == 'firefox') {
                    $('#playaudio').html(
                        '    <embed id="play_audio_0" src="' + audio + '&key=' + (new Date()).toIdString() + '" autostart="true" loop="true" hidden="true"> </embed>'
                    );
                } else if (avwUserEnvObj.os == "ipad") {
                    $('#playaudio').html(
                        '   <audio  id="play_audio_0" loop="loop"  >' +
                        '        <source src="' + audio + '&key=' + (new Date()).toIdString() + '" type="audio/mpeg" />' +
                        '   </audio>'
                        );
                } else {
                    $('#playaudio').html(
                        '   <audio  id="play_audio_0" loop="loop"  autoplay ="autoplay">' +
                        '        <source src="' + audio + '&key=' + (new Date()).toIdString() + '" type="audio/mpeg" />' +
                        '   </audio>'
                    );
                }

            } else {
                if (avwUserEnvObj.browser == 'firefox') {
                    $('#playaudio').html(
                        '    <embed id="play_audio_0" src="' + audio + '&key=' + (new Date()).toIdString() + '" autostart="true" hidden="true"> </embed>'
                    );
                } else if (avwUserEnvObj.os == "ipad") {
                    $('#playaudio').html(
                        '   <audio  id="play_audio_0">' +
                        '        <source src="' + audio + '&key=' + (new Date()).toIdString() + '" type="audio/mpeg" />' +
                        '   </audio>'
                        );
                } else {
                    $('#playaudio').html(
                        '   <audio  id="play_audio_0" autoplay ="autoplay">' +
                        '        <source src="' + audio + '&key=' + (new Date()).toIdString() + '" type="audio/mpeg" />' +
                        '   </audio>'
                    );
                }

            }

            if (avwUserEnvObj.os == "ipad") {
                document.getElementById("play_audio_0").load();
                document.getElementById("play_audio_0").play();
            }

        } 
        else if (type == "1") { /* play all page */        
           
            if (document.getElementById("play_audio_1") != undefined) {

                if (ClientData.userOpt_musicMode() == "1") {
                    if (avwUserEnvObj.browser == 'firefox') {
                        /*
                        $('#playaudioallpage').html(
                                                    '    <embed id="play_audio_1" src="' + audio + '&key=' + (new Date()).toIdString() + '" autostart="true" loop="true"  hidden="true"> </embed>'
                                                );*/
                        
                    } 
                    else {
                        if(!isPendingContentBGM){
                            document.getElementById("play_audio_1").play();
                        }                       
                    }
                }
                else {
                    if (avwUserEnvObj.browser == 'firefox') {
/*
                        $('#playaudioallpage').html(
                            '    <embed id="play_audio_1" src="' + audio + '&key=' + (new Date()).toIdString() + '" autostart="true" hidden="true"> </embed>'
                        );*/

                    } else {
                        if(!isPendingContentBGM){
                            document.getElementById("play_audio_1").play();
                        }
                    }
                }
            } 
            else {
                TypeAudio1 = type;
                srcAudioType1 = audio;

                if (ClientData.userOpt_musicMode() == "1") {                                        
                    if (avwUserEnvObj.browser == 'firefox') {
                        $('#playaudioallpage').html(
                            '    <embed id="play_audio_1" src="' + audio + '&key=' + (new Date()).toIdString() + '" autostart="true" loop="true"  hidden="true"> </embed>'
                        );

                    } 
                    else if (avwUserEnvObj.os == "ipad") {
                        $('#playaudioallpage').html(
                             '  <audio  id="play_audio_1" loop="loop" >' +
                             '       <source src="' + audio + '&key=' + (new Date()).toIdString() + '" type="audio/mpeg" />' +
                             '  </audio>'
                         );
                    }
                    else {                      
                        if(isPendingContentBGM){
                            $('#playaudioallpage').html(
                                 '  <audio  id="play_audio_1" loop="loop" >' +
                                 '       <source src="' + audio + '&key=' + (new Date()).toIdString() + '" type="audio/mpeg" />' +
                                 '  </audio>'
                             );
                             document.getElementById('play_audio_1').load();
                             isPendingContentBGM = false;
                             
                        }
                        else{
                            $('#playaudioallpage').html(
                                 '  <audio  id="play_audio_1" loop="loop" autoplay="autoplay" >' +
                                 '       <source src="' + audio + '&key=' + (new Date()).toIdString() + '" type="audio/mpeg" />' +
                                 '  </audio>'
                             );
                        }
                    }
                }
                else {
                    if (avwUserEnvObj.browser == 'firefox') {
                        $('#playaudioallpage').html(
                            '    <embed id="play_audio_1" src="' + audio + '&key=' + (new Date()).toIdString() + '" autostart="true" hidden="true"> </embed>'
                        );
                    } else if (avwUserEnvObj.os == "ipad") {
                        $('#playaudioallpage').html(
                             '  <audio  id="play_audio_1" >' +
                             '       <source src="' + audio + '&key=' + (new Date()).toIdString() + '" type="audio/mpeg" />' +
                             '  </audio>'
                         );
                    } else {
                        if(isPendingContentBGM){
                            $('#playaudioallpage').html(
                                 '  <audio  id="play_audio_1" >' +
                                 '       <source src="' + audio + '&key=' + (new Date()).toIdString() + '" type="audio/mpeg" />' +
                                 '  </audio>'
                             );
                             document.getElementById('play_audio_1').load();
                             isPendingContentBGM = false;
                             
                        }
                        else{
                            $('#playaudioallpage').html(
                                 '  <audio  id="play_audio_1" autoplay="autoplay" >' +
                                 '       <source src="' + audio + '&key=' + (new Date()).toIdString() + '" type="audio/mpeg" />' +
                                 '  </audio>'
                             );
                        }
                    }
                }
                // Check to play BGM on ipad
                if (avwUserEnvObj.os == "ipad") {
                    //START TRB00069
                    if(isPendingContentBGM){
                        document.getElementById('play_audio_1').load();
                        isPendingContentBGM = false;
                    }
                    else{
                        // Show confim message to play background music
                        $("#bgmConfirm_dspCancel").unbind('click');
                        $("#bgmConfirm_dspCancel").click(function () {
                            $("#bgmConfirm").hide();
                        });
                        $("#bgmConfirm_dspOK").unbind('click');
                        $("#bgmConfirm_dspOK").click(function () {
                            document.getElementById('play_audio_1').load();
                            document.getElementById('play_audio_1').play();
                            $("#bgmConfirm").hide();
                        });
                        $("#bgmConfirm").show();
                        $("#bgmConfirm").center();
                    }
                    //END TRB00069
                }
            }
        }
        else if (type == "2") { /* play on page */                    
           
            if (document.getElementById("play_audio_2") == undefined) {
                stopAllAudio();

                TypeAudio2 = type;
                srcAudioType2 = audio;

                if (ClientData.userOpt_musicMode() == "1") {
                    if (avwUserEnvObj.browser == 'firefox') {
                        $('#playaudiopage').html(
                                '    <embed id="play_audio_2" src="' + audio + '&key=' + (new Date()).toIdString() + '" autostart="true" loop="true" hidden="true"> </embed>'
                            );
                    } else if (avwUserEnvObj.os == "ipad") {
                        $('#playaudiopage').html(
                            '   <audio  id="play_audio_2" loop="loop" >' +
                            '        <source src="' + audio + '&key=' + (new Date()).toIdString() + '" type="audio/mpeg" />' +
                            '   </audio>'
                        );
                    } else {
                        $('#playaudiopage').html(
                            '   <audio  id="play_audio_2" loop="loop" autoplay ="autoplay">' +
                            '        <source src="' + audio + '&key=' + (new Date()).toIdString() + '" type="audio/mpeg" />' +
                            '   </audio>'
                        );
                    }
                } else {
                    if (avwUserEnvObj.browser == 'firefox') {
                        $('#playaudiopage').html(
                                '    <embed id="play_audio_2" src="' + audio + '&key=' + (new Date()).toIdString() + '" autostart="true" hidden="true"> </embed>'
                            );
                    } else if (avwUserEnvObj.os == "ipad") {
                        $('#playaudiopage').html(
                            '   <audio  id="play_audio_2" >' +
                            '        <source src="' + audio + '&key=' + (new Date()).toIdString() + '" type="audio/mpeg" />' +
                            '   </audio>'
                        );
                    } else {
                        $('#playaudiopage').html(
                            '   <audio  id="play_audio_2" autoplay ="autoplay">' +
                            '        <source src="' + audio + '&key=' + (new Date()).toIdString() + '" type="audio/mpeg" />' +
                            '   </audio>'
                        );
                    }
                }

                // Check to play BGM on ipad
                if (avwUserEnvObj.os == "ipad") {
                    // Show confim message to play background music
                    $("#bgmConfirm_dspCancel_page").unbind('click');
                    $("#bgmConfirm_dspCancel_page").click(function () {
                        $("#bgmConfirm_page").hide();
                    });
                    $("#bgmConfirm_dspOK_page").unbind('click');
                    $("#bgmConfirm_dspOK_page").click(function () {
                        document.getElementById('play_audio_2').load();
                        document.getElementById('play_audio_2').play();
                        $("#bgmConfirm_page").hide();
                    });
                    $("#bgmConfirm_page").show();
                    $("#bgmConfirm_page").center();
                }
            }
        }
    }
    else {
        stopAllAudio();
    }

};

//START : TRB00028 - Editor: Long - Date: 09/10/2013 - Summary : Fix For Page BGM
function createPageBGM(){
    
    var currentPageObject = getContent().pageObjects;
    var audioFile  = '';
    var playType = '';
    $('#playaudiopage').html('');
    for(var i = 0; i < currentPageObject.length; i++){
        var BGMObject = currentPageObject[i];
        
        if(BGMObject.mediaType == '3' && BGMObject.actionType=='2' && BGMObject.playType == '2'){           
            
            audioFile = BGMObject.audioFile;
            playType = BGMObject.playType;
            
            createAudio(audioFile, playType);
            
            break;
        }
    }                
};
//END : TRB00028 - Editor: Long - Date: 09/10/2013 - Summary : Fix For Page BGM