
function _getElement(id)
{
	if (document.getElementById && document.getElementById(id)) {
		return document.getElementById(id);
	}
	else if (document.all && document.all[id]) {
		return document.all[id];
	}
	else {
		return false;
	}
}

function _getParentElement(id)
{
	if (parent.document.getElementById && parent.document.getElementById(id)) {
		return parent.document.getElementById(id);
	}
	else if (parent.document.all && parent.document.all[id]) {
		return parent.document.all[id];
	}
	else {
		return false;
	}
}

function toggleBlock(id)
{
	var is_closed = (_getElement(id).style.display == 'none');
	
	_getElement(id).style.display = (is_closed) ? 'block' : 'none';
	_getElement(id+'pic').src = (is_closed) ? '/pics/dtable.opened.png' : '/pics/dtable.closed.png';
	
}

function setDisplay(id,dis)
{
	if (_getElement(id))
		_getElement(id).style.display = dis;
}

function openNewWindow(page,width,height)
{
	var newwin = window.open(page, '', 'screenX=20,screenY=20,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+(width)+',height='+(height));
	newwin.focus();
	return newwin;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
	var i;
	
    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = _getElement(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
	
    balloon_opacity = opacity;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function confirmRemove()
{
	return confirm("are you sure you want to remove this?");
}

var balloon_opacity = 0;
var balloon_timeout;

function showUserBalloon(username,content_id)
{
	clearTimeout(balloon_timeout);
	
	var url = '/ajax.username.php';
	var params = 'username=' + username;
	var ajax = new Ajax.Updater(
		'user_balloon',
		url,
		{method: 'get', parameters: params});
	
	_getElement('user_balloon').style.visibility = 'visible';
	
	var x = findPosX(_getElement(content_id)) + 5;
	var y = findPosY(_getElement(content_id)) - 10;
		
	_getElement('user_balloon').style.left = x + 'px';
	_getElement('user_balloon').style.top  = y + 'px';
	
	opacity('user_balloon',balloon_opacity,100,500);
}

function hideUserBalloon()
{
	balloon_timeout = setTimeout("_hideUserBalloon()",1000);	
	opacity('user_balloon',balloon_opacity,0,500);
	
}

function _hideUserBalloon()
{
	_getElement('user_balloon').style.visibility = 'hidden';
}

function showMyStuff()
{
	_getElement('my_stuff').style.visibility = 'visible';
}

function hideMyStuff()
{
	_getElement('my_stuff').style.visibility = 'hidden';
}

function showTags(tag_type)
{	
	_getElement('tags_'+tag_type).style.visibility = 'visible';
}

function hideTags(tag_type)
{
	_getElement('tags_'+tag_type).style.visibility = 'hidden';
}

function showGallery(content_image_id,width,height)
{
	var html = '<html><head><title>Large Image - Click Image to Close</title></head><body><table style="width: 99%; height: 99%"><tr><td style="width: 100%; height: 100%; vertical-align: middle; text-align: center"><a href="javascript:window.close()"><img src="/content_pics/' + content_image_id + '_large.jpg" border=0></a></td></tr></table></body></html>';
	
	var newwin = window.open('', '', 'screenX=20,screenY=20,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=no,width='+(width+50)+',height='+(height+50));
	newwin.document.write(html);
	newwin.focus();
	
	//_getElement('gallery').innerHTML = html;
	//_getElement('gallery').style.visibility = 'visible';
}

function hideGallery()
{
	_getElement('gallery').style.visibility = 'hidden';
}

function changeContent(cid)
{
	window.location.href = '/' + cid + '.html';
}

function videoChecked(vid, checked)
{
	_getElement('title'+vid).disabled = !checked;
	_getElement('tags'+vid).disabled = !checked;
}
