
/*******************************************************************************************************************
  * CMS objects defined below
  *******************************************************************************************************************/

var _glbAspects 	= new Array();
var _glbAspectNames = new Array();

function sisSite(_xml)
{
	var _pages 		= new Array();
	var _properties	= new Array();
	
	// public function definitions
	this.GetPage			= _getPage;
	this.GetProperty		= _getProperty;
	
	var _pageNode = _xml.firstChild;
	while(_pageNode != null)
	{
		if(_pageNode.nodeName == 'page')
		{
			_pages[_pages.length] = new sisPage(_pageNode);
		}

		if(_pageNode.nodeName == 'properties')
		{
			_processProperties(_pageNode);
		}
		
		_pageNode = get_nextsibling(_pageNode);
	}

	function _processProperties(_propertiesXML)
	{
		var _property = _propertiesXML.firstChild;
		while(_property != null)
		{
			_properties[_properties.length] = new sisProperty(_property);
			_property = get_nextsibling(_property);
		}
		
	}
	
	function _getProperty(_name)
	{
		for(var i=0; i<_properties.length; i++)
		{
			if(_properties[i].Name == _name) return _properties[i];
		}
		
		return "";
	}
	
	function _getPage(_id)
	{
		for(var i=0; i<_pages.length; i++)
		{
			if(_pages[i].GetID() == _id) return _pages[i];
		}
		
		return null;
	}
		
}

function sisPage(_xml)
{
	// private variables
	var _objects 	= new Array();
	var _styles		= new Array();
	var _properties	= new Array();
	var _pageXML	= _xml;

	this.GetID					= _getID;
	this.RenderToBody			= _renderToBody;
	this.RenderBodyTemplate		= _renderBodyTemplate;
	this.GetProperty			= _getProperty;
	this.GetContent				= function _getContent() { return ''; }
	this.GetStyles				= function _getStyles() { return _styles; }
	
	var _objectNode = _xml.firstChild;
	while(_objectNode != null)
	{
		switch(_objectNode.nodeName)
		{
		case 'object':
			_objects[_objects.length] = new sisObject(_objectNode);
			break;
			
		case 'style':
			_processStyle(_objectNode);
			break;
			
		case 'properties':
			_processProperties(_objectNode);
			break;
			
		default:
			break;
			
		}
		
		_objectNode = get_nextsibling(_objectNode);
	}
	
	function _getID()
	{
		return _pageXML.getAttribute("id");
	}
	
	function _renderToBody()
	{
		
		for(var i=0; i< _objects.length; i++)
		{
			var _str 		= _objects[i].Render();
			var _hotspot	= _objects[i].GetTarget();
			
			if(_str==null || _str=='null') continue;
			
			document.getElementById(_hotspot).innerHTML += _str;
		}
	}
	
	function _renderBodyTemplate()
	{
		var _aspect		= _getProperty('aspect').Value;
		var _ajax 		= new sisAJAXConnector();
		
		_ajax.open("GET", "templates/" + _aspect + ".aspect", false);
		_ajax.send(null);

		_aspectObj = new sisAspect(new sisXMLDocument(_ajax.responseText), this);
		
		// set the page level background colour
		try {
			_style = _getStyle('background-color').Value;
			document.getElementById("body").style.backgroundColor = _style;
		} catch(e) {}
		
		document.getElementById("body").innerHTML = _aspectObj.Render();
	}
	
	function _processStyle(_styleXML)
	{
		var _style = _styleXML.firstChild;
		while(_style != null)
		{
			if(_style.nodeType != 1) { _style = get_nextsibling(_style); continue; }
			
			_styles[_styles.length] = new sisStyle(_style);
			_style = get_nextsibling(_style);
		}
		
	}
	
	function _processProperties(_propertiesXML)
	{
		var _property = _propertiesXML.firstChild;
		while(_property != null)
		{
			_properties[_properties.length] = new sisProperty(_property);
			_property = get_nextsibling(_property);
		}
		
	}
	
	function _getProperty(_name)
	{
		for(var i=0; i<_properties.length; i++)
		{
			if(_properties[i].Name == _name) return _properties[i];
		}
		
		return "";
	}
	
	function _getStyle(_name)
	{
		for(var i=0; i<_styles.length; i++)
		{
			if(_styles[i].Name == _name) return _styles[i];
		}
		
		return "";
	}
}

function sisStyle(_styleNode)
{
	this.XML			= _styleNode;
	this.Name			= _styleNode.nodeName;
	this.Value			= (_styleNode.firstChild!=null)? _styleNode.firstChild.nodeValue : _styleNode.nodeValue;
	
	try {
		this.Units		= (_styleNode.getAttribute("units")!=null)? _styleNode.getAttribute("units") : '';
	} catch(e) {
		this.Units		= '';
	}
	
	try {
		var _encoding 	= _styleNode.getAttribute("encoding");
		if(_encoding!=null)
		{
			switch(_encoding)
			{
				case 'base64':
					this.Value = decode64(this.Value);
					break;
					
			}
		}
	} catch(e) {
	}
}

function sisProperty(_propertyNode)
{
	if(_propertyNode == null) return;
	
	this.XML			= _propertyNode;
	this.Name			= _propertyNode.nodeName;
	this.Value			= (_propertyNode.firstChild!=null)? _propertyNode.firstChild.nodeValue : _propertyNode.nodeValue;
}

function sisObject(_xml)
{
	var _styles		= new Array();
	var _properties	= new Array();
	var _content	= '';
	var _object		= null;
	
	// public functions
	this.Render				= _render;
	this.GetProperty		= _getProperty;
	this.GetStyle			= _getStyle;
	this.GetTarget			= _getTarget;
	this.GetProperties		= function _getProperties() { return _properties; }
	this.GetStyles			= function _getStyles() { return _styles; }
	this.GetContent			= function _getContent() { return _content; }
	this.GetObject			= function _getObject() { return _object; }

	var _objectNode = _xml.firstChild;
	while(_objectNode != null)
	{
		switch(_objectNode.nodeName)
		{
		case 'content':
			_content = _objectNode.firstChild.nodeValue;
			break;
			
		case 'style':
			_processStyle(_objectNode);
			break;
			
		case 'properties':
			_processProperties(_objectNode);
			break;
			
		default:
			break;
			
		}
		
		_objectNode = get_nextsibling(_objectNode);
	}

	switch(_getProperty('type').Value)
	{
		case 'text': 				_object = new sisObjectText(this); break;
		case 'media': 				_object = new sisObjectMedia(this); break;
		case 'subject':				_object = new sisObjectSubject(this); break;
		case 'blog':				_object = new sisObjectBlog(this); break;
		case 'calendar':			_object = new sisObjectCalendar(this); break;
		case 'project':				_object = new sisObjectProject(this); break;
		case 'person':				_object = new sisObjectPerson(this); break;
		case 'group':				_object = new sisObjectGroup(this); break;
		case 'groups':				_object = new sisObjectGroup(this); break;
		case 'feed':				_object = new sisObjectFeed(this); break;
		case 'navigation':			_object = new sisObjectNavigation(this); break;
		case 'hotspot':				_object = new sisObjectHotspot(this); break;
		case 'comment':				_object = new sisObjectComment(this); break;
		case 'category':			_object = new sisObjectCategory(this); break;
		case 'chart':				_object = new sisObjectChart(this); break;
		default:					break;
	}
	
	function _processStyle(_styleXML)
	{
		var _style = _styleXML.firstChild;
		while(_style != null)
		{
			if(_style.nodeType != 1) { _style = get_nextsibling(_style); continue; }
			
			_styles[_styles.length] = new sisStyle(_style);
			_style = get_nextsibling(_style);
		}
		
	}
	
	function _processProperties(_propertiesXML)
	{
		var _property = _propertiesXML.firstChild;
		while(_property != null)
		{
			_properties[_properties.length] = new sisStyle(_property);
			_property = get_nextsibling(_property);
		}
		
	}
	
	function _getProperty(_name)
	{
		for(var i=0; i<_properties.length; i++)
		{
			if(_properties[i].Name == _name) return _properties[i];
		}
		
		return "";
	}
	
	function _getStyle(_name)
	{
		for(var i=0; i<_styles.length; i++)
		{
			if(_styles[i].Name == _name) return _styles[i];
		}
		
		return "";
	}
	
	function _getTarget()
	{
		return _getProperty('target').Value;
	}
	
	function _render()
	{
		if(_object==null) return '';
		return _object.Render();
	}
}

function sisObjectText(_obj)
{
	var _parent		= _obj;
	
	this.Render		= _render;
	
	function _render()
	{
		var _aspect = _parent.GetProperty('aspect').Value;

		if(_aspect == 'none')
		{
			return _renderWithoutAspect();
		} else
		{
			return _renderWithAspect();
		}
	}
	
	function _renderWithoutAspect()
	{
		var _styles = _parent.GetStyles();
		
		var _str	 = '<div style="' + _createStyle();
		_str 		+= '">';
		_str 		+= _obj.GetProperty('content').Value;
		_str 		+= '</div>';

		return _str;
	}
	
	function _renderWithAspect()
	{
		// we need to fetch the aspect and process it
		var _aspect		= _obj.GetProperty('aspect').Value;
		var _ajax 		= new sisAJAXConnector();
		
		_ajax.open("GET", "aspects/text/" + _aspect + ".aspect", false);
		_ajax.send(null);

		_aspectObj = new sisAspect(new sisXMLDocument(_ajax.responseText), _obj);
		
		return _aspectObj.Render();
	}
	
	function _createStyle()
	{
		var _styles = _obj.GetStyles();
		var _str	= '';
		
		for(var i=0; i<_styles.length; i++)
		{
			try {
				_str += _styles[i].Name + ':' + _styles[i].Value + _styles[i].Units;
				_str += ';';
			} catch(e) { continue; }
		}
		
		return _str;
	}	
	
}

function sisObjectMedia(_obj, _field)
{
	var _parent		= _obj;
	var _fieldName	= _field;
	
	if(_fieldName == null || _fieldName == '' || 
		_fieldName == 'undefined' || _obj.GetProperty(_fieldName)=='') _fieldName = 'media_file';

	if(_fieldName != 'media_file') _obj.SetProperty('media_file', _obj.GetProperty(_fieldName).Value);
	
	this.Render		= _render;
	
	function _render(_forceAspect)
	{
		var _aspect = _parent.GetProperty('aspect').Value;
		
		if(_forceAspect!=null)
		{
			 _aspect = _forceAspect;
		}
		
		if(_aspect == 'none')
		{
			return _renderWithoutAspect();
		} else
		{
			return _renderWithAspect(_aspect);
		}
	}
	
	function _renderWithoutAspect()
	{
		var _styles = _parent.GetStyles();
		
		var _str	 = '<div style="' + _createStyle();
		_str 		+= '"><img src="';
		_str		+= _obj.GetProperty('media_file').Value;
		_str 		+= '"/></div>';
		
		return _str;
	}
	
	function _renderWithAspect(_forceAspect)
	{
		// we need to fetch the aspect and process it
		var _aspect		= _parent.GetProperty('aspect').Value;
		var _ajax 		= new sisAJAXConnector();
		var _format		= _calcFormat(_parent.GetProperty(_fieldName).Value);
		
		if(_format=="default" && (_parent.GetProperty('media_format').Value!=null && _parent.GetProperty('media_format').Value!='')) _format = _parent.GetProperty('media_format').Value;
		
		if(_forceAspect!=null)
		{
			 _aspect = _forceAspect;
		}

		var _aspectName = "aspects/media/" + _aspect + ".aspect";
		var _response	= null;
		
		for(var i=0; i<_glbAspectNames.length; i++)
		{
			if(_glbAspectNames[i] == _aspectName)
			{
				_response = _glbAspects[i];
				break;
			}
		}
		
		if(_response == null)
		{
			_ajax = new sisAJAXConnector();
			_ajax.open("GET", GetURL(_aspectName), false);
			_ajax.send(null);

			_response = _ajax.responseText;

			_glbAspectNames[_glbAspectNames.length] = _aspectName;
			_glbAspects[_glbAspects.length] = _response;
		}
		
//		_ajax.open("GET", "aspects/media/" + _aspect + ".aspect", false);
//		_ajax.send(null);

		_aspectObj = new sisAspect(new sisXMLDocument(_response), _parent, _format, false);
		
		var _str = _aspectObj.Render();

		if(_parent.GetProperty('linktype').Value=='page')
		{
			_str = '<a href="viewer.phtml?' + _parent.GetProperty('linkparameters').Value + '">' + _str + '</a>';
		}
		
		return _str;
	}

	function _calcFormat(_filename)
	{
		var _parts	= _filename.split('.');
		var _part	= _parts[_parts.length-1];
		
		switch(_part.toLowerCase())
		{
			case 'swf':
				return 'flash';
			
			case 'mov':
			case 'psd':
			case 'avi':
			case '3gp':
			case '3gpp':
			case 'mp4':
			case 'mpg4':
			case 'mp3':
			case 'mpeg-4':
			case 'dv':
			case 'flc':
			case 'qtl':
			case 'pano':
			case 'mpg':
			case 'mpeg':
			case 'sdp':
			case 'rtsp':
			case 'rts':
			case 'aif':
			case 'aiff':
			case 'aifc':
			case 'cdda':
			case 'mid':
			case 'midi':
			case 'm4a':
			case 'wav':
			case 'sd2':
				return 'quicktime';
				
			default:
				return 'default';
		}
	}
		
	function _createStyle()
	{
		var _styles = _obj.GetStyles();
		var _str	= '';
		
		for(var i=0; i<_styles.length; i++)
		{
			try {
				_str += _styles[i].Name + ':' + _styles[i].Value + _styles[i].Units;
				_str += ';';
			} catch(e) { continue; }
		}
		
		return _str;
	}	
}

function sisObjectSubject(_obj)
{
}

function sisObjectBlog(_obj)
{
	var _parent					= _obj;
	var _properties				= new Array();
	
	this.Render					= _render;
	this.GetStyle				= _getStyle;
	this.GetProperty			= _getProperty;
	this.GetContent				= _getContent;
	this.GetStyles				= _getStyles;
	this.SetMediaProperties		= _setMediaProperties;

	function _getStyles()
	{
		return _parent.GetStyles();
	}
	
	function _getContent()
	{
		return _parent.GetContent();
	}
	
	function _getStyle(_name)
	{
		return _parent.GetStyle(_name);
	}
	
	function _getProperty(_name)
	{
		for(var i=0; i<_properties.length; i++)
		{
			if(_properties[i].Name == _name) return _properties[i];
		}
		
		return "";
	}
	
	function _setMediaProperties(_props)
	{
		var _parts = _props.split('&');
		for(var i=0; i<_parts.length; i++)
		{
			var _prop = _parts[i].split('=');
			var _mediaProp = new sisProperty();
			_mediaProp.Name = _prop[0];
			_mediaProp.Value = _prop[1];
			
			_properties[_properties.length] = _mediaProp;
		}
	}
	
	function _render()
	{
		var _aspect = _parent.GetProperty('aspect').Value;
		
		if(_aspect == 'none')
		{
			return _renderWithoutAspect();
		} else
		{
			return _renderWithAspect();
		}
	}
	
	function _renderWithoutAspect()
	{
		var _styles = _parent.GetStyles();
		
		var _str	 = '<div style="' + _createStyle();
		_str 		+= '">';
		_str 		+= _parent.GetContent();
		_str 		+= '</div>';
		
		return _str;
	}

	function _renderPart(_part, _aspect)
	{
		var _aspectName = "aspects/blog/" + _aspect + ".aspect";
		var _ajax		= null;
		var _response	= null;
		
		for(var i=0; i<_glbAspectNames.length; i++)
		{
			if(_glbAspectNames[i] == _aspectName)
			{
				_response = _glbAspects[i];
				break;
			}
		}
		
		if(_response == null)
		{
			_ajax 		= new sisAJAXConnector();
			
			_ajax.open("GET", _aspectName, false);
			_ajax.send(null);
			
			_response = _ajax.responseText;
			
			_glbAspectNames[_glbAspectNames.length] 	= _aspectName;
			_glbAspects[_glbAspects.length] 			= _response;
		}

		// create all the property objects
		_processProperties(_part.getElementsByTagName('properties')[0].firstChild);
		
		// now run the aspect processor
		var _aspectObj = new sisAspect(new sisXMLDocument(_response), _parent.GetObject());
		
		var _rendered = _aspectObj.Render();

		return _rendered;
	}
	
	function _renderWithAspect()
	{
	
		var _blogXML		= _fetchBlog();
		var _blogDocument 	= new sisXMLDocument(_blogXML);
		var _str			= '';
		var _blogs 			= _blogDocument.getElementsByTagName('blog');
		var _cnt			= 0;
		
		for(var b=0; b < _blogs.length; b++)
		{
			var _blog = _blogs[b];
			
			if(_parent.GetProperty('show_blog').Value*1 != 0)
			{
				var _aspect = _parent.GetProperty('aspect').Value;
				document.getElementById(_parent.GetProperty('target').Value).innerHTML += _renderPart(_blog, _aspect);
			}
			
			// now we need to process each blog_entry in the response
			var _entries = _blog.getElementsByTagName('blog_entry');

			for(var e=0; e<_entries.length; e++)
			{
				var _entry			= _entries[e];
				var _aspect			= _determineAspect(_parent.GetProperty('secondary_aspect').Value, _cnt, _entries.length);
				var _target 		= _determineTarget(_parent.GetProperty('secondary_target').Value, _cnt, _entries.length, _parent.GetProperty('orientation').Value);
				
				document.getElementById(_target).innerHTML += _renderPart(_entry, _aspect);
				
				_cnt++;
			}
		}
		
		return null;
	}
	
	function _determineTarget(_targetlist, _index, _totalentries, _orientation)
	{
		var _targets = _targetlist.split(',');
		
		if(_targets.length == 1 || _index == 0) 	return _targets[0].split('!')[0];
		
		var _cnt 			= _index + 1;
		var _flexTargets	= new Array();
		
		for(var i=0; i<_index; i++)
		{
			var _targetCnt 	= 0;
			for(var a=0; a<_targets.length; a++)
			{
				var _target = _targets[a];
				var _parts	= _target.split('!');
				
				if(_parts.length == 1)
				{
					_targetCnt++;
					_flexTargets[_flexTargets.length] = _target;
				}
				
				_targetCnt += _parts[1]*1;

				if(_targetCnt >= _cnt) return _parts[0];
			}
		}
		
		_target = _index%_flexTargets.length;
		return _flexTargets[_target].split('!')[0];
	}
	
	function _determineAspect(_aspectlist, _index, _totalentries)
	{
		var _aspects = _aspectlist.split(',');

		if(_aspects.length == 1 || _index ==0 ) 	return _aspects[0].split('!')[0];
		
		// all other entries, we need to figure out which aspect to use
		var _cnt 			= _index + 1;
		
		for(var i=0; i<_index; i++)
		{
			var _aspectCnt 	= 0;
			for(var a=0; a<_aspects.length; a++)
			{
				var _aspect = _aspects[a];
				var _parts	= _aspect.split('!');
				
				if(_parts.length == 1) return _parts[0];
				
				_aspectCnt += _parts[1]*1;

				if(_aspectCnt >= _cnt) return _parts[0];
			}
		}
	}
	
	function _fetchBlog()
	{
		var _ajax 			= new sisAJAXConnector();
		var _fetch_by		= _expandValue(_parent.GetProperty('fetch_by').Value);
		var _showby			= _expandValue(_parent.GetProperty('show_by').Value);
		var _componentid	= _expandValue(_parent.GetProperty('componentid').Value);
		var _show_entries	= _parent.GetProperty('show_entries').Value;
		var _url			= "";
		
		switch(_fetch_by)
		{
			case 'blog_entry':
				_url = "../xml/FetchBlogEntries.php?ShowBy=" + _showby + '&ComponentID=' + _componentid + '&ShowEntries=' + _show_entries;
				break;
				
			default:
				_url = "../xml/FetchBlog.php?ShowBy=" + _showby + '&ComponentID=' + _componentid + '&ShowEntries=' + _show_entries;
		}
		
		_ajax.open("GET", _url, false);
		_ajax.send(null);

		return _ajax.responseText;
	}
	
	function _expandValue(_value)
	{
		if(_value.charAt(0)!= '|') return _value;
		
		var _MasterParts	= _value.split('|');			// get the bit in the middle
		var _parts			= _MasterParts[1].split('.');	// split the bit in the middle again
		
		switch(_parts[0])
		{
			case 'get':
			try {
				return GetURLParameter(_parts[1]);
				} catch(e) { return _value; }
				break;
						
			case 'site':
			try {
				return Site.GetProperty(_parts[1]);
				} catch(e) { return ''; }
				break;
			
			case 'page':
			try {
				return Page.GetProperty(_parts[1]);
				} catch(e) { return ''; }
				break;
			
			default:
				return _value;
		}
	}
	
	function _createStyle()
	{
		var _styles = _parent.GetStyles();
		var _str	= '';
		
		for(var i=0; i<_styles.length; i++)
		{
			try {
				_str += _styles[i].Name + ':' + _styles[i].Value + _styles[i].Units;
				_str += ';';
			} catch(e) { continue; }
		}
		
		return _str;
	}
	
	function _processProperties(_propertiesXML)
	{
		_properties = new Array();
		
		var _property = _propertiesXML;
		
		while(_property != null)
		{
			_properties[_properties.length] = new sisStyle(_property);
			_property = get_nextsibling(_property);
		}
	}
}

function sisObjectComment(_obj)
{
	var _parent			= _obj;
	var _properties		= new Array();
	
	this.Render					= _render;
	this.GetStyle				= _getStyle;
	this.GetProperty			= _getProperty;
	this.GetContent				= _getContent;
	this.GetStyles				= _getStyles;
	this.SetMediaProperties		= _setMediaProperties;

	function _setMediaProperties(_props)
	{
		var _parts = _props.split('&');
		for(var i=0; i<_parts.length; i++)
		{
			var _prop = _parts[i].split('=');
			var _mediaProp = new sisProperty();
			_mediaProp.Name = _prop[0];
			_mediaProp.Value = _prop[1];
			
			_properties[_properties.length] = _mediaProp;
		}
	}
	
	function _getStyles()
	{
		return _parent.GetStyles();
	}
	
	function _getContent()
	{
		return _parent.GetContent();
	}
	
	function _getStyle(_name)
	{
		return _parent.GetStyle(_name);
	}
	
	function _getProperty(_name)
	{
		for(var i=0; i<_properties.length; i++)
		{
			if(_properties[i].Name == _name) return _properties[i];
		}
		
		return "";
	}

	function _render()
	{
		var _aspect = _parent.GetProperty('aspect').Value;
		
		if(_aspect == 'none')
		{
			return _renderWithoutAspect();
		} else
		{
			return _renderWithAspect();
		}
	}
	
	function _renderWithoutAspect()
	{
		var _styles = _parent.GetStyles();
		
		var _str	 = '<div style="' + _createStyle();
		_str 		+= '">';
		_str 		+= _parent.GetContent();
		_str 		+= '</div>';
		
		return _str;
	}

	function _renderPart(_part, _aspect)
	{
		var _ajax 		= new sisAJAXConnector();
		
		_ajax.open("GET", "aspects/comment/" + _aspect + ".aspect", false);
		_ajax.send(null);

		// create all the property objects
		_processProperties(_part.getElementsByTagName('properties')[0].firstChild);
		
		// now run the aspect processor
		_aspectObj = new sisAspect(new sisXMLDocument(_ajax.responseText), _parent.GetObject());
		
		var _rendered = _aspectObj.Render();

		return _rendered;
	}

	function _renderWithAspect()
	{
		var _document 	= new sisXMLDocument(_fetchComments());
		var _str			= '';
		var _cnt			= 0;
		
			// now we need to process each blog_entry in the response
		var _entries = _document.getElementsByTagName('commentObj');
		for(var e=0; e<_entries.length; e++)
		{
			var _entry			= _entries[e];
			var _aspect			= _determineAspect(_parent.GetProperty('aspect').Value, _cnt, _entries.length);
			var _target 		= _determineTarget(_parent.GetProperty('target').Value, _cnt, _entries.length, _parent.GetProperty('orientation').Value);
			
			document.getElementById(_target).innerHTML += _renderPart(_entry, _aspect);
			
			_cnt++;
		}
		
		return null;
	}

	
	function _expandValue(_value)
	{
		if(_value.charAt(0)!= '|') return _value;
		
		var _MasterParts	= _value.split('|');			// get the bit in the middle
		var _parts			= _MasterParts[1].split('.');	// split the bit in the middle again
		
		switch(_parts[0])
		{
			case 'get':
			try {
				return GetURLParameter(_parts[1]);
				} catch(e) { return _value; }
				break;
						
			case 'site':
			try {
				return Site.GetProperty(_parts[1]);
				} catch(e) { return ''; }
				break;
			
			case 'page':
			try {
				return Page.GetProperty(_parts[1]);
				} catch(e) { return ''; }
				break;
			
			default:
				return _value;
		}
	}
	
	function _fetchComments()
	{
		var _ajax 			= new sisAJAXConnector();
		var _showby			= _expandValue(_parent.GetProperty('show_by').Value);
		var _componentid	= _expandValue(_parent.GetProperty('componentid').Value);
		var _show_entries	= _parent.GetProperty('show_entries').Value;
		
		_ajax.open("GET", "../xml/FetchComments.php?ShowBy=" + _showby + '&ComponentID=' + _componentid + '&ShowEntries=' + _show_entries, false);
		_ajax.send(null);
		
		return _ajax.responseText;
	}
	
	function _determineTarget(_targetlist, _index, _totalentries, _orientation)
	{
		var _targets = _targetlist.split(',');
		
		if(_targets.length == 1 || _index == 0) 	return _targets[0].split('!')[0];
		
		var _cnt 			= _index + 1;
		var _flexTargets	= new Array();
		
		for(var i=0; i<_index; i++)
		{
			var _targetCnt 	= 0;
			for(var a=0; a<_targets.length; a++)
			{
				var _target = _targets[a];
				var _parts	= _target.split('!');
				
				if(_parts.length == 1)
				{
					_targetCnt++;
					_flexTargets[_flexTargets.length] = _target;
				}
				
				_targetCnt += _parts[1]*1;

				if(_targetCnt >= _cnt) return _parts[0];
			}
		}
		
		_target = _index%_flexTargets.length;
		return _flexTargets[_target].split('!')[0];
	}
	
	function _determineAspect(_aspectlist, _index, _totalentries)
	{
		var _aspects = _aspectlist.split(',');

		if(_aspects.length == 1 || _index ==0 ) 	return _aspects[0].split('!')[0];
		
		// all other entries, we need to figure out which aspect to use
		var _cnt 			= _index + 1;
		
		for(var i=0; i<_index; i++)
		{
			var _aspectCnt 	= 0;
			for(var a=0; a<_aspects.length; a++)
			{
				var _aspect = _aspects[a];
				var _parts	= _aspect.split('!');
				
				if(_parts.length == 1) return _parts[0];
				
				_aspectCnt += _parts[1]*1;

				if(_aspectCnt >= _cnt) return _parts[0];
			}
		}
	}
	
	function _processProperties(_propertiesXML)
	{
		_properties = new Array();
		
		var _property = _propertiesXML;
		
		while(_property != null)
		{
			_properties[_properties.length] = new sisStyle(_property);
			_property = get_nextsibling(_property);
		}
	}
}

function sisObjectCalendar(_obj)
{
}

function sisObjectProject(_obj)
{
}

function sisObjectPerson(_obj)
{
	var _parent			= _obj;
	var _properties		= new Array();
	
	this.Render			= _render;
	this.GetStyle		= _getStyle;
	this.GetProperty	= _getProperty;
	this.GetContent		= _getContent;
	this.GetStyles		= _getStyles;
	this.SetMediaProperties		= _setMediaProperties;

	function _setMediaProperties(_props)
	{
		var _parts = _props.split('&');
		for(var i=0; i<_parts.length; i++)
		{
			var _prop = _parts[i].split('=');
			var _mediaProp = new sisProperty();
			_mediaProp.Name = _prop[0];
			_mediaProp.Value = _prop[1];
			
			_properties[_properties.length] = _mediaProp;
		}
	}
	
	function _getStyles()
	{
		return _parent.GetStyles();
	}
	
	function _getContent()
	{
		return _parent.GetContent();
	}
	
	function _getStyle(_name)
	{
		return _parent.GetStyle(_name);
	}
	
	function _getProperty(_name)
	{
		for(var i=0; i<_properties.length; i++)
		{
			if(_properties[i].Name == _name) return _properties[i];
		}
		
		return "";
	}

	function _render()
	{
		var _aspect = _parent.GetProperty('aspect').Value;
		
		if(_aspect == 'none')
		{
			return _renderWithoutAspect();
		} else
		{
			return _renderWithAspect();
		}
	}
	
	function _renderWithoutAspect()
	{
		var _styles = _parent.GetStyles();
		
		var _str	 = '<div style="' + _createStyle();
		_str 		+= '">';
		_str 		+= _parent.GetContent();
		_str 		+= '</div>';
		
		return _str;
	}

	function _renderPart(_part, _aspect)
	{
		var _ajax 		= new sisAJAXConnector();
		
		_ajax.open("GET", "aspects/person/" + _aspect + ".aspect", false);
		_ajax.send(null);

		// create all the property objects
		_processProperties(_part.getElementsByTagName('properties')[0].firstChild);
		
		// now run the aspect processor
		_aspectObj = new sisAspect(new sisXMLDocument(_ajax.responseText), _parent.GetObject());
		
		var _rendered = _aspectObj.Render();

		return _rendered;
	}

	function _renderWithAspect()
	{
		var _document 	= new sisXMLDocument(_fetchPeople());
		var _str			= '';
		var _cnt			= 0;
		
			// now we need to process each blog_entry in the response
		var _entries = _document.getElementsByTagName('person');
		for(var e=0; e<_entries.length; e++)
		{
			var _entry			= _entries[e];
			var _aspect			= _determineAspect(_parent.GetProperty('aspect').Value, _cnt, _entries.length);
			var _target 		= _determineTarget(_parent.GetProperty('target').Value, _cnt, _entries.length, _parent.GetProperty('orientation').Value);
			
			document.getElementById(_target).innerHTML += _renderPart(_entry, _aspect);
			
			_cnt++;
		}
		
		return null;
	}

	
	function _expandValue(_value)
	{
		if(_value.charAt(0)!= '|') return _value;
		
		var _MasterParts	= _value.split('|');			// get the bit in the middle
		var _parts			= _MasterParts[1].split('.');	// split the bit in the middle again
		
		switch(_parts[0])
		{
			case 'get':
			try {
				return GetURLParameter(_parts[1]);
				} catch(e) { return ''; }
				break;
						
			case 'site':
			try {
				return Site.GetProperty(_parts[1]);
				} catch(e) { return ''; }
				break;
			
			case 'page':
			try {
				return Page.GetProperty(_parts[1]);
				} catch(e) { return ''; }
				break;
			
			default:
				return _value;
		}
	}
	
	function _fetchPeople()
	{
		var _ajax 			= new sisAJAXConnector();
		var _showby			= _expandValue(_parent.GetProperty('show_by').Value);
		var _componentid	= _expandValue(_parent.GetProperty('componentid').Value);
		var _show_entries	= _parent.GetProperty('show_entries').Value;
		
		_ajax.open("GET", "../xml/FetchPerson.php?ShowBy=" + _showby + '&ComponentID=' + _componentid + '&ShowEntries=' + _show_entries, false);
		_ajax.send(null);
		
		return _ajax.responseText;
	}
	
	function _determineTarget(_targetlist, _index, _totalentries, _orientation)
	{
		var _targets = _targetlist.split(',');
		
		if(_targets.length == 1 || _index == 0) 	return _targets[0].split('!')[0];
		
		var _cnt 			= _index + 1;
		var _flexTargets	= new Array();
		
		for(var i=0; i<_index; i++)
		{
			var _targetCnt 	= 0;
			for(var a=0; a<_targets.length; a++)
			{
				var _target = _targets[a];
				var _parts	= _target.split('!');
				
				if(_parts.length == 1)
				{
					_targetCnt++;
					_flexTargets[_flexTargets.length] = _target;
				}
				
				_targetCnt += _parts[1]*1;

				if(_targetCnt >= _cnt) return _parts[0];
			}
		}
		
		_target = _index%_flexTargets.length;
		return _flexTargets[_target].split('!')[0];
	}
	
	function _determineAspect(_aspectlist, _index, _totalentries)
	{
		var _aspects = _aspectlist.split(',');

		if(_aspects.length == 1 || _index ==0 ) 	return _aspects[0].split('!')[0];
		
		// all other entries, we need to figure out which aspect to use
		var _cnt 			= _index + 1;
		
		for(var i=0; i<_index; i++)
		{
			var _aspectCnt 	= 0;
			for(var a=0; a<_aspects.length; a++)
			{
				var _aspect = _aspects[a];
				var _parts	= _aspect.split('!');
				
				if(_parts.length == 1) return _parts[0];
				
				_aspectCnt += _parts[1]*1;

				if(_aspectCnt >= _cnt) return _parts[0];
			}
		}
	}
	
	function _processProperties(_propertiesXML)
	{
		_properties = new Array();
		
		var _property = _propertiesXML;
		
		while(_property != null)
		{
			_properties[_properties.length] = new sisStyle(_property);
			_property = get_nextsibling(_property);
		}
	}
}

function sisObjectGroup(_obj)
{
	var _parent			= _obj;
	var _properties		= new Array();
	
	this.Render			= _render;
	this.GetStyle		= _getStyle;
	this.GetProperty	= _getProperty;
	this.GetContent		= _getContent;
	this.GetStyles		= _getStyles;
	this.SetMediaProperties		= _setMediaProperties;

	function _setMediaProperties(_props)
	{
		if(_props==null || _props=='') return;
		
		var _parts = _props.split('&');
		for(var i=0; i<_parts.length; i++)
		{
			var _prop = _parts[i].split('=');
			var _mediaProp = new sisProperty();
			_mediaProp.Name = _prop[0];
			_mediaProp.Value = _prop[1];
			
			_properties[_properties.length] = _mediaProp;
		}
	}
	

	function _getStyles()
	{
		return _parent.GetStyles();
	}
	
	function _getContent()
	{
		return _parent.GetContent();
	}
	
	function _getStyle(_name)
	{
		return _parent.GetStyle(_name);
	}
	
	function _getProperty(_name)
	{
		for(var i=0; i<_properties.length; i++)
		{
			if(_properties[i].Name == _name) return _properties[i];
		}
		
		return "";
	}

	function _render()
	{
		var _aspect = _parent.GetProperty('aspect').Value;
		
		if(_aspect == 'none')
		{
			return _renderWithoutAspect();
		} else
		{
			return _renderWithAspect();
		}
	}
	
	function _renderWithoutAspect()
	{
		var _styles = _parent.GetStyles();
		
		var _str	 = '<div style="' + _createStyle();
		_str 		+= '">';
		_str 		+= _parent.GetContent();
		_str 		+= '</div>';
		
		return _str;
	}

	function _renderPart(_part, _aspect)
	{
		var _ajax 		= new sisAJAXConnector();
		
		_ajax.open("GET", "aspects/groups/" + _aspect + ".aspect", false);
		_ajax.send(null);

		// create all the property objects
		_processProperties(_part.getElementsByTagName('properties')[0].firstChild);
		
		// now run the aspect processor
		_aspectObj = new sisAspect(new sisXMLDocument(_ajax.responseText), _parent.GetObject());
		
		var _rendered = _aspectObj.Render();

		return _rendered;
	}

	function _renderWithAspect()
	{
		var _document 	= new sisXMLDocument(_fetchGroup());
		var _str			= '';
		var _cnt			= 0;
		
			// now we need to process each blog_entry in the response
		var _entries = _document.getElementsByTagName('group');
		for(var e=0; e<_entries.length; e++)
		{
			var _entry			= _entries[e];
			var _aspect			= _determineAspect(_parent.GetProperty('aspect').Value, _cnt, _entries.length);
			var _target 		= _determineTarget(_parent.GetProperty('target').Value, _cnt, _entries.length, _parent.GetProperty('orientation').Value);
			
			document.getElementById(_target).innerHTML += _renderPart(_entry, _aspect);
			
			_cnt++;
		}
		
		return null;
	}

	
	function _expandValue(_value)
	{
		if(_value.charAt(0)!= '|') return _value;
		
		var _MasterParts	= _value.split('|');			// get the bit in the middle
		var _parts			= _MasterParts[1].split('.');	// split the bit in the middle again
		
		switch(_parts[0])
		{
			case 'get':
			try {
				return GetURLParameter(_parts[1]);
				} catch(e) { return ''; }
				break;
						
			case 'site':
			try {
				return Site.GetProperty(_parts[1]);
				} catch(e) { return ''; }
				break;
			
			case 'page':
			try {
				return Page.GetProperty(_parts[1]);
				} catch(e) { return ''; }
				break;
			
			default:
				return _value;
		}
	}
	
	function _fetchGroup()
	{
		var _ajax 			= new sisAJAXConnector();
		var _showby			= _expandValue(_parent.GetProperty('show_by').Value);
		var _componentid	= _expandValue(_parent.GetProperty('componentid').Value);
		var _show_entries	= _parent.GetProperty('show_entries').Value;
		
		_ajax.open("GET", "../xml/FetchGroups.php?ShowBy=" + _showby + '&ComponentID=' + _componentid + '&ShowEntries=' + _show_entries, false);
		_ajax.send(null);
		
		return _ajax.responseText;
	}
	
	function _determineTarget(_targetlist, _index, _totalentries, _orientation)
	{
		var _targets = _targetlist.split(',');
		
		if(_targets.length == 1 || _index == 0) 	return _targets[0].split('!')[0];
		
		var _cnt 			= _index + 1;
		var _flexTargets	= new Array();
		
		for(var i=0; i<_index; i++)
		{
			var _targetCnt 	= 0;
			for(var a=0; a<_targets.length; a++)
			{
				var _target = _targets[a];
				var _parts	= _target.split('!');
				
				if(_parts.length == 1)
				{
					_targetCnt++;
					_flexTargets[_flexTargets.length] = _target;
				}
				
				_targetCnt += _parts[1]*1;

				if(_targetCnt >= _cnt) return _parts[0];
			}
		}
		
		_target = _index%_flexTargets.length;
		return _flexTargets[_target].split('!')[0];
	}
	
	function _determineAspect(_aspectlist, _index, _totalentries)
	{
		var _aspects = _aspectlist.split(',');

		if(_aspects.length == 1 || _index ==0 ) 	return _aspects[0].split('!')[0];
		
		// all other entries, we need to figure out which aspect to use
		var _cnt 			= _index + 1;
		
		for(var i=0; i<_index; i++)
		{
			var _aspectCnt 	= 0;
			for(var a=0; a<_aspects.length; a++)
			{
				var _aspect = _aspects[a];
				var _parts	= _aspect.split('!');
				
				if(_parts.length == 1) return _parts[0];
				
				_aspectCnt += _parts[1]*1;

				if(_aspectCnt >= _cnt) return _parts[0];
			}
		}
	}
	
	function _processProperties(_propertiesXML)
	{
		_properties = new Array();
		
		var _property = _propertiesXML;
		
		while(_property != null)
		{
			_properties[_properties.length] = new sisStyle(_property);
			_property = get_nextsibling(_property);
		}
	}
}

function sisObjectChart(_obj)
{
	var _parent			= _obj;
	var _properties		= new Array();
	
	this.Render			= _render;
	this.GetStyle		= _getStyle;
	this.GetProperty	= _getProperty;
	this.GetContent		= _getContent;
	this.GetStyles		= _getStyles;
	this.SetMediaProperties		= _setMediaProperties;

	function _setMediaProperties(_props)
	{
		var _parts = _props.split('&');
		for(var i=0; i<_parts.length; i++)
		{
			var _prop = _parts[i].split('=');
			var _mediaProp = new sisProperty();
			_mediaProp.Name = _prop[0];
			_mediaProp.Value = _prop[1];
			
			_properties[_properties.length] = _mediaProp;
		}
	}
	

	function _getStyles()
	{
		return _parent.GetStyles();
	}
	
	function _getContent()
	{
		return _parent.GetContent();
	}
	
	function _getStyle(_name)
	{
		return _parent.GetStyle(_name);
	}
	
	function _getProperty(_name)
	{
		for(var i=0; i<_properties.length; i++)
		{
			if(_properties[i].Name == _name) return _properties[i];
		}
		
		return "";
	}

	function _render()
	{
		var _aspect = _parent.GetProperty('aspect').Value;
		
		if(_aspect == 'none')
		{
			return _renderWithoutAspect();
		} else
		{
			return _renderWithAspect();
		}
	}
	
	function _renderWithoutAspect()
	{
		var _styles = _parent.GetStyles();
		
		var _str	 = '<div style="' + _createStyle();
		_str 		+= '">';
		_str 		+= _parent.GetContent();
		_str 		+= '</div>';
		
		return _str;
	}

	function _renderPart(_part, _aspect)
	{
		var _ajax 		= new sisAJAXConnector();
		
		_ajax.open("GET", "aspects/chart/" + _aspect + ".aspect", false);
		_ajax.send(null);

		// create all the property objects
		_processProperties(_part.getElementsByTagName('properties')[0].firstChild);
		
		// now run the aspect processor
		_aspectObj = new sisAspect(new sisXMLDocument(_ajax.responseText), _parent.GetObject());
		
		var _rendered = _aspectObj.Render();

		return _rendered;
	}

	function _renderWithAspect()
	{
		var _document 	= new sisXMLDocument(_fetchChart());
		var _str			= '';
		var _cnt			= 0;
		
			// now we need to process each blog_entry in the response
		var _entries = _document.getElementsByTagName('chart');
		for(var e=0; e<_entries.length; e++)
		{
			var _entry			= _entries[e];
			var _aspect			= _determineAspect(_parent.GetProperty('aspect').Value, _cnt, _entries.length);
			var _target 		= _determineTarget(_parent.GetProperty('target').Value, _cnt, _entries.length, _parent.GetProperty('orientation').Value);
			
			document.getElementById(_target).innerHTML += _renderPart(_entry, _aspect);
			
			_cnt++;
		}
		
		return null;
	}

	
	function _expandValue(_value)
	{
		if(_value==null || _value.charAt(0)!= '|') return _value;
		
		var _MasterParts	= _value.split('|');			// get the bit in the middle
		var _parts			= _MasterParts[1].split('.');	// split the bit in the middle again
		
		switch(_parts[0])
		{
			case 'get':
			try {
				return GetURLParameter(_parts[1]);
				} catch(e) { return ''; }
				break;
						
			case 'site':
			try {
				return Site.GetProperty(_parts[1]);
				} catch(e) { return ''; }
				break;
			
			case 'page':
			try {
				return Page.GetProperty(_parts[1]);
				} catch(e) { return ''; }
				break;
			
			default:
				return _value;
		}
	}
	
	function _fetchChart()
	{
		var _ajax 			= new sisAJAXConnector();
		var _showby			= _expandValue(_parent.GetProperty('show_by').Value);
		var _componentid	= _expandValue(_parent.GetProperty('componentid').Value);
		var _show_entries	= _parent.GetProperty('show_entries').Value;
		
		_ajax.open("GET", "../xml/FetchChart.php?ShowBy=" + _showby + '&ComponentID=' + _componentid + '&ShowEntries=' + _show_entries, false);
		_ajax.send(null);

		return _ajax.responseText;
	}
	
	function _determineTarget(_targetlist, _index, _totalentries, _orientation)
	{
		var _targets = _targetlist.split(',');
		
		if(_targets.length == 1 || _index == 0) 	return _targets[0].split('!')[0];
		
		var _cnt 			= _index + 1;
		var _flexTargets	= new Array();
		
		for(var i=0; i<_index; i++)
		{
			var _targetCnt 	= 0;
			for(var a=0; a<_targets.length; a++)
			{
				var _target = _targets[a];
				var _parts	= _target.split('!');
				
				if(_parts.length == 1)
				{
					_targetCnt++;
					_flexTargets[_flexTargets.length] = _target;
				}
				
				_targetCnt += _parts[1]*1;

				if(_targetCnt >= _cnt) return _parts[0];
			}
		}
		
		_target = _index%_flexTargets.length;
		return _flexTargets[_target].split('!')[0];
	}
	
	function _determineAspect(_aspectlist, _index, _totalentries)
	{
		var _aspects = _aspectlist.split(',');

		if(_aspects.length == 1 || _index ==0 ) 	return _aspects[0].split('!')[0];
		
		// all other entries, we need to figure out which aspect to use
		var _cnt 			= _index + 1;
		
		for(var i=0; i<_index; i++)
		{
			var _aspectCnt 	= 0;
			for(var a=0; a<_aspects.length; a++)
			{
				var _aspect = _aspects[a];
				var _parts	= _aspect.split('!');
				
				if(_parts.length == 1) return _parts[0];
				
				_aspectCnt += _parts[1]*1;

				if(_aspectCnt >= _cnt) return _parts[0];
			}
		}
	}
	
	function _processProperties(_propertiesXML)
	{
		_properties = new Array();
		
		var _property = _propertiesXML;
		
		while(_property != null)
		{
			_properties[_properties.length] = new sisStyle(_property);
			_property = get_nextsibling(_property);
		}
	}
}

function sisObjectCategory(_obj)
{
	var _parent			= _obj;
	var _properties		= new Array();
	
	this.Render			= _render;
	this.GetStyle		= _getStyle;
	this.GetProperty	= _getProperty;
	this.GetContent		= _getContent;
	this.GetStyles		= _getStyles;
	this.SetMediaProperties		= _setMediaProperties;

	function _setMediaProperties(_props)
	{
		if(_props==null || _props=='') return;
		
		var _parts = _props.split('&');
		for(var i=0; i<_parts.length; i++)
		{
			var _prop = _parts[i].split('=');
			var _mediaProp = new sisProperty();
			_mediaProp.Name = _prop[0];
			_mediaProp.Value = _prop[1];
			
			_properties[_properties.length] = _mediaProp;
		}
	}
	

	function _getStyles()
	{
		return _parent.GetStyles();
	}
	
	function _getContent()
	{
		return _parent.GetContent();
	}
	
	function _getStyle(_name)
	{
		return _parent.GetStyle(_name);
	}
	
	function _getProperty(_name)
	{
		for(var i=0; i<_properties.length; i++)
		{
			if(_properties[i].Name == _name) return _properties[i];
		}
		
		return "";
	}

	function _render()
	{
		var _aspect = _parent.GetProperty('aspect').Value;
		
		if(_aspect == 'none')
		{
			return _renderWithoutAspect();
		} else
		{
			return _renderWithAspect();
		}
	}
	
	function _renderWithoutAspect()
	{
		var _styles = _parent.GetStyles();
		
		var _str	 = '<div style="' + _createStyle();
		_str 		+= '">';
		_str 		+= _parent.GetContent();
		_str 		+= '</div>';
		
		return _str;
	}

	function _renderPart(_part, _aspect)
	{
		var _ajax 		= new sisAJAXConnector();
		
		_ajax.open("GET", "aspects/category/" + _aspect + ".aspect", false);
		_ajax.send(null);

		// create all the property objects
		_processProperties(_part.getElementsByTagName('properties')[0].firstChild);
		
		// now run the aspect processor
		_aspectObj = new sisAspect(new sisXMLDocument(_ajax.responseText), _parent.GetObject());
		
		var _rendered = _aspectObj.Render();

		return _rendered;
	}

	function _renderWithAspect()
	{
		var _document 	= new sisXMLDocument(_fetchCategory());
		var _str			= '';
		var _cnt			= 0;
		
			// now we need to process each blog_entry in the response
		var _entries = _document.getElementsByTagName('category');
		for(var e=0; e<_entries.length; e++)
		{
			var _entry			= _entries[e];
			var _aspect			= _determineAspect(_parent.GetProperty('aspect').Value, _cnt, _entries.length);
			var _target 		= _determineTarget(_parent.GetProperty('target').Value, _cnt, _entries.length, _parent.GetProperty('orientation').Value);
			
			document.getElementById(_target).innerHTML += _renderPart(_entry, _aspect);
			
			_cnt++;
		}
		
		return null;
	}

	
	function _expandValue(_value)
	{
		if(_value==null || _value=='' || _value.charAt(0)!= '|') return _value;
		
		var _MasterParts	= _value.split('|');			// get the bit in the middle
		var _parts			= _MasterParts[1].split('.');	// split the bit in the middle again
		
		switch(_parts[0])
		{
			case 'get':
			try {
				return GetURLParameter(_parts[1]);
				} catch(e) { return ''; }
				break;
						
			case 'site':
			try {
				return Site.GetProperty(_parts[1]);
				} catch(e) { return ''; }
				break;
			
			case 'page':
			try {
				return Page.GetProperty(_parts[1]);
				} catch(e) { return ''; }
				break;
			
			default:
				return _value;
		}
	}
	
	function _fetchCategory()
	{
		var _ajax 			= new sisAJAXConnector();
		var _showby			= _expandValue(_parent.GetProperty('show_by').Value);
		var _componentid	= _expandValue(_parent.GetProperty('componentid').Value);
		var _show_entries	= _parent.GetProperty('show_entries').Value;
		
		_ajax.open("GET", "../xml/FetchCategory.php?ShowBy=" + _showby + '&ComponentID=' + _componentid + '&ShowEntries=' + _show_entries, false);
		_ajax.send(null);
		
		return _ajax.responseText;
	}
	
	function _determineTarget(_targetlist, _index, _totalentries, _orientation)
	{
		var _targets = _targetlist.split(',');
		
		if(_targets.length == 1 || _index == 0) 	return _targets[0].split('!')[0];
		
		var _cnt 			= _index + 1;
		var _flexTargets	= new Array();
		
		for(var i=0; i<_index; i++)
		{
			var _targetCnt 	= 0;
			for(var a=0; a<_targets.length; a++)
			{
				var _target = _targets[a];
				var _parts	= _target.split('!');
				
				if(_parts.length == 1)
				{
					_targetCnt++;
					_flexTargets[_flexTargets.length] = _target;
				}
				
				_targetCnt += _parts[1]*1;

				if(_targetCnt >= _cnt) return _parts[0];
			}
		}
		
		_target = _index%_flexTargets.length;
		return _flexTargets[_target].split('!')[0];
	}
	
	function _determineAspect(_aspectlist, _index, _totalentries)
	{
		var _aspects = _aspectlist.split(',');

		if(_aspects.length == 1 || _index ==0 ) 	return _aspects[0].split('!')[0];
		
		// all other entries, we need to figure out which aspect to use
		var _cnt 			= _index + 1;
		
		for(var i=0; i<_index; i++)
		{
			var _aspectCnt 	= 0;
			for(var a=0; a<_aspects.length; a++)
			{
				var _aspect = _aspects[a];
				var _parts	= _aspect.split('!');
				
				if(_parts.length == 1) return _parts[0];
				
				_aspectCnt += _parts[1]*1;

				if(_aspectCnt >= _cnt) return _parts[0];
			}
		}
	}
	
	function _processProperties(_propertiesXML)
	{
		_properties = new Array();
		
		var _property = _propertiesXML;
		
		while(_property != null)
		{
			_properties[_properties.length] = new sisStyle(_property);
			_property = get_nextsibling(_property);
		}
	}
}

function sisObjectFeed(_obj)
{
	var _parent				= _obj;
	var _properties			= new Array();
	
	this.Render				= _render;
	this.GetStyle			= _getStyle;
	this.GetProperty		= _getProperty;
	this.GetContent			= _getContent;
	this.GetStyles			= _getStyles;
	this.SetMediaProperties	= _setMediaProperties;
	this.SetProperty		= _setProperty;

	function _setMediaProperties(_props)
	{
		if(_props==null || _props=='' || _props=='undefined') return;
		
		var _parts = _props.split('&');
		for(var i=0; i<_parts.length; i++)
		{
			var _prop = _parts[i].split('=');
			var _mediaProp = new sisProperty();
			_mediaProp.Name = _prop[0];
			_mediaProp.Value = _prop[1];
			
			_properties[_properties.length] = _mediaProp;
		}
	}
	

	function _getStyles()
	{
		return _parent.GetStyles();
	}
	
	function _getContent()
	{
		return _parent.GetContent();
	}
	
	function _getStyle(_name)
	{
		return _parent.GetStyle(_name);
	}
	
	function _setProperty(_name, _value)
	{
		for(var i=0; i<_properties.length; i++)
		{
			if(_properties[i].Name == _name)
			{
				_properties[i].Value = _value;
				return;
			}
		}
		
		var _prop = new sisProperty();
		_prop.Name = _name;
		_prop.Value = _value;
		_properties[_properties.length] = _prop;
		
		return;
	}
	
	function _getProperty(_name)
	{
		for(var i=0; i<_properties.length; i++)
		{
			if(_properties[i].Name == _name) return _properties[i];
		}
		
		return "";
	}
	
	function _render()
	{
		var _aspect = _parent.GetProperty('aspect').Value;
		
		if(_aspect == 'none')
		{
			return _renderWithoutAspect();
		} else
		{
			return _renderWithAspect();
		}
	}
	
	function _renderWithoutAspect()
	{
		var _styles = _parent.GetStyles();
		
		var _str	 = '<div style="' + _createStyle();
		_str 		+= '">';
		_str 		+= _parent.GetContent();
		_str 		+= '</div>';
		
		return _str;
	}

	function _renderPart(_part, _aspect)
	{
		var _aspectName = "aspects/feed/" + _aspect + ".aspect";
		var _ajax		= null;
		var _response	= null;
		
		for(var i=0; i<_glbAspectNames.length; i++)
		{
			if(_glbAspectNames[i] == _aspectName)
			{
				_response = _glbAspects[i];
				break;
			}
		}
		
		if(_response == null)
		{
			_ajax 		= new sisAJAXConnector();
			
			_ajax.open("GET", _aspectName, false);
			_ajax.send(null);
			
			_response = _ajax.responseText;
			
			_glbAspectNames[_glbAspectNames.length] 	= _aspectName;
			_glbAspects[_glbAspects.length] 			= _response;
		}

		// create all the property objects
		_processProperties(_part.getElementsByTagName('properties')[0].firstChild);
		
		// now run the aspect processor
		var _format		= _part.getElementsByTagName('format')[0].firstChild.nodeValue;
		var _aspectObj = new sisAspect(new sisXMLDocument(_response), _parent.GetObject(), _format, true);
		
		var _rendered = _aspectObj.Render();

		return _rendered;
	}
	
	function _renderWithAspect()
	{
	
		var _blogXML		= _fetchFeed();
		var _blogDocument 	= sisXMLDocument(_blogXML);
		var _str			= '';
		var _blogs 			= _blogDocument.getElementsByTagName('feed');
		var _cnt			= 0;
//alert('DEBUG: ' + _blogDocument);
		for(var b=0; b < _blogs.length; b++)
		{
			var _blog = _blogs[b];
			
			if(_parent.GetProperty('show_feed').Value*1 != 0)
			{
				var _aspect = _parent.GetProperty('aspect').Value;
				document.getElementById(_parent.GetProperty('target').Value).innerHTML += _renderPart(_blog, _aspect);
			}
			
			// now we need to process each feed_entry in the response
			var _entries = _blog.getElementsByTagName('feed_entry');

			for(var e=0; e<_entries.length; e++)
			{
				var _entry			= _entries[e];
				var _aspect			= _determineAspect(_parent.GetProperty('secondary_aspect').Value, _cnt, _entries.length);
				var _target 		= _determineTarget(_parent.GetProperty('secondary_target').Value, _cnt, _entries.length, _parent.GetProperty('orientation').Value);
				
				document.getElementById(_target).innerHTML += _renderPart(_entry, _aspect);
				
				_cnt++;
			}
		}
		
		return null;
	}
	
	function _determineTarget(_targetlist, _index, _totalentries, _orientation)
	{
		var _targets = null;
		try {
			_targets = _targetlist.split(',');
		} catch(e) {
			return "hotspot1";
		}
		
		if(_targets.length == 1 || _index == 0) 	return _targets[0].split('!')[0];
		
		var _cnt 			= _index + 1;
		var _flexTargets	= new Array();
		
		for(var i=0; i<_index; i++)
		{
			var _targetCnt 	= 0;
			for(var a=0; a<_targets.length; a++)
			{
				var _target = _targets[a];
				var _parts	= _target.split('!');
				
				if(_parts.length == 1)
				{
					_targetCnt++;
					_flexTargets[_flexTargets.length] = _target;
				}
				
				_targetCnt += _parts[1]*1;

				if(_targetCnt >= _cnt) return _parts[0];
			}
		}
		
		_target = _index%_flexTargets.length;
		return _flexTargets[_target].split('!')[0];
	}
	
	function _determineAspect(_aspectlist, _index, _totalentries)
	{
		var _aspects = null;
		try {
			_aspects = _aspectlist.split(',');
		} catch(e) {
			return "default";
		}

		if(_aspects.length == 1 || _index ==0 ) 	return _aspects[0].split('!')[0];
		
		// all other entries, we need to figure out which aspect to use
		var _cnt 			= _index + 1;
		
		for(var i=0; i<_index; i++)
		{
			var _aspectCnt 	= 0;
			for(var a=0; a<_aspects.length; a++)
			{
				var _aspect = _aspects[a];
				var _parts	= _aspect.split('!');
				
				if(_parts.length == 1) return _parts[0];
				
				_aspectCnt += _parts[1]*1;

				if(_aspectCnt >= _cnt) return _parts[0];
			}
		}
	}
	
	function _fetchFeed()
	{
		var _ajax 			= new sisAJAXConnector();
		var _fetch_by		= _expandValue(_parent.GetProperty('fetch_by').Value);
		var _showby			= _expandValue(_parent.GetProperty('show_by').Value);
		var _componentid	= _expandValue(_parent.GetProperty('componentid').Value);
		var _show_entries	= _parent.GetProperty('show_entries').Value;
		var _url			= "";
		
		switch(_fetch_by)
		{
			case 'feed_item':
				_url = "../xml/FetchFeedItems.php?ShowBy=" + _showby + '&ComponentID=' + _componentid + '&ShowEntries=' + _show_entries;
				break;
				
			default:
				_url = "../xml/FetchFeed.php?ShowBy=" + _showby + '&ComponentID=' + _componentid + '&ShowEntries=' + _show_entries;
		}
		
		_ajax.open("GET", GetURL(_url), false);
		_ajax.send('');

		return _ajax.responseText;
	}
	
	function _expandValue(_value)
	{
		if(_value==null || _value=='' || _value.charAt(0)!= '|') return _value;
		
		var _MasterParts	= _value.split('|');			// get the bit in the middle
		var _parts			= _MasterParts[1].split('.');	// split the bit in the middle again
		
		switch(_parts[0])
		{
			case 'get':
			try {
				return GetURLParameter(_parts[1]);
				} catch(e) { return _value; }
				break;
						
			case 'site':
			try {
				return Site.GetProperty(_parts[1]);
				} catch(e) { return ''; }
				break;
			
			case 'page':
			try {
				return Page.GetProperty(_parts[1]);
				} catch(e) { return ''; }
				break;
			
			default:
				return _value;
		}
	}
	
	function _createStyle()
	{
		var _styles = _parent.GetStyles();
		var _str	= '';
		
		for(var i=0; i<_styles.length; i++)
		{
			try {
				_str += _styles[i].Name + ':' + _styles[i].Value + _styles[i].Units;
				_str += ';';
			} catch(e) { continue; }
		}
		
		return _str;
	}
	
	function _processProperties(_propertiesXML)
	{
		_properties = new Array();
		
		var _property = _propertiesXML;
		
		while(_property != null)
		{
			_properties[_properties.length] = new sisStyle(_property);
			_property = get_nextsibling(_property);
		}
	}
}

function sisObjectNavigation(_obj)
{
}

function sisObjectHotspot(_obj)
{
}

function sisAspect(_aspect, _object, _format, _noop)
{
	var _controlBlock 	= _aspect.getElementsByTagName('control')[0];
	var _contentBlock 	= _aspect.getElementsByTagName('content')[0].firstChild;
	var _obj			= _object;
	
	this.Render			= _render;

	if(_format != null)
	{
		// we need to find the alternate content block for this format if available
		var _blocks = _aspect.getElementsByTagName('content');
		for(var i=0; i<_blocks.length; i++)
		{
			var _attr = _blocks[i].getAttribute('format');
			if(_attr!=null && _attr == _format)
			{
				_contentBlock = _blocks[i].firstChild;
				break;
			}
		}
	}
		
	function _render()
	{
		var _pageParts 	= _contentBlock.nodeValue.split('|');
		var _str		= '';
		
		for(var i=0; i<_pageParts.length; i++)
		{
			var _varParts = _pageParts[i].split('.');

			if(_varParts.length >= 2)
			{
				switch(_varParts[0])
				{
					case 'object':
						if(_varParts[1] == 'content')
						{
							_str += _obj.GetContent();
						}
						break;
						
					case 'style':
					try {
						var _val = _obj.GetStyle(_varParts[1]).Value;
						if(_val!=null && _val!='null') _str += _val;
						} catch (e) { continue; }
						break;
						
					case 'properties':
						if((_noop==null || (_noop!=null && _noop!=false)) && 
								(_varParts[1] == 'media_file' || _varParts[1] == 'enclosure_thumbnail'))
						{
							_obj.SetMediaProperties(_varParts[2]);
							var _smo = new sisObjectMedia(_obj, _varParts[1]);
							_str += _smo.Render('embedded');
						} else
						{
							try {
								var _val = _obj.GetProperty(_varParts[1]).Value;
								if(_val!=null && _val!='null')
								{
									if(_varParts[1]=='media_file' || _varParts[1]=='enclosure_thumbnail') _val = escape(_val);
									 _str += _val;
								}
								} catch(e) { continue; }
						}
						break;
						
					case 'page':
					try {
						var _val = Page.GetProperty(_varParts[1]).Value;
						if(_val!=null && _val!='null') _str += _val;
						} catch(e) { continue; }
						break;
						
					case 'site':
					try {
						var _val = Site.GetProperty(_varParts[1]).Value;
						if(_val!=null && _val!='null') _str += _val;
						} catch(e) { continue; }
						break;
					
					case 'variable':
						break;
						
					case 'get':
					try {
						var _val = unescape(GetURLParameter(_varParts[1]));
						if(_val!=null && _val!='null') _str += _val;
						} catch(e) { continue; }
						break;
						
					case 'option':
						// this is for the conditional optional extras processing
						// TBD
						break;
						
					default:
						_str += _pageParts[i];
						break;
					
				}
			} else
			{
				_str += _pageParts[i];
			}
		}
		
		return _addWrapperDIV(_str);
	}
	
	function _addWrapperDIV(_buf)
	{
		var _str	 = '<div style="' + _createStyle();
		_str 		+= '">';
		_str 		+= _buf;
		_str 		+= '</div>';
		
		return _str;
	}
	
	function _createStyle()
	{
		var _styles = _obj.GetStyles();
		var _str	= '';
		
		for(var i=0; i<_styles.length; i++)
		{
			try {
				_str += _styles[i].Name + ':' + _styles[i].Value + _styles[i].Units;
				_str += ';';
			} catch(e) { continue; }
		}
		
		return _str;
	}
}

