/*

	Define Global Variables

	Logic - 2 div's. Each 1/2 the size of the total volume of feed items
	[ÖÖÖ][ÖÖÖ]
	These div's switch places so it seems seamless.

*/

rss = 0; // total RSS items
refreshrate = 90; // milliseconds
speed = 1; // pixels per [refresh rate]
rsswidth = 350; // RSS feed item width
rssinterval = null;

function startRSS() {
	
	var r_1 = $('container_1'); // RSS Container 1
	var r_2 = $('container_2'); // RSS Container 2
	
	var r1_left = parseInt(r_1.style.left);
	var r2_left = parseInt(r_2.style.left);	

	//alert(r1_left + " " + r2_left);

	if(r1_left > 830) {

		r_1.style.left = (parseInt(r_2.style.left)+parseInt(r_1.style.width)*-1) + "px";
	
	}
	
	if(r2_left > 830) {
	
		r_2.style.left = (parseInt(r_1.style.left)+parseInt(r_2.style.width)*-1) + "px";	
	
	} 
	
	r_1.style.left = (parseInt(r_1.style.left) + speed) + "px";
	r_2.style.left = (parseInt(r_2.style.left) + speed) + "px";
	
}

function stopRSS() {
	
	clearInterval(rssinterval);

}

function restartRSS() {

	rssinterval = setInterval("startRSS()", refreshrate);

}

function init_item(id) {

	rss++;
	
	$(id).id = 'rss_' + rss;

}

function init_RSS() {

	var r_1 = $('container_1'); // RSS Container 1
	var r_2 = $('container_2'); // RSS Container 2
	
	if(rss % 2 == 0) { // Even
	
		r_1.style.width = ((rsswidth * rss)/2) + 'px';
		r_2.style.width = ((rsswidth * rss)/2) + 'px';	
		
		r_1.style.left = "0px";
		r_2.style.left = (parseInt(r_1.style.width) + "px");		
	
	} else { // Odd, need to compensate for additional item
	
		r_1.style.width = (((rsswidth * rss)/2)+rsswidth/2) + 'px'; // add a half size
		r_2.style.width = (((rsswidth * rss)/2)-rsswidth/2) + 'px'; // remove a half size
		
		r_1.style.left = "0px";
		r_2.style.left = (parseInt(r_1.style.width) + "px");				
		
	}
	
	rssinterval = setInterval("startRSS()", refreshrate);

}
