var transitions = [
	"progid:DXImageTransform.Microsoft.Barn()",
	"progid:DXImageTransform.Microsoft.Blinds()",
	"progid:DXImageTransform.Microsoft.CheckerBoard()",
	"progid:DXImageTransform.Microsoft.Fade()",
	"progid:DXImageTransform.Microsoft.GradientWipe()",
	"progid:DXImageTransform.Microsoft.Inset()",
	"progid:DXImageTransform.Microsoft.Iris()",
	"progid:DXImageTransform.Microsoft.Pixelate(maxSquare=15)",
	"progid:DXImageTransform.Microsoft.RadialWipe()",
	"progid:DXImageTransform.Microsoft.RandomBars()",
	"progid:DXImageTransform.Microsoft.RandomDissolve()",
	"progid:DXImageTransform.Microsoft.Slide()",
	"progid:DXImageTransform.Microsoft.Spiral()",
	"progid:DXImageTransform.Microsoft.Stretch()",
	"progid:DXImageTransform.Microsoft.Strips()",
	"progid:DXImageTransform.Microsoft.Wheel()",
	"progid:DXImageTransform.Microsoft.Zigzag()"
];

var indexGallery = {};
indexGallery.akt = 0;
indexGallery.lapoz = 0;
indexGallery.preloadImages = new Array();
indexGallery.video = 0;
indexGallery.max = 6;
indexGallery.intervalTimer = null;
indexGallery.Init = function()
{
	indexGallery.buttons = $("pagebar_right").getElementsByTagName("a");
	for (var i = 0; i <= 6; i++)
	{
		this.preloadImages[i] = new Image();
		this.preloadImages[i].src = "thumbnail/"+indexPictures[i][0]+"/692x323fill";
		indexGallery.buttons[i].index = i;
		indexGallery.buttons[i].onclick = function() { clearInterval(indexGallery.intervalTimer); indexGallery.SetPicture(this.index); return false; };
	}
	indexGallery.elem = $("mainpicture");
	indexGallery.oldHTML = $("mainpicturebox").innerHTML;
	indexGallery.filtersupport = isIE;
	indexGallery.swf = 0;
};

indexGallery.setopacity = function(el, degree) { 
	if (typeof el.style.opacity != "undefined") {
		el.style.opacity = degree;
	}
	else {
		el.style.MozOpacity = degree;
	}
	el.currentopacity = degree;
};

indexGallery.hideTransition = function() {
	if (indexGallery.filtersupport) {
		$("mainpicturebox").filters[0].apply();
	}
	else {
		indexGallery.setopacity($("mainpicturebox"), 0);
	}
};

indexGallery.playEffect = function() {
	if (indexGallery.filtersupport) {
		$("mainpicturebox").filters[0].play(1);
	}
	else {
		$("mainpicturebox").fadetimer = setInterval(function() {
			if ($("mainpicturebox").currentopacity < 1)
				indexGallery.setopacity($("mainpicturebox"), $("mainpicturebox").currentopacity + 0.1);
			else
				clearInterval($("mainpicturebox").fadetimer);
		}, 50); //end setInterval
	}

};

indexGallery.SetPicture = function(akt) {
	if (this.akt == akt) return;
	this.buttons[this.akt].id = "";
	this.akt = akt;
	this.buttons[this.akt].id = "actualp"+ (this.akt+1);
	if (!this.swf) {
		if (this.video) {
			$("mainpicturebox").innerHTML = indexGallery.oldHTML;
			this.elem = $("mainpicture");
			this.video = 0;
		}
		if (indexGallery.filtersupport) {
			var effectindex = 3; //Math.floor(Math.random()*transitions.length);
			$("mainpicturebox").style.filter = transitions[effectindex];
		}
		indexGallery.hideTransition();
		this.elem.src = "thumbnail/" + indexPictures[this.akt][0] + "/692x323fill";
		this.elem.alt = indexPictures[this.akt][1];
		this.elem.title = indexPictures[this.akt][1];
		$("pagebar_left").innerHTML = indexPictures[this.akt][1];
		indexGallery.playEffect();
	}
};

window.onload = function() {
	indexGallery.Init();
	indexGallery.intervalTimer = setInterval(function() {
		indexGallery.lapoz++;
		if(indexGallery.lapoz > 6) indexGallery.lapoz = 0;
		indexGallery.SetPicture(indexGallery.lapoz);
	}, 3000);
};
