// JavaScript Document
i=0; 
j=0;

function start() {
	slide = SlideChange();
	realtor = RealtorChange();
}

function SlideChange() {
	// Split the /n/ delimited listings into an array
	listings = document.hiddenlistings.alllistings.value.split(' /n/ ');
	//alert(listings[0]); // The first listing
	if (listings[i]=="") { i=0; /* start over */ }
	listing = listings[i].split(' / ');
	nextlisting = listings[i+1].split(' / ');
	pic1= new Image(400,300); 
	pic1.src="/listingpictures/QUADCITIES" + nextlisting[3] + ".jpg";
	i++; //increment i so we go to the next listing
	elem("Address").innerHTML = "<a href='/" + listing[2] + "/listing.php?mls=" + listing[3] + "' style='text-decoration:none; color:#fff;'>"+ listing[0] + "</a>";
	elem("Price").innerHTML = "$" + listing[1];
	elem("Image").innerHTML = "<a href='/" + listing[2] + "/listing.php?mls=" + listing[3] + "' style='text-decoration:none;'><img src='/listingpictures/QUADCITIES" + listing[3] + ".jpg' /></a>";
	//elem("SlideLeft").innerHTML = "<span class='address'>" + listing[0] + "</p>" +
	//	"<br /><span class='price'>$" + listing[1] + "</span>" + 
	//	"<img src='/listingpictures/QUADCITIES" + listing[2] + ".jpg' width='400px' />";
	newlisting=setTimeout('SlideChange()', 7000);
}

function RealtorChange() {
	// Split the /n/ delimited listings into an array
	realtors = document.hiddenlistings.allrealtors.value.split(' /n/ ');
	//alert(realtors[0]); // The first listing
	if (realtors[j]=="") { j=0; /* start over */ }
	realtor = realtors[j].split(' / ');
	if (realtors[j+1]=="") {  
		j=0;
		nextrealtor = realtors[j].split(' / ');
	} else {
		nextrealtor = realtors[j+1].split(' / '); 
		j++; //increment i so we go to the next listing
	}
	if (realtors[j+2]>"") { 
		deckrealtor = realtors[j+2].split(' / '); 
		pic1= new Image(100,80); 
		pic1.src="/staff/staffphotos/" + deckrealtor[0];
	}
	elem("SlideRight").innerHTML = "<span class='title'>" + realtor[1] + "</span>" +
		"<img src='/staff/staffphotos/" + realtor[0] + "' width='80px' />" +
		"<span class='phone'>" + realtor[2] + "</span><span class='email'>" + realtor[3] + "</span>" +
		"<span class='title'>" + nextrealtor[1] + "</span>" +
		"<img src='/staff/staffphotos/" + nextrealtor[0] + "' width='80px' />" +
		"<span class='phone'>" + nextrealtor[2] + "</span><span class='email'>" + nextrealtor[3] + "</span>";
	newrealtor=setTimeout('RealtorChange()', 4000);
}

function elem(id)
{ // compat element grabber
        if(document.all) { return document.all(id); }
        else if (document.getElementById) { return document.getElementById(id); 
}
        return new Array(); // hides angry errors in buggy situations
}

//*****************************************************************************
// Start of the Fade Functions
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 + ")"; 
}

/*function shiftOpacity(id, millisec) { 
    //if an element is invisible, make it visible, else make it ivisible 
    if(document.getElementById(id).style.opacity == 0) { 
        opacity(id, 0, 100, millisec); 
    } else { 
        opacity(id, 100, 0, millisec); 
    } 
}*/
