/*
 *  Slide function for moving objects on the screen
 *
 *  Author: Artur Thiessen
 *
 *  obj			: ID of the object to slide (String)
 *  x  			: amout of pixels you want the object to slide along the x axis (int)
 *  y  			: amout of pixels you want the object to slide along the y axis (int)
 *  alphaForth	: change opacity while moving one way (float)
 *  alphaBack	: change opacity while moving the other way (float)
 *  mode		: 'linear' or 'swing' (String)
 *  time		: amout of time the object is supposed to move (milliseconds)
 *  cycle		: TRUE for moving the object back and forth, FALSE for only moving the object once (boolean)
 */
function slide(obj, x, y, alphaForth, alphaBack, mode, time, cycle) {
	if(x != 0 || y != 0){
		jQuery('#' + obj).animate({
			marginLeft: x + 'px',
			marginTop: y + 'px',
			opacity: alphaForth
		}, time, mode);
		if(cycle == true) {
			setTimeout(function(){
				jQuery('#' + obj).animate({
					marginLeft: (x * -1) + 'px',
					marginTop: (y * -1) + 'px',
					opacity: alphaBack
				}, time, mode);
			}, time);
			setTimeout(function(){
				slide(obj, x, y, alphaForth, alphaBack, mode, time, cycle);
			}, time);
		}
	}else{
		changeOpacity(obj, alphaForth, alphaBack, mode, time, cycle);
	}
}

function changeOpacity(obj, alphaForth, alphaBack, mode, time, cycle){
	jQuery('#' + obj).animate({
		opacity: alphaForth
	}, time, mode);
	if(cycle == true) {
		setTimeout(function(){
			jQuery('#' + obj).animate({
				opacity: alphaBack
			}, time, mode);
		}, time);
		setTimeout(function(){
			changeOpacity(obj, alphaForth, alphaBack, mode, time, cycle);
		}, time);
	}
}
