/**
// Copyright (C) 2008 - 2010 Mike Feng Jinglong
//
// This program is a commercial software; you cannot redistribute it
// and/or modify it without the explicit consent from the author.
//
// All title and copyright in and to the Product is owned by Mike Feng
// and is protected by international copyright laws and treaty provisions.
// Mike Feng retains all ownership rights in the Product.
// The copyright notice must be reproduced and included on any copy
// that is expressly permitted under this Agreement.
**/

function makeProfilePic(aid,id) {
	var url = "/index2.php?option=com_simgallery&no_html=1&func=makeprofilepic&aid="+aid+"&id="+id;
	new Request({
		'url': url,
		'method': 'get',
		onRequest: function(){
		},
		onComplete: function(responseText) {
			var delimiter = responseText.indexOf('###');
			var avatar = responseText.substring(0,delimiter);
			var rest = responseText.substring(delimiter+3);
			//$('headerAvatar').href = "/images/comprofiler/" + avatar;
			if ($('headerAvatarThumb'))
				$('headerAvatarThumb').src = "components/com_simgallery/image.php?width=60&height=60&cropratio=1:1&image=/images/comprofiler/tn" + avatar;
			$('photo_output').innerHTML = rest;
			
			sginit('cmttext');
			alert('Profile picture updated.');
		},
		onFailure: function(){
			alert('There was an error with your request. Please try again later');
		}
	}).send();
}

function deleteComment(aid, id, cmtid) {
	var url = "/index2.php?option=com_simgallery&no_html=1&func=deletecomment&aid="+aid+"&id="+id+"&cmtid="+cmtid;
	new Request({
		'url': url,
		'method': 'get',
		onRequest: function(){
		},
		onComplete: function(responseText) {
			$('photo_output').innerHTML = responseText;
			sginit('cmttext');
			alert('Comment deleted.');
		},
		onFailure: function(){
			alert('There was an error with your request. Please try again later');
		}
	}).send();
}

function gotoPhoto(aid,id) {
	var url = "/index2.php?option=com_simgallery&no_html=1&func=detail2&aid="+aid+"&id="+id+"&currentURL="+$('currentURL').value;
	new Request({
		'url': url,
		'method': 'get',
		onRequest: function(){
			$('photo-container').setStyle('visibility','hidden');
			$$('div.message').setStyle('display','none');
		},
		onComplete: function(responseText) {
			$('photo_output').innerHTML = responseText;
			sginit('cmttext');
		},
		onFailure: function(){
			alert('There was an error with your request. Please try again later');
		}
	}).send();
}

function rotate(direction,aid,id) {
	var url = "/index2.php?option=com_simgallery&no_html=1&func=rotate&direction="+direction+"&aid="+aid+"&id="+id+"&currentURL="+$('currentURL').value;
	new Request({
		'url': url,
		'method': 'get',
		onRequest: function(){
			$('currentphoto').fade('out');
		},
		onComplete: function(responseText) {
			$('photo_output').innerHTML = responseText;
			sginit('cmttext');
		},
		onFailure: function(){
			alert('There was an error with your request. Please try again later');
		}
	}).send();
}

function sgVote(aid,id,rating,vip) {
	var url = "/index2.php?option=com_simgallery&no_html=1&func=vote";
	new Request({
		'url': url,
		'method': 'post',
		'data': {
			'aid': aid,
			'id': id,
			'rating': rating,
			'vip': vip
		},
		onRequest: function() {
			$('sgvote'+id).innerHTML = '<img src="'+live_site+'/components/com_simgallery/images/loading.gif" border="0" align="absmiddle" /> '+_SG_VOTE_UPDATING;
		},
		onComplete: function(responseText) {
			var responseArray = responseText.split('###');
			var votes = parseInt(responseArray[0]);
			var votesum = parseInt(responseArray[1]);
			var string = responseArray[2];
			setTimeout(function() {
				$('sgvote'+id).innerHTML = string;
				var percentage = (votesum / votes) * 20;
				$('rating'+id).style.width=percentage+'%';
			}, 1000);
			setTimeout(function() {
				$('sgvote'+id).innerHTML='('+_SG_VOTE_RATINGS+votes+')';
			}, 3000);
		},
		onFailure: function(){
			alert('There was an error with your request. Please try again later');
		}
	}).send();
}

