
// ----------------------------------------------------------------------------
// Use a stub object to prevent errors in IE from using console.log() etc.
// ----------------------------------------------------------------------------

(function(){
	if (!('console' in window) || !('firebug' in console)) {
		var names = ['log','debug','info','warn','error','assert','dir','dirxml','group','groupEnd','time','timeEnd','count','trace','profile','profileEnd'];
		window.console = window.console || {};
		for (var i=0; i<names.length; ++i) {
			window.console[names[i]] = window.console[names[i]] || function(){};
		}
	}
})();


// ----------------------------------------------------------------------------
// We sometimes need to give IE6 special treatment, so add a test for it.
// ----------------------------------------------------------------------------

if (typeof Prototype.Browser.IE6 == 'undefined') {
	Prototype.Browser.IE6 = (Prototype.Browser.IE && /MSIE 6/i.test(navigator.userAgent));
}


// ----------------------------------------------------------------------------
// Instantly hide elements with a class of 'jsHide' (for JS-fallback content)
// ----------------------------------------------------------------------------

function addCss(cssCode) {
	// See: http://yuiblog.com/blog/2007/06/07/style/
	var styleElement = document.createElement("style");
	styleElement.type = "text/css";
	if (styleElement.styleSheet) {
		styleElement.styleSheet.cssText = cssCode;
	} else {
		styleElement.appendChild(document.createTextNode(cssCode));
	}
	document.getElementsByTagName("head")[0].appendChild(styleElement);
}

addCss(".jsShowBlock, div.jsShow, .jsShow 	{ display:block !important; }");
addCss(".jsShowInline, span.jsShow 			{ display:inline !important; }");
addCss(".jsHide 							{ display:none; }");


// ----------------------------------------------------------------------------
// Extensions to the prototype framework (inspired by jQuery 1.2.3)
// Allows for showing and hiding of elements that have been hidden via an 
// external CSS declaration, rather than an inline "display:none;"
// ----------------------------------------------------------------------------

sense.elementMethods = {
	visible: function(element) {
		return $(element).getStyle('display') != 'none';
	},
	show: function(element){
		$(element).setStyle({ display: $(element).oldblock || '' });
		if ($(element).getStyle('display') == 'none') {
			var newElement = document.createElement($(element).tagName);
			$$('body').first().insert({bottom: newElement});
			$(element).setStyle({ display: $(newElement).getStyle('display')});
			$(newElement).remove();
			if ($(element).getStyle('display') == 'none') $(element).setStyle({ display: 'block'});
		}
		return element;
	},
	hide: function(element){
		$(element).oldblock = $(element).oldblock || $(element).getStyle("display");
		$(element).setStyle({display: 'none'});
		return element;
	}
};


// ----------------------------------------------------------------------------
// A few core UI classes applied directly to Element so we can call them as 
// short-hand methods on the object, i.e. myElement.tween({ ...options... });
//
// (We also provide for these classes being instantiated in a widget-y fashion)
// ----------------------------------------------------------------------------

$A(['Tween','Dragger','Dropper','Sortable']).each(function(klassName){
	var methodName = klassName.toLowerCase();
	sense.elementMethods[methodName] = function(element, options) {
		if (typeof sense.ui.effect[klassName] != 'undefined') {
			return element[klassName] = new sense.ui.effect[klassName](element, options);
		} else {
			return element;
		}
	}

	sense.ui.widget[klassName] = sense.ui.effect[klassName];
	sense.ui.widget.Manager.register(klassName);
});

Element.addMethods(sense.elementMethods);
