﻿/* ------------------
	CMS functions
------------------ */
function imageSwap(str_panel, int_item) {
	var obj_panel, arr_anchors, arr_listitems;
	
	obj_panel = document.getElementById(str_panel);
		
	// Clear existing panel's 'current' classes
	arr_anchors = getElementsByClassNameSafe('current', obj_panel);
	
	for (var i = 0; i <= arr_anchors.length; i++) {
		if(arr_anchors[i] != undefined)
			arr_anchors[i].className = '';
	}
	
	// Set new 'current' class
	arr_listitems = getElementsByClassNameSafe('side_' + int_item, obj_panel);
	arr_listitems[0].getElementsByTagName('a')[0].className = 'current';
}


/* -- Core Functions -- */

function getElementsByClassNameSafe(searchClass, node, tag) {
	/* --------
	Selects elements by the class name.
	Create function if it doesn't already exist.
	
	NOTE: getElementsByClassName not supported by IE 
	
	Modified version of: http://www.dustindiaz.com/getelementsbyclass/
		(found via http://ejohn.org/blog/getelementsbyclassname-speed-comparison)
	-------- */
	
	if (typeof getElementsByClassName == 'function') {
		return node.getElementsByClassName(searchClass);
	
	} else {
			
		var classElements = new Array();
		if ( node == null )
				node = document;
		if ( tag == null )
				tag = '*';
		var els = node.getElementsByTagName(tag);
		var elsLen = els.length;
		var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
		for (var i = 0, j = 0; i < elsLen; i++) {
				if ( pattern.test(els[i].className) ) {
						classElements[j] = els[i];
						j++;
				}
		}
		return classElements;
	}
}
