/*********************\
  GSSI Base framework
\*********************/

if (! GSSI) { var GSSI = {}; };
if (! GSSI.Base ) { GSSI.Base = {}; };

GSSI.$ = function (element) {
	if (arguments.length > 1) {
		elements = [];
		for (var i = 0; i < arguments.length; i++)
			elements.push(GSSI.$(arguments[i]));
		return elements;
	}
	if (element instanceof Array) {
		elements = [];
		for (var i = 0; i < element.length; i++)
			elements.push(GSSI.$(element[i]));
		return elements;
	}
	if (typeof element == 'string')
		element = document.getElementById(element);
	return GSSI.Base.WrapElement(element);
}

if (! GSSI.ElementPrototype ) { GSSI.ElementPrototype = new Object; };

GSSI.Base.Extend = function(destination, source) { // Extend: all properties in source copied to dest
	destination = destination || {};
	source = source || {};
	for (var property in source) {
		destination[property] = source[property];
	}
	return destination;
}

GSSI.Base.DoNothing = function() {};

GSSI.Base.Include = function(destination, source) { // Include: all properties in source NOT ALREADY PRESENT copied to dest
	destination = destination || {};
	source = source || {};
	for (var property in source) {
		if ((destination[property] === null) || (destination[property] === undefined)) {
			destination[property] = source[property];
		}
	}
	return destination;
}

GSSI.Base.Clone = function(source) {
	return GSSI.Base.Extend({},source);
}

GSSI.Base.HasProperty = function ( object, propname ) {
	return ( object && (typeof(object[propname]) != "undefined"));
}

GSSI.Base.WrapElement = function( element ) {
	if (! element) { return element; }
	if (element.__gssi) { return element; }
	GSSI.Base.Extend( element, GSSI.ElementPrototype );
	element.__gssi = true;
	return element;
}

GSSI.Class = function( ) {
	var j = function() {
		if(this.initialize) {
			this.initialize.apply(this, arguments);
		};
	};
	j.prototype = {};

	GSSI.Base.Extend( j, GSSI.Class.prototype );
	for(var i=0; i<arguments.length; i++) {
		GSSI.Base.Extend( j.prototype, arguments[i] );
	}

	return j;
}

GSSI.Class.prototype = {
	Inherits: function( ) {		
		for(var i=0; i<arguments.length; i++) {
			GSSI.Base.Include( this.prototype, arguments[i].prototype );
			GSSI.Base.Include( this, arguments[i] );
		}
	},
	
	Static: function() {
		for(var i=0; i<arguments.length; i++) {
			GSSI.Base.Extend( this, arguments[i] );
		}
	},
	
	Instance: function() {
		for(var i=0; i<arguments.length; i++) {
			GSSI.Base.Extend( this.prototype, arguments[i] );
		}
	}
};

GSSI.Base.UID = function () {
	return("_gssiuid" + (GSSI.Base.UID.counter++) + "_" );
};

GSSI.Base.UID.counter = 0;

GSSI.Base.Extend( GSSI.ElementPrototype,  {
	getDocument: function() {
		if( this.tagName.toLowerCase() != 'iframe') { return null; }
		try {
			return element.contentDocument || element.document || element.contentWindow.document;
		} catch (e) {
			return null;	
		}
	}
});
