/**
 * (C) KAYAC Inc. <http://www.kayac.com/>
 * License: MIT License <http://www.opensource.org/licenses/mit-license.php>
 */

new function() {

        var swfpath = 'http://www.blogdeco.jp/coin/swf/main.swf';
        var logkayac_id = 'blogdeco00072';

        var width  = 160;
        var height = 200;

//-----------------------------------------------------------------------------

	var self = getSelfScript();
	var uid = new Date().getTime();

	var flashvars = param({
		loc: location.href,
		ref: document.referrer
	});
	var container = document.createElement('div');
	container.style.width  = width  + 'px';
	container.style.height = height + 'px';
	self.parentNode.insertBefore(container, self);
	container.innerHTML = [
		'<object id="cubaclock-swf-'+uid+'" data="'+ swfpath +'" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'">',
		'  <param name="movie" value="'+ swfpath +'"/>',
                '  <param name="quality value="high" />',
		'  <param name="wmode" value="transparent"/>',,
                '  <param name="allowFullScreen" value="false" />',
		'  <param name="flashvars" value="'+flashvars+'"/>',
		'</object>'
	].join('');

        if(typeof logkayac_id != 'undefined') {
            document.createElement('img').src = 'http://log.kayac.com/cl/?rs=i&cm='+logkayac_id+'&ln=1';
        }

	function param(obj) {
		var ret = [];
		for (var v in obj)
			ret.push(encodeURIComponent(v)+'='+encodeURIComponent(obj[v])); 
		return ret.join('&');
	}

        function getSelfScript() {
            var s = document.getElementsByTagName('script');
            for(var i = 0, l = s.length; i < l; i++) {
                if(s[i].className && s[i].className == 'blogdeco-coin') {
                    return s[i];
                }
            }
            return null;
        }
};
