
/*
PLEASE DO NOT MAKE MODIFICATIONS TO THIS FILE TO ACCOMODATE FEATURES OR BUG FIXES THAT ARE NOT RELEVANT ACCROSS ALL SITES.
ALL CHANGES SHOULD BE EXPLAINED IN THE CHANGE HISTORY AND THE REVISION NUMBER SUBSEQUENTLY INCREMENTED.
*/

/*
--------------------------------------------------------------------------------------------------------------------------
StarmindHelper
Provides general helper methods shared between all starmind javascript libraries.

Version: 1.0 (Rev. 001)
Required libraries: jQuery 1.4


Change history:
--------------------------------------------------------------------------------------------------------------------------

1.0.001: Code moved to separate library.
*/

var StarmindHelper = {
	CssStringToObject: function(css) {
		var r = new RegExp('\s*([^:]+?)\s*:\s*([^;]+?)\s*(?:;|$)', "ig");
		var cssobj = new Object(), m = null;

		while((m = r.exec(css)) != null) cssobj[m[1]] = m[2];

		return cssobj;
	},
	ObjectToCssString: function(obj) {
		if(!obj || typeof(obj) != "object") return obj;
	
		var tmp = new Array();
		for(var k in obj) tmp.push(k + ": " + obj[k]);

		return tmp.join("; ");
	},
	MergeAttrObject: function() {
		var sto = function(o) {
			for(var i in o) if(o[i] && typeof(o[i]) == "object") sto.call(this, o[i]);
			if(typeof(o["style"]) == "string") o["style"] = this.CssStringToObject(o["style"]);
			return o;
		};
		
		var ots = function(o) {
			for(var i in o) if(o[i] && typeof(o[i]) == "object") ots.call(this, o[i]);
			if(typeof(o["style"]) == "object") o["style"] = this.ObjectToCssString(o["style"]);
			return o;
		};
		
		var args = [];
		for(var at = 0; at < arguments.length; at++)
			if(typeof(arguments[at]) == "object") {
				args.push(sto.call(this, arguments[at]));
			}

		var merged = jQuery.extend.apply(jQuery.extend, jQuery.merge([ true, {}], args));
		if(merged != null) merged = ots.call(this, merged);

		return merged;
	},
	MergeObject: function() {
		var args = [];
		for(var i = 0; i < arguments.length; i++) if(typeof(arguments[i]) == "object") args.push(arguments[i]);
	
		return jQuery.extend.apply(jQuery.extend, jQuery.merge([ true, {}], args));
	}
};
