function slideShower(starty,startx,finaly,finalx,i)
{
	var pic = document.getElementById('slideshow');
	if(starty - finaly == 5 || startx - finalx == 5 || starty - finaly == -5 || startx - finalx == -5)
	{
		fadeOut(1,i);
	}
	if(starty - finaly == 0 && startx - finalx == 0)
	{
		return;
	}
	
	var increment = parseInt(1);
	if(starty - finaly !== 0) //if there is a difference between the start and finish coords (i.e. it hasn't finished)
	{
		if(starty - finaly > 0)// if the difference is positive - it's going towards the right
		{
			starty = parseInt(starty) - increment;
		}
		else// if the difference is negative - it's going towards the left
		{
			starty = parseInt(starty) + increment;
		}
	}
	
	if(startx - finalx !== 0) //if there is a difference between the start and finish coords (i.e. it hasn't finished)
	{
		if(startx - finalx > 0)// if the difference is positive - it's moving upwards
		{
			startx = parseInt(startx) - increment;
		}
		else// if the difference is negative - it's moving downwards
		{
			startx = parseInt(startx) + increment;
		}
	}
	pic.style.left = starty+'px';
	pic.style.top = startx+'px';

	setTimeout('slideShower('+starty+', '+startx+', '+finaly+', '+finalx+', '+i+')',40);
}

function picSwapper(i)
{
	var slideshowHeight = Math.round(screen.availHeight/3);
	var shrinkage = slideshowHeight/400;
	var pic = document.getElementById('slideshow');
	pic.src = '/images/'+loocation+'/big_pic'+i+'.jpg';
	document.getElementById('slideshower').style.height = slideshowHeight + 'px';
	
	///preload the next image
	if(i == 4)
	{
		var next_pic = 1;
	}
	else
	{
		var next_pic = parseInt(i+1);
	}
	preload_image = new Image();
	preload_image.src = '/images/'+loocation+'/big_pic'+ next_pic +'.jpg';

	////sort out how big the image is and how far it has to go once it has been scaled down
	if(big_pics[i][0] == 'up')
	{
		var pic_width = screen.availWidth;
		var shrinkage = screen.availWidth/big_pics[i][1];
		var pic_height = Math.round(big_pics[i][2]*shrinkage);
		var movement = slideshowHeight - pic_height;
		var starty = 0;
		var startx = 0;
		var finaly = 0;
		var finalx = movement;
	}
	
	if(big_pics[i][0] == 'down')
	{
		var pic_width = screen.availWidth;
		var shrinkage = screen.availWidth/big_pics[i][1];
		var pic_height = Math.round(big_pics[i][2]*shrinkage);
		var movement = slideshowHeight - pic_height;
		var starty = 0;
		var startx = movement;
		var finaly = 0;
		var finalx = 0;
	}
	
	if(big_pics[i][0] == 'right')
	{
		var pic_height = slideshowHeight;
		var shrinkage = slideshowHeight/big_pics[i][2];
		var pic_width = Math.round(big_pics[i][1]*shrinkage);
		var movement = screen.availWidth - pic_width;
		var starty = movement;
		var startx = 0;
		var finaly = 0;
		var finalx = 0;
	}
	
	if(big_pics[i][0] == 'left')
	{
		var pic_height = slideshowHeight;
		var shrinkage = slideshowHeight/big_pics[i][2];
		var pic_width = Math.round(big_pics[i][1]*shrinkage);
		var movement = screen.availWidth - pic_width;
		var starty = 0;
		var startx = 0;
		var finaly = movement;
		var finalx = 0;
	}
	
	pic.style.width = pic_width + 'px';
	pic.style.height = pic_height + 'px';
	fadeIn (starty,startx,finaly,finalx,i,0);
}

function fadeIn (starty,startx,finaly,finalx,i,opac)
{
	var pic = document.getElementById('slideshow');
	if(opac == 0)
	{
		slideShower(starty,startx,finaly,finalx,i);
	}
	if(opac == 1)
	{
		pic.style.opacity = 1;
		return;
	}
	pic.style.opacity = opac;
	pic.style.filter = 'alpha(opacity=' + opac*100 + ')';
	opac = opac + 0.1;
	opac = Math.round(opac*10)/10;
	setTimeout('fadeIn('+starty+', '+startx+', '+finaly+', '+finalx+', '+i+', '+opac+')',20); // rerun the function every 20ms
}

function fadeOut (opac,i)
{
	if(opac == 0)
	{
		if(i == 4)
		{
			i = 1;
		}
		else
		{
			i++;
		}
		picSwapper(i)
		return;
	}
	var pic = document.getElementById('slideshow');
	pic.style.opacity = opac;
	pic.style.filter = 'alpha(opacity=' + opac*100 + ')';
	opac = opac - 0.1;
	opac = Math.round(opac*10)/10;
	setTimeout('fadeOut('+opac+', '+i+')',20); // rerun the function every 20ms
}

