var fl_path = "http://www.meiji.co.jp/sweets/chocolate/kinotake/blogparts/src/blogparts.swf";
var big_fl_path = "http://www.meiji.co.jp/sweets/chocolate/kinotake/blogparts/src/full.swf";
var agent = navigator.appName;
var main;
var nowpix;
var ua = navigator.userAgent;
var _height = 0;
var _width = 0;
var root = (document.compatMode == "CSS1Compat") ? document.body.parentNode : document.body;
var date = new Date();

function add(num,num2) {
	document.body.appendChild(make(num));
}

function make(num) {
	var main = document.createElement('div');
	main.style.width = getWindowWidth()+"px";
	main.style.height = getWindowHeight()+"px";
	main.style.position ="absolute";
	main.style.top = getWinYOffset()+"px";
	main.style.left = 0;
	main.style.overflow = "hidden";
	main.style.backgroundColor = "#ff0000";
	return main;
}

function top(obj){
    var pos = 0;
    if (obj) {
        pos = obj.offsetTop;
        if (obj.offsetParent) {
            pos += top(obj.offsetParent)
        }
    }
    return pos
}

function left(obj){
    var pos = 0;
    if (obj) {
        pos = obj.offsetLeft;
        if (obj.offsetParent) {
            pos += left(obj.offsetParent)
        }
    }
    return pos
}

function closeParts(){
    if (ua.indexOf("Safari") > -1 || ua.indexOf("Firefox") > -1) {
        document.getElementById('flash').style.display = "none";
        document.getElementById('flash').removeAttribute("id");
        window.removeEventListener('scroll', scrollEvent, false);
    }
    else {
        document.body.removeChild(document.getElementById('flash'));
        window.detachEvent('onscroll', scrollEvent);
    }
}

function createMOZ(){
    var _yoko = left(document.getElementById('blogparts'));
    var _tate = top(document.getElementById('blogparts')) - getWinYOffset();
    init();
    big_fl_path = big_fl_path + "?g" + date.getSeconds() + "=nocache&_heightw=" + _height + "&_widthw=" + (_width-16) + "&_yoko=" + _yoko + "&_tate=" + _tate;
    main = document.createElement('div');
    imgObj = document.createElement('embed');
    imgObj.src = big_fl_path;
    imgObj.id = 'kinoyama_fla';
    imgObj.salign = 'lt';
    imgObj.quality = 'high';
    imgObj.setAttribute('wmode', 'transparent');
    imgObj.width = _width-15;
    imgObj.height = _height;
    imgObj.setAttribute('allowScriptAccess', 'always');
    imgObj.type = 'application/x-shockwave-flash';
    imgObj.pluginspage = 'http://www.macromedia.com/go/getflashplayer';
    main.id = 'flash';
    document.body.appendChild(main);
    initiaCSS();
    document.getElementById('flash').appendChild(imgObj);
}

function createIE(){
    var _yoko = left(document.getElementById('blogparts'));
    var _tate = top(document.getElementById('blogparts')) - getWinYOffset();
    init();
    big_fl_path = big_fl_path + "?g" + date.getSeconds() + "=nocache&_heightw=" + _height + "&_widthw=" + _width + "&_yoko=" + _yoko + "&_tate=" + _tate;
    main = document.createElement('div');
    initiaCSS();
    main.id = 'flash';
    var dd = document.createElement('div');
    dd.id = 'w';
    var flaObj1 = document.createElement('object');
    flaObj1.id = 'kinoyama_fla';
    var flaObj2 = document.createElement('param');
    flaObj2.name = 'allowScriptAccess';
    flaObj2.value = 'always';
    var flaObj3 = document.createElement('param');
    flaObj3.name = 'movie';
    flaObj3.value = big_fl_path;
    var flaObj4 = document.createElement('param');
    flaObj4.name = 'quality';
    flaObj4.value = 'high';
    var flaObj5 = document.createElement('param');
    flaObj5.name = 'wmode';
    flaObj5.value = 'transparent';
    document.body.appendChild(main);
    document.getElementById('flash').appendChild(flaObj1);
    document.getElementById('kinoyama_fla').appendChild(flaObj2);
    document.getElementById('kinoyama_fla').appendChild(flaObj3);
    document.getElementById('kinoyama_fla').appendChild(flaObj4);
    document.getElementById('kinoyama_fla').appendChild(flaObj5);
    document.getElementById('kinoyama_fla').setAttribute("classid", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000");
    document.getElementById('kinoyama_fla').setAttribute("codebase", "http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0");
    var w = _width;
    var h = _height;
    document.getElementById('kinoyama_fla').setAttribute("width", w);
    document.getElementById('kinoyama_fla').setAttribute("height", h);
}

function initiaCSS(){
    main.style.position = "absolute";
    main.style.zIndex = "1";
    main.style.left = 0;
    main.style.top = nowpix + "px";
    main.style.height = _height + "px";
    main.style.width = "100%";
}

function getWinYOffset(){
    if (window.scrollY) 
        return window.scrollY; // Mozilla
    if (window.pageYOffset) 
        return window.pageYOffset; // Opera, NN4
    if (document.documentElement && document.documentElement.scrollTop) { // ??? IE
        return document.documentElement.scrollTop;
    }
    else 
        if (document.body && document.body.scrollTop) {
            return document.body.scrollTop;
        }
    return 0;
}

function scrollEvent(){
    nowpix = getWinYOffset();
    document.getElementById('flash').style.top = nowpix + "px";
}

function blogFloat(){
    try {
        window.addEventListener('scroll', scrollEvent, false);
    } 
    catch (e) {
        window.attachEvent('onscroll', scrollEvent);
    }
    nowpix = getWinYOffset();
    if (agent == "Microsoft Internet Explorer") {
        createIE();
    }
    else 
        if (agent == "Netscape") {
            createMOZ();
        }
}

document.writeln("<div>");
document.writeln("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='150' height='250' id='blogparts' align='middle'>");
document.writeln("<param name='allowScriptAccess' value='always'>");
document.writeln("<param name='movie' value='" + fl_path + "'>");
document.writeln("<param name='quality' value='high'>");
document.writeln("<param name='bgcolor' value='#ffffff'>");
document.writeln("<param name='wmode' value='transparent'>");
document.writeln("<embed src='" + fl_path + "' allowScriptAccess='always' wmode='transparent' quality='high' bgcolor='#ffffff' width='150' height='250' name='blogparts' align='middle' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'>");
document.writeln("</object>");
document.writeln("</div>");

function getWindowWidth(){
    if (window.innerWidth) 
        return window.innerWidth; // Mozilla, Opera, NN4
    if (document.documentElement && document.documentElement.clientWidth) { // ??? IE
        return document.documentElement.clientWidth;
    }
    else 
        if (document.body && document.body.clientWidth) {
            return document.body.clientWidth;
        }
    return 0;
}

function getWindowHeight(){
    if (window.innerHeight) 
        return window.innerHeight; // Mozilla, Opera, NN4
    if (document.documentElement && document.documentElement.clientHeight) { // ??? IE
        return document.documentElement.clientHeight;
    }
    else 
        if (document.body && document.body.clientHeight) {
            return document.body.clientHeight;
        }
    return 0;
}

function init(){
    _width = getWindowWidth();
    _height = getWindowHeight();
}

function getAgent(){
    var ua = navigator.userAgent;
    if (ua.indexOf("Safari") > -1) 
        return "Safari";
    if (ua.indexOf("Firefox") > -1) 
        return "Firefox";
    if (ua.indexOf("MSIE") > -1) 
        return "Ie";
    return "unknown";
}

init();
