/**
 * @author Tan
 */
var element = null;
var url = '<img src="/wp-content/themes/newmark/images/image';
var topImage = "invisible";
var x = 1;
var y = 0;
var speed = 3500;

function fadein() {
	y += .1;
	z = y*100;
	element.style.opacity = y;
	element.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity=' + z + ')';
	if (element.style.opacity < 1) {
		setTimeout(fadein,40);
	} else {
		setTimeout(swap,speed);
	}
}

function fadeout() {
	y -= .1;
	z = y*100;
	element.style.opacity = y;
	element.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity=' + z + ')';
	if (element.style.opacity > 0) {
		setTimeout(fadeout,40);
	} else {
		setTimeout(swap,speed);
	}
}

function swap() {
	if (x < 3) {
		x++;
	} else {
		x = 1;
	}
	
	if (topImage == "invisible") {
		element.innerHTML = url + x + '.png" alt="" />';
		topImage = "visible";
		fadein();
	} else {
		topImage = "invisible";
		document.getElementById("first").innerHTML = url + x + '.png" alt="" />';
		fadeout();
	}
}

function init() {
	element = document.getElementById("second");
	element.style.opacity = 0;
	element.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity=0)';
	setTimeout(swap,speed);
}
