function vote ( image_id, value ) {
	
	if ( isVoted( image_id ) ) return false;
	
	var vote_value = 0;
	
	try {
		vote_value = parseInt( value );
		vote_value = ( vote_value < 1 || vote_value > 5 ) ? 1 : vote_value;
	} catch( e ) {
		vote_value = 1;
	}
	
	var url = root_url + 'index.php';
	var params = 'act=gallery/vote&image_id=' + image_id + '&vote_value=' + vote_value;
	
	var ajaxRequest = new Ajax.Request(
		url, {
			method: 'get',
			parameters: params,
			onSuccess: function ( req ) {
				try {
					var result = req.responseText;
					
					if ( result ) {
						
						var array = result.split( '|' );
						
						if ( array[0] && array[1] ) {
							
							$( 'rating' ).innerHTML = array[0];
							$( 'vote_count' ).innerHTML = array[1];
							
							setDataToCookie( 'voting_for_image_' + image_id, vote_value );
						}
					}
				} catch( e ) {
				}
			}
		}
	);
}

function isVoted( image_id ) {
	
	if ( !allowVote() ) return true;
	
	var cookie = getDataFromCookie( 'voting_for_image_' + image_id );
	
	if ( cookie && cookie >= 1 && cookie <= 5 ) return true;
	
	return false;
}

function allowVote() {
	
	var currentDateTime = new Date();
	var currMonth = (currentDateTime.getMonth() + 1).toString();
	var currDay = currentDateTime.getDate().toString();
	
	var currentDateTimeString = currentDateTime.getFullYear() + '-' +
								( ( currMonth.length == 1 ) ? ( '0' + currMonth ) : currMonth ) + '-' +
								( ( currDay.length == 1 ) ? ( '0' + currDay ) : currDay ) + ' ' +
								currentDateTime.getHours() + ':' +
								currentDateTime.getMinutes() + ':' +
								currentDateTime.getSeconds();
	
	if ( currentDateTimeString > '2008-05-18 23:59:59' && currentDateTimeString < '2008-05-19 23:59:59' ) return false;
	
	return true;
}