﻿/// <reference path="Scripts/jquery-1.3.2-vsdoc.js" />
var domain = "http://free.newsbank.co.kr";
var viewerDomain = "http://image.newsbank.co.kr";

function ViewFlashViewer(cmscode) {
    document.write(GetViewSrcMaxSize(cmscode, null));
}

function GetViewSrcMaxSize(cmscode, maxSize) {
    var imgObj = new Image();

    //요게 이미지 객체
    imgObj.src = GetImagePath(cmscode);

    var intWidth = imgObj.width;
    var intHeight = imgObj.height;

    

    var intMaxWidth = 600;
    var intMaxHeight = 600;

    if (maxSize != null) {
        intMaxWidth = maxSize;
        intMaxHeight = maxSize;
    }

    //비율을 같게 한다
    if (intWidth > intHeight) {
        intHeight = intMaxWidth * intHeight / intWidth;
        intWidth = intMaxWidth;
    }

    if (intHeight > intWidth) {
        intWidth = intMaxHeight * intWidth / intHeight;
        intHeight = intMaxHeight;
    }

    if (intWidth == intHeight) {
        intWidth = intMaxWidth;
        intHeight = intMaxHeight;
    }

    intWidth = parseInt(intWidth.toString());
    intHeight = parseInt(intHeight.toString());

    intHeight += 30;

    $("#spanFlashWidth").attr("innerHTML", parseInt(intWidth) - 2);

    strObject = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"'
                + ' width="' + intWidth + '" height="' + intHeight + '" id="Viewer" align="middle">'
                + ' <param name="movie" value="' + viewerDomain + '/flashviewer/001@' + cmscode + '" /><param name="allowScriptAccess" value="always" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><param name="wmode" value="transparent"/>'
                + ' <EMBED id = "Viewer"'
                + ' name="Viewer"'
                + ' pluginspage = "http://www.macromedia.com/go/getflashplayer"'
                + ' align = "middle"'
                + ' src= "' + viewerDomain + '/flashviewer/001@' + cmscode + '"'
                + ' width="' + intWidth + 'px"'
                + ' height="' + intHeight + 'px"'
                + ' type="application/x-shockwave-flash"'
                + ' wmode="transparent"'
                + ' allowFullScreen="true"'
                + ' allowScriptAccess="always"'
                + ' quality="high" />'
                + ' </object>';

    return strObject;
}

function GetViewSrc(cmscode, intWidth, intHeight) {

    $("#spanFlashWidth").attr("innerHTML", parseInt(intWidth) - 2);

    strObject = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"'
                + ' width="' + intWidth + '" height="' + intHeight + '" id="Viewer" align="middle">'
                + ' <param name="movie" value="' + viewerDomain + '/flashviewer/001@' + cmscode + '" /><param name="allowScriptAccess" value="always" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><param name="wmode" value="transparent"/>'
                + ' <EMBED id = "Viewer"'
                + ' name="Viewer"'
                + ' pluginspage = "http://www.macromedia.com/go/getflashplayer"'
                + ' align = "middle"'
                + ' src= "' + viewerDomain + '/flashviewer/001@' + cmscode + '"'
                + ' width="' + intWidth + 'px"'
                + ' height="' + intHeight + 'px"'
                + ' type="application/x-shockwave-flash"'
                + ' wmode="transparent"'
                + ' allowFullScreen="true"'
                + ' allowScriptAccess="always"'
                + ' quality="high" />'
                + ' </object>';

    return strObject;
}

function GetImagePath(cmsCode) {

    var imagePath = domain + "/datafolder/Repository/Img/";
    imagePath += cmsCode.toString().substr(0, 2);
    imagePath += "/";
    imagePath += cmsCode.toString().substr(4, 4);
    imagePath += "/";
    imagePath += cmsCode.toString().substr(8, 2);
    imagePath += "/";
    imagePath += cmsCode.toString().substr(10, 2);
    imagePath += "/";
    imagePath += cmsCode + "_001_P.jpg";

    return imagePath;

}

//기본 플래쉬 오브젝트 코드
function WriteSwf(url, width, height) {
    var strObject;

    strObject = ' <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + 'px" height="' + height + 'px"  id="" name="" align="middle" >'
	            + ' <param name="movie" value="' + url + '" />'
	            + ' <param name="allowScriptAccess" value="always" />'
	            + ' <param name="wmode" value="transparent"'
	            + ' <EMBED '
                + ' pluginspage = "http://www.macromedia.com/go/getflashplayer"'
                + ' align = "middle"'
                + ' src= "' + url + '"'
                + ' width="' + width + '"'
                + ' height="' + height + '"'
                + ' type="application/x-shockwave-flash"'
                + ' wmode="transparent"'
                + ' allowFullScreen="true"'
                + ' allowScriptAccess="always"'
    //+ ' bgcolor="#060606"'
                + ' quality="high">'
                + ' </object>';

    document.write(strObject);
}