// general 
 
 mailTo = function(pref, suf) {
	document.location.href='mailto:'+pref+'@'+suf;
 }
 
createMailto = function(pref, suf) {
	email = pref+'@'+suf;
	document.write('<a href="mailto:'+email+'">'+email+'</a>');
}

mouseOver = function(obj) {
	ext = obj.src.substring(obj.src.lastIndexOf('.'), obj.src.length);
	if (obj.src.indexOf('_o' + ext) == -1) obj.src = obj.src.replace(ext, '_o'+ext);
}

mouseOut = function(obj) {
	ext = obj.src.substring(obj.src.lastIndexOf('.'), obj.src.length);
	if (obj.src.indexOf('_o' + ext) != -1) obj.src = obj.src.replace('_o'+ext, ext);
}

var mouseX, mouseY;
document.onmousemove = function(e) {
	if (e) {
		mouseX = e.clientX; mouseY = e.clientY;
	} else {
		mouseX = event.clientX; mouseY = event.clientY;
	}
	if (document.body) {
		mouseX += document.body.scrollLeft;
		mouseY += document.body.scrollTop;
	} else if (document.documentElement) {
		mouseX += document.documentElement.scrollLeft;
		mouseY += document.documentElement.scrollTop;
	}
}

createFlashMovie = function(id, src, width, height, isSolid) {
	var str = '';
	str += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="'+id+'">';
	str += '<param name="allowScriptAccess" value="sameDomain" />\n';
	str += '<param name="movie" value="'+src+'" />\n';
	str += '<param name="quality" value="high" />\n';
	str += '<param name="menu" value="false" />\n';
	if (!isSolid) str += '<param name="wmode" value="transparent" />\n';
	str += '<embed src="'+src+'" quality="high" ';
	if (!isSolid) str += 'wmode="transparent" ';
	str += 'width="'+width+'" height="'+height+'" name="'+id+'" menu="false" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n';
	str += '</object>\n';
	document.write(str);
}

showPopup = function(lnk) {
	var url = lnk.href;
	var w = 400;
	var h = 420;
	var x = parseInt(screen.width / 2) - parseInt(w/2);
	var y = parseInt(screen.height / 2) - parseInt(h/2);
	var parameters = 'location=0,menubar=1,toolbar=1,scrollbars=0,width=' + w + ',height=' + h + ',top=' + y + ',left=' + x + ',screenY=' + y + ',screenX=' + x;
	var w = window.open(url, 'p', parameters);
	if (w.focus) w.focus();
	return false;
}

addCssClass = function(objectOrId, cssClass) {
	var obj = ((typeof(objectOrId) == 'string') ? document.getElementById(objectOrId) : objectOrId);
	var c = obj.className + ' ';
	if (c.indexOf(cssClass + ' ') == -1) obj.className = c + cssClass;
}	

removeCssClass = function(objectOrId, cssClass) {
	var obj = ((typeof(objectOrId) == 'string') ? document.getElementById(objectOrId) : objectOrId);
	var c = obj.className + ' ';
	obj.className = c.replace(cssClass + ' ', '');
}		

hide = function(obj) {
	addCssClass(obj, 'hidden');
}


openImagePopup = function(src) {
	var myImg = new Image();
	myImg.onload = function() {
		var w = this.width;
		var h = this.height;
		var scrollbars = 0;
		if (w > screen.availWidth) { w = screen.availWidth; scrollbars = 1; }
		if (h > screen.availHeight) { h = screen.availHeight; scrollbars = 1; }
		var url = '/image.php?src='+escape(src);
		openMediaPopup(url, w, h);
	}
	myImg.src = src;
}

openVideoPopup = function(src) {
	var w = 384; var h = 308; // var w = 680; var h = 510;
	var url = '/video.php?src='+escape(src);
	openMediaPopup(url, w, h);
}

openAudioPopup = function(src) {
	var w = 400; var h = 120;
	var url = '/audio.php?src='+escape(src);
	openMediaPopup(url, w, h);
}

openMediaPopup = function(src, w, h) {
	var x = parseInt(screen.width/2) - parseInt(w/2);
	var y = parseInt(screen.height/2) - parseInt(h/2);
	var parameters = 'toolbar=0,location=1,status=0,menubar=0,toolbar=0,scrollbars=0,width=' + w + ',height=' + h + ',top=' + y + ',left=' + x + ',screenY=' + y + ',screenX=' + x;
	var d = new Date();
	var name = 'pop' + d.getTime();
	var w = window.open(src, name, parameters);
	if (w.focus) w.focus();
}

initLinks = function() {
	links = document.getElementsByTagName('A');
	for (var i=0; i<links.length; i++) {
		if (links[i].href) {
			var href = links[i].href.toLowerCase();
			if ((href.indexOf('.jpg') != -1) || (href.indexOf('.jpeg') != -1) || (href.indexOf('.gif') != -1)) {
				links[i].onclick = function() {
					openImagePopup(this.href);
					return false;
				}
			}
			
			if (href.indexOf('.flv') != -1) {
				links[i].onclick = function() {
					openVideoPopup(this.href);
					return false;
				}
			}
			
			if (href.indexOf('.mp3') != -1) {
				links[i].onclick = function() {
					openAudioPopup(this.href);
					return false;
				}
			}
		}
	}
}

window.onload = function() {
	initLinks();	
}

