// requires yui.dom

if (typeof(ARK) === 'undefined')
	var ARK = {};

if (!console) {
    var console = {log: function(){}};
}

ARK.utils = {
	createTimeStamp: function() {
		var now = new Date();
		return now.getHours()+''+now.getMinutes()+''+now.getSeconds()+''+now.getMilliseconds();
	}
}

ARK.gui = {
	attachOpenInNewWindow: function(classname) {
		if (!classname || classname==null)
			var classname = 'new-window';
		
		var links = YAHOO.util.Dom.getElementsByClassName(classname, 'a');
		
		for (i=0; i<links.length; i++) {
			// TODO: how to register 'return false' on click action with addListener ??
			// YAHOO.util.Event.addListener(links[i], 'click', function() {ARK.gui.openInNewWindow(this.href); return false;});
			links[i].onclick = function(){ ARK.gui.openInNewWindow(this.href); return false; };
		}
	},
	
	openInNewWindow: function(uri) {
		window.open(uri);
		
	},
	
	// IE6 support for li:hover
	attachHoverEvents: function(id) {
		if (document.getElementById(id))
	   		var items = document.getElementById(id).getElementsByTagName("li");
		else
			return false;
				
		for (i=0; i<items.length; i++) {
			if (items[i].className.indexOf('parent')!=-1) {
				items[i].onmouseover=function() {
					YAHOO.util.Dom.addClass(this, 'hovered');
				}
				items[i].onmouseout=function() {
					YAHOO.util.Dom.removeClass(this, 'hovered');
				}
			}
		}
	}
}

ARK.status = {
	xhrs: Array,
	
	createStatusObj: function(el, count) {
		id = YAHOO.util.Dom.generateId(el, 'xhr_');
		
		this.xhrs[id] = (count == null) ? 1 : count;
		return id;
	},
	
	startLoadingStatus: function(el, count) {
		if (!this.xhrs[el.id])
			this.createStatusObj(el, count);
		
		YAHOO.util.Dom.addClass(el, 'loading');
	},
	
	stopLoadingStatus: function(el) {
		if (!this.xhrs[el.id])
			return false;
	
		this.xhrs[el.id]--;
		if (this.xhrs[el.id]<=0) {
			this.xhrs[el.id] = null;
			YAHOO.util.Dom.removeClass(el, 'loading');
		}
	}
};
