

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

if(
	typeof WidzzyWK.version == 'undefined'
	|| WidzzyWK.version < WidzzyWK.library_version
) {
	(function() {
		this.version = WidzzyWK.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(WidzzyWK);


	WidzzyWK.Widget = function(){};
	WidzzyWK.Widget.prototype = {
		width: 0,
		height: 0,
		swf_path: '',
		arrow: 'always',
		transparent: false,
		play: true,
		loop: false,
		menu: false,
		quality: 'high',
		bgcolor: '#e9e9e9',
		id: '',
		flash_vars: '',
		wrapperId: '',
		getObjectId: function(){ return this.id + 'Object'; },
		getEmbedId: function(){ return this.id + 'Embed'; },
		getTag: function() {
			var style = '';
			if (this.getObjectId().match(/floating/i)) {
				style = ' style="border:1px solid #ca9"';
			}
			var es = WidzzyWK.escapeHTML;
			var trans_obj = (this.transparent) ? '<param name="wmode" value="transparent" />' : '';
			var trans_emb = (this.transparent) ? 'wmode="transparent" ' : '';
			return [
'<object' + style + ' 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) {

// Swf is loaded two times.
//				WidzzyWK.$(this.wrapperId).innerHTML = tags;

				var elem = document.createElement('div');
				elem.innerHTML = tags;
				WidzzyWK.$(this.wrapperId).appendChild(elem);

			} else {
				var elem = document.createElement('div');
				elem.innerHTML = tags;
				document.body.appendChild(elem);
			}
		},
		getAvailableElement: function(){
			var el;
			return (el = WidzzyWK.$(this.getEmbedId()))? el: WidzzyWK.$(this.getObjectId());
		}
	}

	if (!WidzzyWK.LazyTask) WidzzyWK.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(WidzzyWK.LazyTask);
}




if(typeof WidzzyWKManager == 'undefined') {
	var WidzzyWKManager = function(){};
	WidzzyWKManager.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: '#e9e9e9',
		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 WidzzyWK.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=__WidzzyWK_ie_init defer=true " + "src=//:><\/script>");
				document.getElementById('__WidzzyWK_ie_init').onreadystatechange = function() {
					if(this.readyState != 'complete') return;
					_self.complete();
				};
			}
			/*@end @*/
			else {
				addEvent(window,"load",_self.complete);
			}
		}
	}
}




// for customization
if(typeof webkare == 'undefined') {
	var webkare = new WidzzyWKManager();
	(function(){

		var floatingSwfPath = {};
		floatingSwfPath['event'] = new Array('http://web-kare.jp/img/DUMMY/eventSc.swf?200912241421', '/event_api/event', '/event_api/event_end')
		floatingSwfPath['kkevent'] = new Array('http://web-kare.jp/img/DUMMY/kk_eventSc.swf?200912241421', '/kk_event_api/event', '/kk_event_api/event_end')
		floatingSwfPath['user_event'] = new Array('http://web-kare.jp/img/DUMMY/eventSc.swf?200912241421', '/event_api/user_event', '/event_api/user_event_end')

		var noCache = 0;

		this.event = function(id, event_id, event_log_id, public_key, target_key, w, h, replay) {
			url = floatingSwfPath[id][0];
			event_url = floatingSwfPath[id][1];
			event_end_url = floatingSwfPath[id][2];

			if (url.indexOf('http') == -1) {
				return false;
			}
			if ( (!location.href.match(/^http\:\/\/web-kare\.jp\//)) && (!location.href.match(/^http\:\/\/[^\/]+?linkthink\.jp\//))) {
				return false;
			}

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

			var root_url = 'http://web-kare.jp/lib/widget/';
			var panelId = 'WidzzyWK-panel';

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

			var floating = new WidzzyWK.Widget();

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

			floating.id = "WebkareWidgetFloating";
//			floating.flash_vars = 'domain=api.web-kare.jp';
			floating.flash_vars = 'apidomain=api.web-kare.jp&domain=web-kare.jp&event_url='+event_url+'&end_url='+event_end_url+'&event_id='+event_id+'&event_log_id='+event_log_id+'&public_key='+public_key+'&target_key='+target_key+'&replay='+replay;
			if (noCache) {
				floating.flash_vars += '&nocache=true';
			}

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

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

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

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

				if (document.getElementById('WebkareWidgetFloatingObject')) {

					clearInterval(timer);
					var speed = 5;

					var valance = document.getElementById('valance');
					if (valance) {
						WidzzyWK.LazyTask.register({
							action: "bytefx_webkare.fade",
							args: [valance, 0, 60, speed]
						});
					}

/*
					setTimeout(function () {
						WidzzyWK.LazyTask.register({
							action: "bytefx_webkare.fade",
							args: [panelElm, 0, 99.9, speed]
						});
					}, 20);
*/
				}
			}
		}


		this.close = function(){

			var panelId = 'WidzzyWK-panel';

			var speed = 4;

			if (! (window.opera || /webkit/.test(navigator.userAgent.toLowerCase())) ) {

/*
				WidzzyWK.LazyTask.register({
					action: "bytefx_webkare.fade",
					args: [document.getElementById(panelId), 99.9, 0, speed]
				});
*/

				setTimeout(function () {
					WidzzyWK.LazyTask.register({
						action: "bytefx_webkare.fade",
						args: [document.getElementById('valance'), 60, 0, speed]
					});
				}, 110);

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

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


		this.home = function() {
			if ('http://' + location.host == 'http://web-kare.jp') {
				location.href = 'http://web-kare.jp/home/onacrystal';
			} else {
				location.href = 'http://web-kare.jp/home/onacrystal';
//				window.open('http://web-kare.jp/home/onacrystal');
			}
		}


		this.myalbum = function() {
			if ('http://' + location.host == 'http://web-kare.jp') {
				location.href = 'http://web-kare.jp/album/user/onacrystal';
			} else {
				location.href = 'http://web-kare.jp/album/user/onacrystal';
//				window.open('http://web-kare.jp/album/user/onacrystal');
			}
		}

		this.change = function(c) {
			if (typeof siteJs != 'undefined') {
				siteJs.change(c);
			}
		}

		// widget params
		this.contextWrapper = 'WebkareWidgetWrapper';
		this.base_id = 'Webkare-widget-';
		this.path = 'http://media.web-kare.jp/kare/200912241421/main.swf';
		this.width = 150;
		this.height = 340;
		this.arrow = 'always';
		this.transparent = true;
		this.play = true;
		this.loop = false;
		this.menu = false;
		this.quality = 'high';
		this.bgcolor = '#e9e9e9';
	}).apply(webkare);

	webkare.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);
	}

	webkare.appendWidget('public_key=bd9440e77a801dc9d4999ef89bcbd7fe&amp;domain=api.web-kare.jp&amp;media_domain=media.web-kare.jp&amp;load_delay=1250',
		''
	);






document.write("<div style='margin-top:0px' class='webkarekk'>");
document.write("<script type='text/javascript' src='http://kk.linkthink.co.jp/js/webkare/web-kare/webkare1.js'></script>");
document.write("</div>");
})();


