var count=new Array();
var small_value = 0.0;
var big_value 	= 1.0;
var duration_value_shrink = 0.1;
var duration_value_expand = 0.2;

function OutsideElement(elemId,e) {
	e = e || window.event;
	
	var theElem = getEventTarget(e);
	while(theElem != null) {
		if(theElem.id == elemId)
			return false;
		
		theElem = theElem.offsetParent;
	}
	return true;
}

function getEventTarget(evt) {
	var targ = (evt.target) ? evt.target : evt.srcElement;

	if(targ != null) {
		if(targ.nodeType)
			targ = targ.parentNode;
	}
	return targ;
}
function isEven(num) {
	return !(num % 2);
}
function stopoutscroll() {
	document.getElementsByTagName('html')[0].style.overflowY = 'hidden';
}
function size_work_post(id, type) {	
	if (type=='expand')
	{
		if (count[id]!=1)
		{
			$('work_post_'+id).className = 'work_post_hover';
			count[id]=1;
		}
	}
}
function show_hide_about() {
	if ($('about_overlay').style.display == 'none' && $('about_content_container').style.display == 'none')
	{
	 	$('about_overlay').style.display = 'block';
		$('about_content_container').style.display = 'block';
		document.getElementsByTagName('html')[0].style.overflow = 'hidden';
	}
	else
	{
	 	$('about_overlay').style.display = 'none';
		$('about_content_container').style.display = 'none';
		document.getElementsByTagName('html')[0].style.overflow = 'auto';
	}
}
function hideworkpost(e) {
	for (a=1; a<=10; a++)
	{
		var now_id = count[a];
		if (now_id!=0 && now_id!='undefined' && now_id)
		{
			if(OutsideElement('work_post_'+a,e) && OutsideElement('comment_container',e))
			{
				
			
				$('work_post_'+a).className = 'work_post';
				$('comment_container').style.display = 'none';
				
				
				document.getElementsByTagName('html')[0].style.overflowY = 'scroll';
				
				count[a] = 0;
			}
		}
	}
}

function show_comments(id, num) {
	var comments = document.getElementById('posts');
	var comment_div = document.getElementById('comment_container');
	
	comments.innerHTML = '';
	
	$('comment_submit').lang = id;
	
	comment_div.style.display = 'block';
	
	if (isEven(num))
	{
		comment_div.style.left = '50px';
		comment_div.style.top = (num/2-1)*190+27+'px';
	}
	else
	{
		comment_div.style.left = '375px';
		comment_div.style.top = (num/2-1)*190+122+'px';
	}
	new Ajax.Request('/includes/comment_print.php', {
		method: 'post',
		parameters: {'id': id},
		onSuccess: function(transport) 
		{
			comments.innerHTML = transport.responseText;
		}
	});
	
}
function submit_comment() {
	var id = $('comment_submit').lang;
	var author = $('comment_post_author').value;
	
	var message = $('comment_post_message').value;
	
	if (author=='')
	{
		$('comment_post_author').focus();
		return false;
	}
	if (message=='')
	{
		$('comment_post_message').focus();
		return false;
	}
	
	$('comment_post_author').value = '';
	$('comment_post_message').value = '';
	
	new Ajax.Request('/includes/comment_post.php', {
		method: 'post',
		parameters: {'id': id, 'author': author, 'message': message},
		onSuccess: function(transport) 
		{
			comments = document.getElementById('posts');
			new Ajax.Request('/includes/comment_print.php', {
				method: 'post',
				parameters: {'id': id},
				onSuccess: function(transport) 
				{
					comments.innerHTML = transport.responseText;
					$('comments').scrollTop = $('comments').scrollHeight;
				}
			});
		}
	});
}