if (typeof LXSCart == 'undefined') {

//--============================================================================
//-- Definitions & Utilities
//--============================================================================
var LXSCart = {

	base_uri: 'https://shika-mall.com/shop/cart',
	charset : 'utf-8',
	scripts : [],
	styles  : [],

	loadScript: function(url) {
		var script     = document.createElement('script');
		script.type    = 'text/javascript';
		script.charset = this.charset;
		script.src     = this.base_uri + url;

		document.getElementsByTagName('head')[0].appendChild(script);

		this.scripts[this.scripts.length] = script;
		return script;
	},

	loadStyle: function(url) {
		var link     = document.createElement('link');
		link.rel     = 'stylesheet';
		link.type    = 'text/css';
		link.charset = this.charset;
		link.href    = this.base_uri + url;

		document.getElementsByTagName('head')[0].appendChild(link);

		this.styles[this.styles.length] = link;
		return link;
	},

	extend: function(obj) {
		for (var i in obj) this[i] = obj[i];
		return this;
	}
};

//--============================================================================
//-- Initializer
//--============================================================================
with (LXSCart) {
if (!parent || parent == self) { // not available in an frame/iframe
	loadScript('/js/cart_msg.js');
	loadScript('/js/cart_func.js');

	if (typeof JSONScriptRequest == 'undefined') {
		loadScript('/js/jsr_packed.js');
	}

	LXSCart.loadCheckTimer = setInterval(function() {
		if ((typeof JSONScriptRequest != 'undefined') &&
				(typeof jQuery != 'undefined')) {
			clearInterval(loadCheckTimer);

			window.$$ = jQuery;
			if (typeof jQuery._$ != "undefined") window.$ = jQuery._$;

			if ($$.browser.msie) {
				if (document.readyState == 'loaded' ||
						document.readyState == 'complete') {
					return init();
				}
				window.attachEvent('onload', init);
			}
			else {
				$$(init);
			}
		}
	}, 250);
}

LXSCart.init = function() {
	var _self = LXSCart;
	_self.Dialog.init();
	_self.Item.init();
	$$(window).unload(_self.unload);
};

LXSCart.unload = function() {
//	alert('unload');
	var _self = LXSCart;
	_self.Item.remove();
	_self.Dialog.remove();
	$$(_self.styles).remove();
	$$(_self.scripts).remove();
};
} // with (LXSCart) {

//--============================================================================
//-- Item Functions
//--============================================================================
LXSCart.Item = {
	init: function() {
		var _self = this;
		LXSCart.loadStyle('/getcss.php?css=item');
		$$('.LXSCart_Item').each(function() {
			_self.request.call(this, {item_id: this.title});
		});
	},

	request: function(params) {
		var url = '/getitem.php?' + jQuery.param(params);

		$$(this).empty().append('<img src="'+LXSCart.base_uri+'/images/roller.gif" alt="Now Loading..." border="0" />');

		var jsr = new JSONScriptRequest(this);
		jsr.send(LXSCart.base_uri + url, function(json) {
			switch (json.status) {
			case 'ok': break;
			case 'bad item_id':
				$$(this).empty().append(LXSCart.MSG_ITEM_NOT_AVAILABLE);
				return;
			default:
				alert(json.status);
				return;
			}
			$$(this).empty().append(json.html);
		}, 10000);
	},

	remove: function() {
		$$('.LXSCart_Item').remove();
	}
};

//--============================================================================
//-- Dialog Functions
//--============================================================================
LXSCart.Dialog = {
	html: null,

	init: function() {
		LXSCart.loadStyle('/getcss.php?css=dialog');
		var url = '/gettemplate.php?template=dialog';
		var jsr = new JSONScriptRequest(this);
		jsr.send(LXSCart.base_uri + url, function(json) {
			if (json.status != 'ok') {
				alert(json.status);
				return;
			}
			this.html = json.html;
		});
	},

	loading: function() {
		$$('#LXSCDialog').empty().append(this.html);
	},

	remove: function() {
		this.html = null;
	},

	refresh: function() { with (LXSCart) { // used for an event handler
		var $$cover = $$('#LXSCDialog_Cover');
		$$cover.css({
//			'width':  clientWidth() + 'px',
			'height': clientHeight() + 'px',
			'top':    scrollTop() + 'px',
			'left':   scrollLeft() + 'px'
		});
		if ($$.browser.msie) $$cover.css('width', clientWidth() + 'px');

		var $$dialog = $$('#LXSCDialog');

		var width  = clientWidth() - parseInt($$dialog.css('width'));
		var height = clientHeight() - parseInt($$dialog.css('height'));
		var left   = (width > 0 ? width : 0) / 2 + scrollLeft();
		var top    = (height > 0 ? height : 0) / 2 + scrollTop();

		$$dialog.css({'top': top + 'px', 'left': left + 'px'});
	}},

	show: function() {
		$$('<div id="LXSCDialog_Cover" />').appendTo('body');
		var $$cover = $$('#LXSCDialog_Cover');
		$$cover.css('opacity', 0).fadeTo('slow', 0.6);

		$$('<div id="LXSCDialog" />').appendTo('body');
		var $$dialog = $$('#LXSCDialog');
		$$dialog.append(this.html);

		this.refresh();

		$$dialog.fadeIn('slow', function() {
			$$('select').each(function() {
				this.style.display = 'none';
			});
		});

		if (window.opera) this.refresh();

		$$cover.click(this.hide);
		$$(window).resize(this.refresh);
		$$(window).scroll(this.refresh);

		return false;
	},

	hide: function() {
		$$(window).unbind('resize');
		$$(window).unbind('scroll');

		$$('select').each(function() {
			this.style.display = '';
		});

		$$('#LXSCDialog').fadeOut('slow', function() {
			$$('#LXSCDialog').remove();
		});
		$$('#LXSCDialog_Cover').fadeOut('slow', function() {
			$$('#LXSCDialog_Cover').unbind('click').remove();
		});

		return false;
	}
};

//--============================================================================
} // end if (typeof window.LXSCart == 'undefined')
