$(document).ready(function() { $('.lightbox_image').lightbox(); });

function wrexSbDelete(id, type)
{
	$.get('shoutbox/delete/'+id, function(response) {
		if(response != 'OK')
		{
			alert('Error');
		}
		else
		{
			wrexSbRefresh(type);
		}
	});
}

function wrexSbRefresh(type)
{
	$.get('shoutbox/get/'+type, function(response) {
		$('#shoutbox-posts-'+type).html(response);
	});
}

function wrexSbPost(type, input)
{	
	value = $('#'+input).val();

	$('#shoutbox-send-'+type).attr('disabled', true); 
	$('#shoutbox-refresh-'+type).attr('disabled', true);
	
	$.post('shoutbox/post/'+type, { content: value }, function(response) {
		if(response != 'OK')
		{
			alert('Error');
		}
		else
		{
			$('#'+input).val('');
			wrexSbRefresh(type);
		}
		
		$('#shoutbox-send-'+type).removeAttr('disabled');
		$('#shoutbox-refresh-'+type).removeAttr('disabled');
	});
}

function wrexMenuSwitch(id)
{
	// Hide
	$('.menuSub').css('display', 'none');
	$('#menuTop li.active').removeClass('active');
	
	// Show
	$('#menuSub-'+id).show('slow');
	$('#menuTop-'+id).addClass('active');
}

function wrexUserAutocomplete(id)
{
	$('#'+id).autocomplete('index.php?kohana_uri=messages/autocomplete');
}

function validateRegister(field, myvalue)
{
	if(!myvalue || myvalue == 'http://')
	{
		$('#error-'+field).fadeOut('slow');
		return;
	}

	if(field == 'password2')
	{
		data = { value: myvalue, password: document.getElementById('password').value };
	}
	else
	{
		data = { value: myvalue };
	}

	$.post('register/check_field/'+field, data,
	function(data)
	{
		$('#error-'+field).text(data).fadeIn('slow');
	}
	);
}

function wrexOpenWindow(id, url, width, height)
{
	return window.open(url, id, 'width='+width+',height='+height+',toolbar=no,menubar=no,scrollbars=yes');
}

function validateUcp(field, myvalue)
{
	if(!myvalue || myvalue == 'http://')
	{
		$('#error-'+field).fadeOut('slow');
		return;
	}

	$.post('profile/check_field/'+field, { value: myvalue },
	function(data)
	{
		$('#error-'+field).text(data).fadeIn('slow');
	}
	);
}

function doDeleteComment(data)
{
	if(!data)
	{
		alert('Error');
		return;
	}

	$('#comment-id-'+data).hide('slow');
}

function deleteComment(id)
{
	$.get('comments/delete/'+id, doDeleteComment);
}

function refreshRelation(id, ms)
{    
    setInterval('doRefreshRelation('+id+')', ms);
}

function doRefreshRelation(id)
{
    $('#ajaxLoader').css('display', 'block');
    $.get('relations/refresh/'+id, function(data) {
        $('#relation-container').html(data);
        $('#ajaxLoader').fadeOut('slow');
    });
}
