/**
 * (C) KAYAC Inc. <http://www.kayac.com/>
 *
 * @usage   <script type="text/javascript" src="http://path/to/script.js?aid=zlQEr7mkG6I08__2u5gOdJ8i"></script>
 */

if (typeof Kaibutsukun == 'undefined') Kaibutsukun = {};

new function() {
	/*
	 * jQuery 1.2.6 - New Wave Javascript
	 *
	 * Copyright (c) 2008 John Resig (jquery.com)
	 * Dual licensed under the MIT (MIT-LICENSE.txt)
	 * and GPL (GPL-LICENSE.txt) licenses.
	 *
	 * $Date: 2008-05-24 14:22:17 -0400 (Sat, 24 May 2008) $
	 * $Rev: 5685 $
	 */
	var userAgent = navigator.userAgent.toLowerCase();
	var browser = {
		version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
		safari: /webkit/.test( userAgent ),
		opera: /opera/.test( userAgent ),
		msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
		mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
	};

	var defaultView = document.defaultView || {};
	var curCSS = function( elem, name, force ) {
		var ret, style = elem.style;

		// A helper method for determining if an element's values are broken
		function color( elem ) {
			if ( !browser.safari )
				return false;

			// defaultView is cached
			var ret = defaultView.getComputedStyle( elem, null );
			return !ret || ret.getPropertyValue("color") == "";
		}

		// We need to handle opacity special in IE
		if ( name == "opacity" && browser.msie ) {
			// IE uses filters for opacity
			return style.filter && style.filter.indexOf("opacity=") >= 0 ?
				(parseFloat( style.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
				"1";
		}
		// Opera sometimes will give the wrong display answer, this fixes it, see #2037
		if ( browser.opera && name == "display" ) {
			var save = style.outline;
			style.outline = "0 solid black";
			style.outline = save;
		}

		// Make sure we're using the right name for getting the float value
		if ( name.match( /float/i ) )
			name = styleFloat;

		if ( !force && style && style[ name ] )
			ret = style[ name ];

		else if ( defaultView.getComputedStyle ) {

			// Only "float" is needed here
			if ( name.match( /float/i ) )
				name = "float";

			name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();

			var computedStyle = defaultView.getComputedStyle( elem, null );

			if ( computedStyle && !color( elem ) )
				ret = computedStyle.getPropertyValue( name );

			// If the element isn't reporting its values properly in Safari
			// then some display: none elements are involved
			else {
				var swap = [], stack = [], a = elem, i = 0;

				// Locate all of the parent display: none elements
				for ( ; a && color(a); a = a.parentNode )
					stack.unshift(a);

				// Go through and make them visible, but in reverse
				// (It would be better if we knew the exact display type that they had)
				for ( ; i < stack.length; i++ )
					if ( color( stack[ i ] ) ) {
						swap[ i ] = stack[ i ].style.display;
						stack[ i ].style.display = "block";
					}

				// Since we flip the display style, we have to handle that
				// one special, otherwise get the value
				ret = name == "display" && swap[ stack.length - 1 ] != null ?
					"none" :
					( computedStyle && computedStyle.getPropertyValue( name ) ) || "";

				// Finally, revert the display styles back
				for ( i = 0; i < swap.length; i++ )
					if ( swap[ i ] != null )
						stack[ i ].style.display = swap[ i ];
			}

			// We should always get a number back from opacity
			if ( name == "opacity" && ret == "" )
				ret = "1";

		} else if ( elem.currentStyle ) {
			var camelCase = name.replace(/\-(\w)/g, function(all, letter){
				return letter.toUpperCase();
			});

			ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];

			// From the awesome hack by Dean Edwards
			// http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291

			// If we're not dealing with a regular pixel number
			// but a number that has a weird ending, we need to convert it to pixels
			if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
				// Remember the original values
				var left = style.left, rsLeft = elem.runtimeStyle.left;

				// Put in the new values to get a computed value out
				elem.runtimeStyle.left = elem.currentStyle.left;
				style.left = ret || 0;
				ret = style.pixelLeft + "px";

				// Revert the changed values
				style.left = left;
				elem.runtimeStyle.left = rsLeft;
			}
		}

		return ret;
	};

	// The Offset Method
	// Originally By Brandon Aaron, part of the Dimension Plugin
	// http://jquery.com/plugins/project/dimensions
	var offset = function(elem) {
		var left = 0, top = 0, results;

		if ( elem ) with ( browser ) {
			var parent       = elem.parentNode,
			    offsetChild  = elem,
			    offsetParent = elem.offsetParent,
			    doc          = elem.ownerDocument,
			    safari2      = safari && parseInt(version) < 522 && !/adobeair/i.test(userAgent),
			    css          = curCSS,
			    fixed        = css(elem, "position") == "fixed";

			// Use getBoundingClientRect if available
			if ( elem.getBoundingClientRect ) {
				var box = elem.getBoundingClientRect();

				// Add the document scroll offsets
				add(box.left + Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft),
					box.top  + Math.max(doc.documentElement.scrollTop,  doc.body.scrollTop));

				// IE adds the HTML element's border, by default it is medium which is 2px
				// IE 6 and 7 quirks mode the border width is overwritable by the following css html { border: 0; }
				// IE 7 standards mode, the border is always 2px
				// This border/offset is typically represented by the clientLeft and clientTop properties
				// However, in IE6 and 7 quirks mode the clientLeft and clientTop properties are not updated when overwriting it via CSS
				// Therefore this method will be off by 2px in IE while in quirksmode
				add( -doc.documentElement.clientLeft, -doc.documentElement.clientTop );

			// Otherwise loop through the offsetParents and parentNodes
			} else {

				// Initial element offsets
				add( elem.offsetLeft, elem.offsetTop );

				// Get parent offsets
				while ( offsetParent ) {
					// Add offsetParent offsets
					add( offsetParent.offsetLeft, offsetParent.offsetTop );

					// Mozilla and Safari > 2 does not include the border on offset parents
					// However Mozilla adds the border for table or table cells
					if ( mozilla && !/^t(able|d|h)$/i.test(offsetParent.tagName) || safari && !safari2 )
						border( offsetParent );

					// Add the document scroll offsets if position is fixed on any offsetParent
					if ( !fixed && css(offsetParent, "position") == "fixed" )
						fixed = true;

					// Set offsetChild to previous offsetParent unless it is the body element
					offsetChild  = /^body$/i.test(offsetParent.tagName) ? offsetChild : offsetParent;
					// Get next offsetParent
					offsetParent = offsetParent.offsetParent;
				}

				// Get parent scroll offsets
				while ( parent && parent.tagName && !/^body|html$/i.test(parent.tagName) ) {
					// Remove parent scroll UNLESS that parent is inline or a table to work around Opera inline/table scrollLeft/Top bug
					if ( !/^inline|table.*$/i.test(css(parent, "display")) )
						// Subtract parent scroll offsets
						add( -parent.scrollLeft, -parent.scrollTop );

					// Mozilla does not add the border for a parent that has overflow != visible
					if ( mozilla && css(parent, "overflow") != "visible" )
						border( parent );

					// Get next parent
					parent = parent.parentNode;
				}

				// Safari <= 2 doubles body offsets with a fixed position element/offsetParent or absolutely positioned offsetChild
				// Mozilla doubles body offsets with a non-absolutely positioned offsetChild
				if ( (safari2 && (fixed || css(offsetChild, "position") == "absolute")) ||
					(mozilla && css(offsetChild, "position") != "absolute") )
						add( -doc.body.offsetLeft, -doc.body.offsetTop );

				// Add the document scroll offsets if position is fixed
				if ( fixed )
					add(Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft),
						Math.max(doc.documentElement.scrollTop,  doc.body.scrollTop));
			}

			// Return an object with top and left properties
			results = { top: top, left: left };
		}

		function border(elem) {
			add( curCSS(elem, "borderLeftWidth", true), curCSS(elem, "borderTopWidth", true) );
		}

		function add(l, t) {
			left += parseInt(l, 10) || 0;
			top += parseInt(t, 10) || 0;
		}

		return results;
	};

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

	var parseQuery = function(query) {
		var ret = {};
		if (!query) return ret;
		query = query.split('&');
		for (var i = 0, length = query.length; i < length; i++) {
			var q = query[i].split('=');
			var k = decodeURIComponent(q[0]);
			var v = decodeURIComponent(q[1]);
			ret[k] = isNaN(v) ? v : Number(v);
		}
		return ret;
	};


	Kaibutsukun.open = function(desc) {
		var flashvars = param({
			lr  : lr,
			desc: desc
		});
		var div = document.createElement('div');
		div.id = 'blogdecoKaibutsukunComment';
		div.style.position = 'absolute';
		div.style.top      = o.top+'px';
		div.style.left     = ((lr == 'l') ? o.left - 423 - 5 : o.left + 160 + 5)+'px';
		div.style.zIndex   = 50000;
		div.style.width    = '423px';
		div.style.height   = '233px';
		document.body.appendChild(div);

		div.innerHTML = [
			'<object id="blogdecoKaibutsukunCommentSWF" data="http://kaibutsukun.in/swf/comment.swf" type="application/x-shockwave-flash" width="423" height="233">',
			'<param name="movie" value="http://kaibutsukun.in/swf/comment.swf"/>',
			'<param name="wmode" value="transparent"/>',
			'<param name="allowscriptaccess" value="never"/>',
			'<param name="flashvars" value="'+flashvars+'"/>',
			'</object>'
		].join('');
	};

	Kaibutsukun.close = function() {
		setTimeout(function() {
			var swf = document.getElementById('blogdecoKaibutsukunCommentSWF');
			var div = document.getElementById('blogdecoKaibutsukunComment');
			if (swf && div) {
				div.style.display = 'none';
				div.removeChild(swf);
				document.body.removeChild(div);
			}
		}, 0);
	};


	var s = document.getElementsByTagName('script');
	var self = s[s.length - 1];

	var div = document.createElement('div');
	div.id = 'blogdecoKaibutsukun';
	self.parentNode.insertBefore(div, self);
	div.style.width  = '160px';
	div.style.height = '300px';

	var o = offset(div);
	var lr = o.left < 423 + 25 ? 'r' : 'l';
	var flashvars = {
		lr : lr,
		url: location.href
	};
	var aid;
	if (aid = parseQuery((/\?(.+)$/.exec(self.src) || [])[1]).aid)
		flashvars.affiliate_id = aid;
	flashvars = param(flashvars);

	div.innerHTML = [
		'<object id="blogdecoKaibutsukunSWF" data="http://kaibutsukun.in/swf/main.swf" type="application/x-shockwave-flash" width="160" height="300">',
		'<param name="movie" value="http://kaibutsukun.in/swf/main.swf"/>',
		'<param name="wmode" value="transparent"/>',
		'<param name="allowscriptaccess" value="always"/>',
		'<param name="flashvars" value="'+flashvars+'"/>',
		'</object>'
	].join('');
};
