	var play = 0;
	var interval = 0;
	
	var i;
	for (i = 1; i <= 3; i++)
	{
		preload_image = new Image(1600, 700); 
		preload_image.src="./img/bg/"+files[i];		
	}
	
	$(document).ready(function()
		{
	       	init();
		});

	$(window).load(function()
	{
		$(window).bind("resize", function()
		{
			resize();
       	});

       	resumeInterval();
		//interval = setInterval('changeSlide("img/bg/", max);', 4000);


    	$('#navi-ne').mouseover(function() 
    	{
    		$('#navi-ne').attr('src', 'img/next-over.jpg');
    	});
		$('#navi-ne').mouseout(function() 
    	{
    		$('#navi-ne').attr('src', 'img/next.jpg');
    	});

///////

     	$('#navi-pa').mouseover(function() 
    	{
    		$('#navi-pa').attr('src', 'img/pause-over.jpg');
    	});
    	$('#navi-pa').mouseout(function() 
    	{
			if (play != 0)
    		$('#navi-pa').attr('src', 'img/pause.jpg');
    	});

///////

    	$('#navi-pr').mouseover(function() 
    	{
    		$('#navi-pr').attr('src', 'img/prev-over.jpg');
    	});
    	$('#navi-pr').mouseout(function() 
    	{
    		$('#navi-pr').attr('src', 'img/prev.jpg');
    	});
    		
	});

	function pauseInterval()
	{
	   clearInterval(interval);
	   play = 0;
	   interval = 0;
	}

	function resumeInterval() 
	{
		if (!interval)
		{
	   		interval = setInterval('changeSlide("img/bg/", max);', 5000);
	   		play = 1;
		}
	}

	function toggleInterval()
	{
		if (play == 1)
		{
			pauseInterval();
			$('#navi-pa').attr('src', 'img/pause-over.jpg');
		}
		else
		{
			resumeInterval();
			$('#navi-pa').attr('src', 'img/pause.jpg');
		}
	}
	
	function next()
	{
		//Avoid immediate change after next
		if (play == 1)
		{
			pauseInterval();
			resumeInterval(); 
		}
		changeSlide('img/bg/', max);
	}
	
	function prev()
	{
		//Avoid immediate change after prev
		if (play == 1)
		{
			pauseInterval();
			resumeInterval(); 
		}
		changeBackSlide('img/bg/', max);
	}	
