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

// show dialog anket content
CONTENTVIEW_ANKET.showAnket = function(url, fullscreen, objectId) {
    var $container = $('#dialog');

    //url = url + "?sid=" + CONTENTVIEW.getSessionId();

    $container.html('');
    $container.addClass('anket-dialog');

    var canvas = document.getElementById('main');

    var width = fullscreen == true ? canvas.width : 340;

    if (fullscreen == true) {
        $container.attr('style', 'width:' + width + 'px; left:10px;right:auto;');
    }
    else {
        $container.attr('style', 'width:' + width + 'px; right:10px;left:auto;'); // !important
    }

    $container.draggable({ handle: "h1" });
    $container.html(
      '<h1>'+I18N.i18nText('txtEnqueteTitle')
    + '<img src="img/viewer/x.png" style="margin:3px 3px 0px 21px" id="btnClose" class="align_right" ></img>'
    + '</h1>'
    + '<div class="anket-container" id="anket-container"><iframe width="' + width + '" height="100%" frameborder="0" scrolling="auto" src="' + url + '">'
    + '</iframe></div>'
    + '<div class="anket-commands" id="anket-commands"><input type="button" value="' + I18N.i18nText('txtTransparent') + '" id="btnFullOpacity"/> <input type="button" value="' + I18N.i18nText('txtSemiTransparent') + '" id="btnApartOpacity"/> <input type="button" value="' + I18N.i18nText('txtNoTransparent') + '" id="btnNoOpacity"/></div><div style="clear:both;"></div>'
    );

    $("#btnClose").on({
    	'click touchend': function(ev){

    		//時間記録
    		var dateEnd = new Date();
    		var actionTime = dateEnd.subtractBySeconds(dateStart);
    		//alert("actionTime:" + actionTime);
    		COMMON.SetObjectLogActionTime( CONTENTVIEW_GENERAL.contentID, objectId, actionTime );

    		$container.removeAttr('style');
    		CONTENTVIEW_GENERAL.hideDialog();

    		return false;
    	},
    	'touchstart touchmove': function(){
    		//これを入れないと次にダイアログを開くと表示位置が大きくズレる
    		return false;
    	}
    });

	//時間記録
    var dateStart = new Date();

    var avwUserEnvObj = new UserEnvironment();

    // set overflow for container iframe
    if (avwUserEnvObj.isIos()) {
        $('#dialog .anket-container').css('overflow', 'scroll');
        //$('#dialog .anket-container').css('-webkit-overflow-scrolling', 'touch');
        //$('#dialog .anket-container').css('position', 'relative');

        if (fullscreen == true) {
            $container.attr('style', 'width:' + width + 'px; left:10px;right:auto;'); // !important on ipad can't move dialog
        }
        else {
            if (avwUserEnvObj.isIpad()) {
            	$container.attr('style', 'width:' + width + 'px; right:20px;left:auto;');
            } else {
            	$container.attr('style', 'width:' + width + 'px; right:3px;left:auto;');
            }
        }
    }

    // click on button change transparent
    $('#dialog .anket-commands input').click(
        function () {
            //START TRB00092 - EDITOR: Long - Date: 09/26/2013 - Summary : Fix opacity

            if ($(this).index() == 0) {
                //set transparent
                $('#dialog,#dialog iframe,#anket-commands,#anket-commands input').removeClass('anket-opacity anket-transparent anket-translucent anket-transparent-content').addClass('anket-transparent');
                $('#anket-container').removeClass('anket-opacity anket-transparent anket-translucent anket-transparent-content').addClass('anket-transparent-content');
            }
            else if ($(this).index() == 1) {

                // set translucent
                //END TRB00092 - EDITOR: Long - Date: 09/26/2013 - Summary : Fix opacity
                $('#dialog,#dialog iframe,#anket-commands,#anket-commands input,#anket-container').removeClass('anket-opacity anket-transparent anket-translucent anket-transparent-content').addClass('anket-translucent');
            }
            else {
                //set opacity
                $('#dialog,#dialog iframe,#anket-commands,#anket-commands input,#anket-container').removeClass('anket-opacity anket-transparent anket-translucent anket-transparent-content').addClass('anket-opacity');
            }
        }
    );
        // resize anket
    CONTENTVIEW_ANKET.resizeAnket();

};

// resize dialog anket
CONTENTVIEW_ANKET.resizeAnket = function() {

    // get canvas main
    var canvas = document.getElementById('main');
    var height = canvas.height;

    var top = (CONTENTVIEW_GENERAL.isFullScreen?0:$('#header_toolbar').height()) + 4; // get top position for dialog 4 for space

    // set top dialog
    $('#dialog').height(height).css('top', top);

    var iframeHeight = height - $('#dialog h1').height() - $('#dialog .anket-commands').height() - 8;  // 8 for 2xspace

    // set height for iframe
    $('#dialog iframe').attr('height', iframeHeight);

    // set height for anket container
    $('#dialog .anket-container').css('height', iframeHeight);

};

CONTENTVIEW_ANKET.ready = function(){
};

