Event.observe(window, 'load', function() {
/*----------------------------------------------------------
| mg.init.js
+-----------------------------------------------------------
| post-load settings and initialization
+-----------------------------------------------------------
| NOTES:
| + because of the way shadowbox handles inline content - uses innerHTML
|   all element event initialization must occur in the Shadowbox.onFinish() handler.
|   This especially sucks because of IE's inability to use any listener adding method.
|   Event listeners, setting "on" event handlers, etc. all fail.
|   + The only work around is extracting the innerHTML and using replace() to
|     insert inline event callers and then replace the innerHTML.
+---------------------------------------------------------*/

/*----------------------------------------------------------
| initialization
+---------------------------------------------------------*/
if ($('mg_cart-form')) mg.cart.init();
if ($('mg_iteminfo')) mg.item.init();
if ($('mg_select-form')) mg.select.init();
if ($('mg_uketori-form')) mg.uketori.init();
if ($('mg_showcase')) mg.showcase.init();

/*----------------------------------------------------------
| "Shadowbox" popup viewer initialization
+---------------------------------------------------------*/
if ($$('a[rel^=shadowbox]').length) {

	//-- ADD CUSTOM METHODS
	Shadowbox.toggleNav_cust = function(id, on) { //-- [see:"shadowbox.js"] altered original script to call this
		var lbl = 'shadowbox_nav_' , elm;
		switch(Shadowbox.CONTENT_ID) {
			case 'image':
			case 'details': switch(id) {
				case 'next':
				case 'previous':
					if (elm = $(lbl + id + '_X')) elm[(on) ? 'hide' : 'show']();
			}
		}
		if (elm = $(lbl + id)) elm[(on) ? 'show' : 'hide']();
	};

	Shadowbox.open_cust = function(id) {
		Shadowbox.CONTENT_ID = id;
		switch(id) {
/*
			case 'cart':
				$('shadowbox_cart_nav').show();
				$('shadowbox_counter').hide();
				mg.cart.init();
				break;
*/
		}
		if ($env.ie) $('shadowbox_overlay').style.filter = 'alpha(opacity=70)';
	};

	Shadowbox.close_cust = function() {
		['next', 'previous', 'play', 'pause', 'close'].each(function(id) {
			var btn = $('shadowbox_nav_' + id + '_X');
			if (btn) btn.hide();
		});
		$('shadowbox_cart_nav').hide();
		$('shadowbox_counter').show();
		Shadowbox.CONTENT_ID = '';
	};

	Shadowbox.init({
		animSequence: 'sync', // 'wh'
		resizeDuration: 0.6,
		initialWidth: 240,
		initialHeight: 240,
		counterType: '',
		slideshowDelay: 0,
		onOpen: function() { Shadowbox.open_cust('image'); },
		onClose: Shadowbox.close_cust
	});

	//-- init select page item details
	if ($('mg_nav-select')) Shadowbox.setup($$('#mg_nav-select a'), {
		player: 'iframe',
		width: 640,
		onOpen: function() { Shadowbox.open_cust('details'); },
		onClose: Shadowbox.close_cust
	});

/*
	if ($('mg_subcart-edit')) Shadowbox.setup($$('#mg_subcart-edit a')[0], {
		width: 400,
		height: 600,
		modal: true,
		onOpen: function() { Shadowbox.open_cust('cart'); },
		onFinish: function() {
			mg.cart.init_sb();
		},
		onClose: Shadowbox.close_cust
	});
	if (mg.btns) mg.btns.init($('shadowbox_info_inner')); //-- render buttons
*/

}

/*----------------------------------------------------------
| ie fixes
+---------------------------------------------------------*/
if (window.isIE) mg.fixIE.init();

/*----------------------------------------------------------
| complete initialization
+---------------------------------------------------------*/
mg.postinit.call();
});

