/*
 ***********************************************
 *                                             *
 *  This is not the Source you`re looking for  *
 *                                             *
 *          Move along. Move along!            *
 *       (Well, yeah, Star Wars rocks)         *
 *                                             *
 ***********************************************
 */

var onloadFunction = null;


function toggleSubMenu(parent_id) {
	var parent = getObj("main_" + parent_id);
	var obj = getObj("child_" + parent_id);
	
	if(!obj)
		return;
	
	if(parent) {
		parent.setAttribute("class", (obj.style.display == "none") ? "sub_expanded" : "sub_hidden");
		try { parent.blur(); } catch(e) {}
	}
	obj.style.display = (obj.style.display == "none") ? "block" : "none";
}

function showContactform() {
	popup("http://www.widgetschmie.de/contact.php", 500, 500);
}

function popup(url, width, height) {
	if(!url)
		return false;
	
	if(!width)
		var width = 500;
	if(!height)
		var height = 500;
	var screenwidth = screen.innerWidth ? screen.innerWidth : (screen.width ? screen.width : 1024);
	
	var addition = "width=" + width + ", height=" + height + ", top=60, left=" + ((screenwidth - width) / 2) + ", status=yes, menubar=no, scrollbars=auto";
	var pup = window.open(url, 'popup', addition);
	if(pup)
		pup.focus();
}


// launches a body.onload-function, if defined
function launchOnload() {
	if(null != onloadFunction) {
		setTimeout("onloadFunction()", 100);
	}
}


// formats the versiontracker rating
var vt_starid = 0;
function addVTstars() {
	try {
		var div = getObj(vt_starid);
		if(div) {
			var vtrating = div.innerHTML;
			var vtrating_rounded = Math.round(vtrating);
			
			if(0 == vtrating) {
				var span = document.createElement('span');
				span.setAttribute('class', 'small');
				span.innerHTML = '[not yet rated]';
				div.innerHTML = '';
				div.appendChild(span);
			}
			else if(vtrating) {
				var img = document.createElement('img');
				img.setAttribute('class', 'ratingImage');
				img.src = (_pathprefix ? _pathprefix : '') + "Images/rating_" + vtrating_rounded + ".png";
				var text = document.createTextNode(" (" + vtrating + ")");
				
				// compose
				div.innerHTML = '';
				div.appendChild(img);
				div.appendChild(text);
			}
		}
	}
	catch(exc) {  }
}


// returns the object, whether you supply an id (string) or an object itself
function getObj(id) {
	var obj;
	if(typeof(id) == "string") {
		obj = getById(id) ? getById(id) : null;
	}
	else if(typeof(id) == "object") {
		obj = id;
	}
	
	return obj;
}


// returns the object with the correspondent ID
function getById(id) {
	if(document.getElementById)
		return document.getElementById(id);
	else if(document.all)
		return document.all[id];
	else
		return false;
}


