

if(typeof Widzzy == 'undefined') var Widzzy = {};
Widzzy.library_version = 0.01;

if(
	typeof Widzzy.version == 'undefined'
	|| Widzzy.version < Widzzy.library_version
) {
	(function() {
		this.version = Widzzy.library_version;

		// Core Dom
		this.$ = function(elem){
			return (typeof elem == 'string') ? document.getElementById(elem) : elem;
		}
		this.$C = function(name,tag,node) {
			if(node == null) node = document;
			if(tag == null) tag = '*';
			var elems = node.getElementsByTagName(tag);
			var pattern = new RegExp('(?:^|\\s)' + name + '(?:\\s|$)');
			var found = [];
			for(var i = 0; i < elems.length; i++) 
				if(pattern.test(elems[i].className)) found.push(elems[i]);
			return found;
		}
		this.getScriptsByUrl = function(url) {
			var scripts = this.$T('script');
			var found = [];
			var regex = new RegExp('(?:^|\\s)' + url + '(?:\\s|$)' );
			for(var i = 0; i < scripts.length; i++)
				if(regex.test(scripts[i].src)) found.push(scripts[i]);
			return found;
		}
		this.loadLibrary = function(url) {
			if(this.getScriptsByUrl(url).length > 0) return;
			var elem = document.createElement('script');
			elem.type = 'text/javascript';
			elem.src = url;
			document.body.appendChild(elem);
		}
		this.$T = function(tag){ return document.getElementsByTagName(tag);};

		// Core Security
		this.escapeJS = function(source) {
			return source.replace(/\\/g,'\\\\').replace(/"/g,'\\"')
				.replace(/'/g,"\\'").replace(/\//g,'\\/');
		}
		this.escapeHTML = function(source) {
			return (typeof source == 'string') ? source.replace(
					/(&)(?!(?:[a-z0-9]{2,7}|#[0-9]{2,5}|#x[0-9a-f]{2,5});)/gi,
					'&amp;'
				).replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&#34;')
				.replace(/'/g,'&#39;').replace(/`/,'&#96') : source ;
		}
		this.stripTags = function(source) {
			return source.replace(/<\/?[^>]+>/gi,'');
		}

		this.addEvent = function(elem,type,fn,useCapture) {
			if(elem.addEventListener) {
				elem.addEventListener(type, fn, useCapture);
				return true;
			} else if(elem.attachEvent) {
				return elem.attachEvent('on' + type, fn);
			} else {
				elem['on' + type] = fn;
			}
		}
	}).apply(Widzzy);


	Widzzy.Widget = function(){};
	Widzzy.Widget.prototype = {
		width: 0,
		height: 0,
		swf_path: '',
		arrow: 'always',
		transparent: true,
		play: true,
		loop: false,
		menu: false,
		quality: 'high',
		bgcolor: '#ffffff',
		id: '',
		flash_vars: '',
		wrapperId: '',
		getObjectId: function(){ return this.id + 'Object'; },
		getEmbedId: function(){ return this.id + 'Embed'; },
		getTag: function() {
			var es = Widzzy.escapeHTML;
			var trans_obj = (this.transparent) ? '<param name="wmode" value="transparent" />' : '';
			var trans_emb = (this.transparent) ? 'wmode="transparent" ' : '';
			return [
'<object id="' + this.getObjectId() + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ',
'name="' + this.getObjectId() + '" width="' + this.width +'" height="' + this.height + '" ',
'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" >',
'<param name="allowScriptAccess" value="' + this.arrow + '" />',
trans_obj,
'<param name="movie" value="' + es(this.swf_path) + '" />',
'<param name="loop" value="' + this.loop + '" />',
'<param name="menu" value="' + this.menu + '" />',
'<param name="quality" value="' + this.quality + '" />',
'<param name="bgcolor" value="' + this.bgcolor + '" />',
'<param name="FlashVars" value="' + es(this.flash_vars) + '" />',
'<embed id="' + this.getEmbedId() + '" name="' + this.getEmbedId() + '" ',
'src="' + es(this.swf_path) + '" loop="' + this.loop + '" menu="' + this.menu + '" quality="' + this.quality + '" bgcolor="' + this.bgcolor + '" ',
'swLiveConnect="true" width="' + this.width + '" height="' + this.height + '" ',
'FlashVars="' + es(this.flash_vars) + '" ',
trans_emb,
'allowScriptAccess="' + this.arrow + '" type="application/x-shockwave-flash" ',
'pluginspage="http://www.macromedia.com/go/getflashplayer" />',
'</object>'
			].join('');
		},
		load: function () {
			var tags = this.getTag();
			if(this.wrapperId) {
				Widzzy.$(this.wrapperId).innerHTML = tags;
			} else {
				var elem = document.createElement('div');
				elem.innerHTML = tags;
				document.body.appendChild(elem);
			}
		},
		getAvailableElement: function(){
			var el;
			return (el = Widzzy.$(this.getEmbedId()))? el: Widzzy.$(this.getObjectId());
		}
	}

	if (!Widzzy.LazyTask) Widzzy.LazyTask = {};
	(function(){
		this.queue = new Array();
		this.interval = 500;
		this.timer = undefined;

		//task:{ action: function_object_name, args: array_of_arguments };
		this.register = function(task) {
			this.queue.push(task);
			var _self = this;
			this.timer = setTimeout(
				function(){ return _self.tryExecusion.apply(_self);},
				_self.interval
			);
		}

		this.remove = function(task) {
			for(var i = 0; i < this.queue.length; i++) 
				if(this.queue[i].method == task.method
					&& this.queue[i].args == task.args
				) this.queue.splice(i,1);
		}

		this.tryExecusion = function() {
			if(this.timer) clearTimeout(this.timer);
			var next_queue = [];
			while(this.queue.length > 0) {
				var task = this.queue.shift();
				var method = this.getMethod(task.action);
				if(typeof method == 'undefined') {
					next_queue.push(task);
				} else {
					var obj = this.getBindTarget(task.action);
					if(task.result) {
						task.result = method.apply(obj, task.args);
					} else {
						method.apply(obj,task.args);
					}
				}
			}
			if(next_queue.length > 0) {
				this.queue = next_queue;
				var _self = this;
				this.timer = setTimeout(
					function(){ return _self.tryExecusion.apply(_self);},
					_self.interval
				);
			}
		}

		this.getMethod = function(name) {
			var method;
			try {
				method = eval(name);
			} catch(e) {
				method = undefined;
			}
			return method;
		}

		this.getBindTarget = function(name) {
			var obj;
			try {
				obj = eval(name.replace(/.[^.]+$/,''));
			} catch(e) {
				obj = window;
			}
			return obj;
		}
	}).apply(Widzzy.LazyTask);
}




if(typeof WidzzyManager == 'undefined') {
	var WidzzyManager = function(){};
	WidzzyManager.prototype = {
		count: 0,
		interval: 100,
		contextWrapper: '',
		base_id: '',
		path: '',
		width: 0,
		height: 0,
		arrow: 'sameDomain',
		transparent: false,
		play: true,
		loop: false,
		menu: 0,
		quality: 'high',
		bgcolor: '#ffffff',
		widgets_vars: [],

		appendWidget: function(vars, logStr){
			document.write(
				'<div class="' + this.contextWrapper + '" id="' + this.contextWrapper + this.count + '">' + logStr + '</div>'
			);
			this.widgets_vars[this.count] = vars;
			this.count++;
		},
		onload: function() {
			for(var i = 0; i < this.count; i++) {
				var widget = new Widzzy.Widget();

				widget.wrapperId = this.contextWrapper + i;
				widget.id = this.base_id + i + '-';

				widget.swf_path = this.path;
				widget.width = this.width;
				widget.height = this.height;
				widget.arrow = this.arrow;
				widget.transparent = this.transparent;
				widget.play = this.play;
				widget.loop = this.loop;
				widget.menu = this.menu;
				widget.quality = this.quality;
				widget.bgcolor = this.bgcolor;

				widget.flash_vars = this.widgets_vars[i];

				widget.load();
			}
		},
		complete: function() {
			if(this.done) return;
			this.done = true;
			if(!typeof this.done == 'undefined') {
				clearInterval(this.timer);
				this.timer = null;
			}
			this.onload();
		},
		watch: function() {
			var _self = this;
			var ua = navigator.userAgent.toLowerCase();
			if(ua.match(/webkit|safari|khtml/)){ // Safari & KHTML
				_self.timer = setInterval(
					function() { 
						if(document.readyState.match(/loaded|complete/)) {
							return _self.complete.apply(_self);
						}
					},50);
			} else if(document.addEventListener) {
				document.addEventListener(
					"DOMContentLoaded",
					function(){ return _self.complete.apply(_self);},
					false
				);
			}
			/*@cc_on @*/
			/*@if (@_win32) @*/
			else if(ua.match(/msie/) && !ua.match(/opera/)) {
				document.write("<scr" + "ipt id=__widzzy_ie_init defer=true " + "src=//:><\/script>");
				document.getElementById('__widzzy_ie_init').onreadystatechange = function() {
					if(this.readyState != 'complete') return;
					_self.complete();
				};
			}
			/*@end @*/
			else {
				addEvent(window,"load",_self.complete);
			}
		}
	}
}




// for customization
if(typeof cocolo == 'undefined') {
	var cocolo = new WidzzyManager();
	(function(){

		var floatingSwfPath = {};
		floatingSwfPath['omulet'] = 'http://www.blogpet.net/img/omulet.swf'
		floatingSwfPath['bread'] = 'http://www.blogpet.net/img/bread.swf'
		floatingSwfPath['curry'] = 'http://www.blogpet.net/img/curry.swf'
		floatingSwfPath['bentou'] = 'http://www.blogpet.net/img/bentou.swf'
		floatingSwfPath['purple_curry'] = 'http://www.blogpet.net/img/purple_curry.swf'

		var noCache = true;
		//var noCacheParam = noCache ? '?t=' + new Date() : '';
		var noCacheParam = noCache ? '?t=20071218' : '';


		this.open = function(id, w, h){
			url = floatingSwfPath[id] + noCacheParam;

			if (url.indexOf('http') == -1) {
				return false;
			}

			w = w || 400;
			h = h || 550;
			id = id || 'BlogToyWidget-panel';

			var root_url = 'http://www.blogpet.net/lib/widget/';
			var panelId = 'widzzy-panel';

			// load library
			Widzzy.loadLibrary(root_url + 'bytefx_OS.js' + noCacheParam);
			Widzzy.loadLibrary(root_url + 'dom.js' + noCacheParam);
			Widzzy.loadLibrary(root_url + 'effects.js' + noCacheParam);

			var floating = new Widzzy.Widget();

			floating.width = w;
			floating.height = h;
			floating.swf_path = url;
			floating.wrapperId = id;

			floating.id = "BlogToyWidgetFloating";
//			floating.flash_vars = 'domain=api.blogpet.net';
			floating.flash_vars = '';

			Widzzy.LazyTask.register({
				action: "Widzzy.Effects.centering",
				args: [floating]
			});


			if (! (window.opera || /webkit/.test(navigator.userAgent.toLowerCase())) ) {
				var timer = setInterval(checkSwf, 60);
			}

			function checkSwf() {
				var panelElm = document.getElementById(panelId);

//				if (panelElm && panelElm.getElementsByTagName('object').length) {
				if (document.getElementById('BlogToyWidgetFloatingObject')) {

					clearInterval(timer);

					var speed = 20;
					var isMSIE = /*@cc_on!@*/false;
					if (isMSIE) {
						speed = 33;
					}

/*
					var valance = document.getElementById('valance');
					if (valance) {
						Widzzy.LazyTask.register({
							action: "bytefx_cocolo.fade",
							args: [valance, 0, 60, speed]
						});
					}
*/
					setTimeout(function () {
						Widzzy.LazyTask.register({
							action: "bytefx_cocolo.fade",
							args: [panelElm, 0, 99.9, speed]
						});
					}, 20);
				}
			}
		}


		this.close = function(){

			var panelId = 'widzzy-panel';

			var speed = 20;
			var isMSIE = /*@cc_on!@*/false;
			if (isMSIE) {
				speed = 33;
			}

			if (! (window.opera || /webkit/.test(navigator.userAgent.toLowerCase())) ) {
				Widzzy.LazyTask.register({
					action: "bytefx_cocolo.fade",
					args: [document.getElementById(panelId), 99.9, 0, speed]
				});

/*
				setTimeout(function () {
					Widzzy.LazyTask.register({
						action: "bytefx_cocolo.fade",
						args: [document.getElementById('valance'), 60, 0, speed]
					});
				}, 300);
*/

				setTimeout(function () {
					Widzzy.LazyTask.register({
						action: "Widzzy.Effects.end",
						args: []
					});
				}, 1500);

			} else {
				//opera & safari
				Widzzy.LazyTask.register({
					action: "Widzzy.Effects.end",
					args: []
				});
			}
		}


		// widget params
		this.contextWrapper = 'BlogToyWidgetWrapper';
		this.base_id = 'BlogToy-widget-';
		this.path = 'http://media.blogpet.net/6/0/1098860.swf' + noCacheParam;
		this.width = 130;
		this.height = 220;
		this.arrow = 'always';
		this.transparent = true;
		this.play = true;
		this.loop = false;
		this.menu = false;
		this.quality = 'high';
		this.bgcolor = '#ffffff';
	}).apply(cocolo);

	cocolo.watch();
}


(function () {
	try {
		var request = encodeURIComponent(document.URL);
		var referrer = encodeURIComponent(document.referrer);
	} catch (e) {
		var request = escape(document.URL);
		var referrer = escape(document.referrer);
	}

	cocolo.appendWidget(
		'public_key=97e78431d7bd3eeccfcbefec1a06e4e6&domain=api.blogpet.net&current_url="' + request + '"',

		''
	);






document.write("<script type='text/javascript' src='http://kk.blogtoy.net/js/part/blogpet-cocolo/default.js'></script>");
})();


