Object.extend(Element, {
	show : function() {$A(arguments).each(function(i) {
		$(i).style.display = ($(i).tagName.toLowerCase() == 'div' ? 'block' : '');
	});}
});

function $T() {
	var a = [];
	$A(arguments).each(function(i) {
		a.push($A(document.getElementsByTagName(i)));
	}); return(a = a.flatten());
};

var Over = {id: 'tiny-over'}, Load = {id: 'tiny-load'}, Tbox = {id: 'tiny-tbox'};


var Tiny = {
	initialize: function() {
		[Over, Load, Tbox].each(function(i) {
			new Insertion.Bottom($T('body')[0], '<div id="' + i.id + '"></div>');
		});
		Event.observe(document, 'click', Tiny.toggle.bindAsEventListener(Tiny));
	},

	toggle    : function(e) {
		switch(Event.findElement(e, 'a').rel) {
			case 'tiny-hide': Tiny.hide(e); Event.stop(e); break;
			case 'tiny-show': Tiny.show(e); Event.stop(e); break;
			default: return true;
		}
		return(false);
	},

	show      : function(e) {
		/*@cc_on
		$T('select').each(function(i) {
			Element.setStyle(i, {'visibility':'hidden'});
		});
		Tiny.scroll = {x: $T('html').scrollLeft, y: $T('html').scrollTop};
		window.scrollTo(0, 0);
		$T('html', 'body').each(function(i) {
			Element.addClassName(i, 'tiny-ie-hack');
		});
		@*/
		
		Over.show ? Over.show() : Element.show(Over.id);
		new Ajax.Updater(Tbox.id, Event.findElement(e, 'a').href, {
			onCreate  : function() {
				Load.show ? Load.show() : Element.show(Load.id);
			},
			onComplete: function() {
				//alert(Tbox.id);
				Load.hide ? Load.hide() : Element.hide(Load.id);
				Tbox.show ? Tbox.show() : Element.show(Tbox.id);
			},
			evalScripts: true, method: 'get'
		});
	},

	hide      : function(e) {
		/*@
		$T('html', 'body').each(function(i) {
			Element.removeClassName(i, 'tiny-ie-hack');
		});
		window.scrollTo(Tiny.scroll.x, Tiny.scroll.y);
		@*/
		$(Tbox.id).update('');
		Tbox.hide ? Tbox.hide() : Element.hide(Tbox.id);
		Over.hide ? Over.hide() : Element.hide(Over.id);
		/*@
		$T('select').each(function(i) {
			Element.setStyle(i, {'visibility':'visible'});
		});
		@*/
	}
};

/*//create onDomReady Event
window.onDomReady = DomReady;

//Setup the event
function DomReady(fn)
{
	//W3C
	if(document.addEventListener)
	{
		document.addEventListener("DOMContentLoaded", fn, false);
	}
	//IE
	else
	{
		document.onreadystatechange = function(){readyState(fn)}
	}
}

//IE execute function
function readyState(fn)
{
	//dom is ready for interaction
	if(document.readyState == "interactive")
	{
		fn();
	}
}

//Once you have included the above code in your page you can use it in a similar manner as below.


//execute as soon as DOM is loaded
window.onDomReady(onReady);

//do on ready
function onReady()
{
	Tiny.initialize;
	tiny.show();
	alert("The DOM is ready!");
	//Event.observe(window,'load',Tiny.initialize);
	
}
*/



//document.addEventListener('DOMContentLoaded',Tiny.initialize,false);
window.onload = Event.observe(window,'load',Tiny.initialize);


