var manset_loaded;
var manset_ind = 0;
var manset_count = 0;
var manset_count_loaded = 0;
var manset_all_loaded = false;
var manset_timeout = null;

function GalleryInit(count) {
	manset_count = count;
	// boolean array to track image load
	manset_loaded = new Array(manset_count);
	for (var i = 0; i < manset_count; i++) {
		manset_loaded[i] = false;
	}
}

// bir manşet resmi yuklendi mi?
function GalleryLoaded(index) {
	// var index = parseInt(ths.getAttribute("mansetInd"), 10);
	
	if (!manset_loaded[index]) {
		manset_loaded[index] = true;
		manset_count_loaded ++;
		
		// all are loaded, start animation
		if (manset_count_loaded == manset_count) {
			manset_all_loaded = true;
			GallerySwitch2();
		}
	}
}

function GaleryAttachOnLoad() {
	for (var i = 0; i < manset_count; i++) {
		var img = document.getElementById("imgManset" + i);
		img.setAttribute("mansetInd", i);
		img.onload = function() {
			 GalleryLoaded(this);
		};
	}
}

// ana sayfa manşet animasyonu
function LoadGallery(index, manual) {
	var divOuter = document.getElementById("divMansetOuter");
	var divOld = document.getElementById("divManset" + manset_ind);
	manset_ind = index;
	var divNew = document.getElementById("divManset" + manset_ind);
	
	if (isIE55up) {
		if (!divOuter.filters.BlendTrans) {
			divOuter.style.filter="BlendTrans(duration=0.500)";
		}
		divOuter.filters.BlendTrans.apply();
	}
	
	divOld.style.display = "none";
	divNew.style.display = "block";

	if (isIE55up) {
		divOuter.filters.BlendTrans.play();
	}
	
	if (manual)
		GalleryClearSwitch();
	else
		GallerySwitch2();
}

// sonraki resme geç
function GallerySwitch() {
	if (manset_count <= 0) return;
	
	var next_manset_ind = (manset_ind + 1) % manset_count;
	LoadGallery(next_manset_ind, false);
}

// zamanlı geçişi durdur
function GalleryClearSwitch() {
	if (manset_timeout != null) {
		clearTimeout(manset_timeout);
		manset_timeout = null;
	}
}

// zamanlı geçiş başlat
function GallerySwitch2() {
	GalleryClearSwitch();
	manset_timeout = setTimeout("GallerySwitch()", 5000);
}
