var images = new Array();
images[0] = 'images/gallery/0.jpg';
images[1] = 'images/gallery/1.jpg';
images[2] = 'images/gallery/2.jpg';
images[3] = 'images/gallery/3.jpg';
images[4] = 'images/gallery/4.jpg';
images[5] = 'images/gallery/5.jpg';
images[6] = 'images/gallery/6.jpg';
images[7] = 'images/gallery/7.jpg';
images[8] = 'images/gallery/8.jpg';
images[9] = 'images/gallery/9.jpg';
images[10] = 'images/gallery/10.jpg';
images[11] = 'images/gallery/11.jpg';
images[12] = 'images/gallery/12.jpg';
images[13] = 'images/gallery/13.jpg';
images[14] = 'images/gallery/14.jpg';


var cur=0;


function returnObjById( id )
{
    if (document.getElementById)
        var objectID = document.getElementById(id);
    else if (document.all)
        var objectID = document.all[id];
    else if (document.layers)
        var objectID = document.layers[id];
    return objectID;
}



function next()
{
	cur++;

	if (cur>14)
	{
		cur=0;
	}
	
	runner();
}
	
function previous()
{
    cur--;
		
	if (cur<0)
	{
		cur=14;
	}
	
	runner();
}

function runner()
{
	var t=setTimeout(function () {opacity('main_image', 100, 0, 200)},200);
	var r=setTimeout(function () {returnObjById('main_image').src=images[cur]},400);
	var y=setTimeout(function () {opacity('main_image', 0, 100, 200)},600);
}

function opacity(id, opacStart, opacEnd, millisec) 
{
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) 
	{
        for(i = opacStart; i >= opacEnd; i--) 
			{
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
			}
    } 
	else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
			}
    }
	
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 
