// JavaScript Document
//JTools JS
//JTools Namespace everything in this file
var JTools = {};
//Function Name: JTools.$include(<script/stylesheetsrce as string><boolean is stylesheet include as boolean true or false>);
//Edited: 8/6/2007
//Editor: Jack Viers: Manager-Production
//Output: Includes a javascript/stylesheet file based on a string location
JTools.include = function(str, bool){
		if(typeof(str)!='string'){
			alert('Error: File Location is not a string.');
			return false;
		}
		if(typeof(bool)!='boolean'){
			alert('Error: Stylesheet must be true or false.');
			return false;
		}
			if(bool == true){
				var insert_in = document.getElementsByTagName('head')[0];
				var style_link = document.createElement('link');
				style_link.setAttribute('rel', 'stylesheet');
				style_link.setAttribute('type', 'text/css');
				style_link.setAttribute('href', str);
				insert_in.appendChild(style_link);
				return true;			
			}else{
				var included_scripts = document.getElementsByTagName('script');
				for(var i=0; i<included_scripts.length; i++){
					if(included_scripts[i].src){
						if((included_scripts[i].src.toString() == 'http://'+document.domain+str) || included_scripts[i].src.toString() == str || included_scripts[i].id.toString() == str){
							var included_flag = true;
							break;
						}
					}
				}
				if(included_flag != true){
					var insert_in = document.getElementsByTagName('body')[0];
					var script_src = document.createElement('script');
					script_src.setAttribute('language', 'javascript');
					script_src.setAttribute('id', str);
					script_src.setAttribute('type', 'text/javascript');
					new Ajax.Request(
						str,
						{
							method:'get',
							on200:function(transport){
								script_src.text = transport.responseText;
								insert_in.appendChild(script_src);
							},
							asynchronous: false
						}
					);
					return true;
				}else{
					return false;	
				}
			}
};
//Function Name: JTools.createDOMElement(<type of element (a div, etc.) as a string>,<stylesheet c_nameName as string or boolean false>,<array of attribute objects ([{name:'id', 'artist_0'}, {name:'style', 'position:relative;margin:0px'}])>,<text to display as a string>);
//Edited: 8/6/2007
//Editor: Jack Viers: Manager-Production
//Output: If prototype is included, an extended element, otherwise a regular element
JTools._createDOMElement = function(type, c_name, attribs, display_text){
	try{
		var element = document.createElement(type);
		for(var i = 0; i<attribs.length; i++){
			element.setAttribute(attribs[i].name, attribs[i].value);	
		}
		if(c_name != false){
			element.className = c_name;
		}
		if(display_text){
			var element_text = document.createTextNode(display_text);
			element.appendChild(element_text);
		}
		//does prototype exist?return extended element:return element
		if(Element.extend){
			return Element.extend(element);	
		}else{
			return element;	
		}
	}catch(e){
		alert(e.message);	
	}
};
JTools.addLoadEvent = function(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			func;
			oldonload;
		}
	}
};
