// moobase.js
// some javascripts for Cosmos Motion site

// min-width emulator for IE
function minWidth(element, w)
{
	var elt = $(element);
	if(document.documentElement.clientWidth < w)
	{
		elt.setStyle("width", w + "px");
	}
	if(document.documentElement.clientWidth > w)
	{
		elt.setStyle("width", "100%");
	}
}

// browser detector
var Engine = {
	detect: function() {
		var UA = navigator.userAgent;
		this.isKHTML = /Konqueror|Safari|KHTML/.test(UA);
		this.isGecko = (/Gecko/.test(UA) && !this.isKHTML);
		this.isOpera = /Opera/.test(UA);
		this.isMSIE  = (/MSIE/.test(UA) && !this.isOpera);
		this.isMSIE7 = this.isMSIE && (/MSIE 7\./.test(UA) && !this.isOpera);
	}
}
Engine.detect();

// init page content
window.addEvent('domready', function()
{
	// poor little IE 6 doesn't support :hover; let's help him 
	if(Engine.isMSIE && !Engine.isMSIE7)
	{
		minWidth($("main-heading"), "960");
		minWidth($("content"), "960");
		minWidth($("main-footer"), "960");
				
		var buttons = $$("#main-heading #heading-nav li a");
		buttons.each(function(item, index)
		{
			if(item.hasClass("on"))
				return;
				
			// Dear IE, would you be kind enough to update CSS
			// (it's a great time now, really)
			item.addEvent('mouseover', function(event)
			{		
				item.getChildren("span").each(function(i, index)
				{
					i.setStyles(
					{
						backgroundPosition: "0px -70px",
						cursor: "pointer"
					});
				});				
			});
			item.addEvent('mouseout', function(event)
			{		
				item.getChildren("span").each(function(i, index)
				{
					i.setStyles(
					{
						backgroundPosition: "0px 0px",
						cursor: "default"
					});
				});				
			});
			item.addEvent('mousedown', function(event)
			{		
				item.getChildren("span").each(function(i, index)
				{
					i.setStyles(
					{
						backgroundPosition: "0px -140px",
						cursor: "pointer"
					});
				});				
			});
		});
		window.addEvent('resize', function(event)
		{
			minWidth($("main-heading"), "960");
			minWidth($("content"), "960");
			minWidth($("main-footer"), "960");
		});
	}
});
