var flicker = {};
flicker.ticker_counter = Math.floor(Math.random() * 90);
flicker.disable_ajax = null;
flicker.total = 0;
flicker.total_divs = 0;
flicker.the_timeout_tick = 0;
flicker.retreive_ticker = function (id) {
	if (flicker.disable_ajax == null) {
		if (!flicker.ticker_content) {
			var ajax = new Ajax.Request('/index_homefeed.php', {
				method: 'post',
				parameters: 'action=ticker',
				onComplete: function (request) {
					flicker.ticker_content = eval(request.responseText);
					document.getElementById("ticker1").innerHTML = flicker.ticker_content[flicker.ticker_counter];
					document.getElementById("ticker2").innerHTML = flicker.ticker_content[flicker.ticker_counter + 1];
					flicker.ticker_counter = flicker.ticker_counter + 2
				}
			})
		}
	}
};
flicker.hasinit = false;
flicker.direction = 1;
flicker.init = function (ticker) {
	if (!ajax_check.check()) {
		document.getElementById('divandticker').style.display = "none";
		document.getElementById('baseline').style.display = "block"
	}
	if (ticker != 0) {
		flicker.retreive_ticker();
		flicker.the_timeout_tick = setTimeout('flicker.moveTicker();', 7000)
	}
	var flicker_cookie = flicker.readCookie();
	if (flicker_cookie) {
		var cookieValues = new Array();
		cookieValues = flicker_cookie.split('|');
		flicker.direction = cookieValues[0]
	}
};
flicker.start = function (total_divs) {
	flicker.the_timeout = setTimeout('flicker.moveFlicker(' + total_divs + ',' + flicker.direction + ');', 1000);
	flicker.flicker_running = 1
};
flicker.move_amount = 1;
flicker.move_amount_total = 150;
flicker.move_amount_total_min = -150;
flicker.the_timeout;
flicker.total_loop = 0;
flicker.speed = 4;
if (flicker.direction) {
	flicker.direction = flicker.direction
} else {
	flicker.direction = 1
}
flicker.flicker_running = 0;
flicker.speedy = 0;
flicker.moveFlicker = function (total, mydir) {
	if (mydir != flicker.direction) {
		mydir = flicker.direction;
		flicker.move_amount_total = 0;
		flicker.move_amount_total_min = 0
	}
	if (flicker.speedy == 1) {
		flicker.move_amount = 3
	}
	for (var x = 0; x < total; x++) {
		var move_div = "image" + x;
		var the_style = flicker.getStyleObject(move_div);
		if (the_style) {
			var current_left = parseInt(the_style.left);
			if (mydir == 2) {
				var new_left = current_left + flicker.move_amount;
				if (new_left >= (150 * (total - 1))) {
					new_left = -150
				}
			} else {
				var new_left = current_left - flicker.move_amount;
				if (new_left <= "-150") {
					new_left = 150 * (total - 1)
				}
			}
			if (document.layers) {
				the_style.left = new_left
			} else {
				the_style.left = new_left + "px"
			}
		}
	}
	if (mydir == 2) {
		flicker.total_loop = flicker.total_loop - flicker.move_amount;
		flicker.speed = Math.abs(flicker.total_loop) / 4
	} else {
		flicker.total_loop = flicker.total_loop + flicker.move_amount;
		flicker.speed = Math.abs(flicker.total_loop) / 4
	}
	if ((mydir == 1 && flicker.total_loop < flicker.move_amount_total) || (mydir == 2 && flicker.total_loop > flicker.move_amount_total_min)) {
		flicker.flicker_running = 1;
		flicker.the_timeout = setTimeout('flicker.moveFlicker(' + total + ',' + mydir + ');', flicker.speed)
	} else {
		flicker.flicker_running = 0;
		flicker.speedy = 0;
		flicker.total_loop = 0;
		flicker.move_amount = 1;

		//Start:02Jun2011 changes done to speed up the scroller
		/*
		flicker.move_amount_total = 150;
		flicker.move_amount_total_min = -150;
		flicker.the_timeout = setTimeout('flicker.moveFlicker(' + total + ',' + flicker.direction + ');', 3000)
		*/

		flicker.move_amount_total = 50;
		flicker.move_amount_total_min = -50;
		flicker.the_timeout = setTimeout('flicker.moveFlicker(' + total + ',' + flicker.direction + ');', 1)
		//Over:02Jun2011 changes done to speed up the scroller
	}
};
flicker.pauseFlicker = function () {
	flicker.move_amount = 0
};
flicker.resumeFlicker = function () {
	flicker.move_amount = 1
};
var move_amount_tick = 1;
var move_amount_total_tick = 25;
var total_loop_tick = 0;
flicker.moveTicker = function () {
	if (!flicker.ticker_content) {
		return false
	}
	if (!flicker.ticker_content[flicker.ticker_counter]) {
		flicker.ticker_counter = 0
	}
	for (var x = 1; x <= 2; x++) {
		var move_div_tick = "ticker" + x;
		var the_style_tick = flicker.getStyleObject(move_div_tick);
		if (the_style_tick) {
			var current_top = parseInt(the_style_tick.top);
			var new_top = current_top - move_amount_tick;
			if (new_top < "-24") {
				new_top = 25;
				document.getElementById("ticker" + x).innerHTML = flicker.ticker_content[flicker.ticker_counter]
			}
			if (document.layers) {
				the_style_tick.top = new_top
			} else {
				the_style_tick.top = new_top + "px"
			}
		}
	}
	total_loop_tick = total_loop_tick + move_amount_tick;
	if (total_loop_tick < move_amount_total_tick) {
		flicker.the_timeout_tick = setTimeout('flicker.moveTicker();', 1)
	} else {
		flicker.ticker_counter++;
		total_loop_tick = 0;
		flicker.the_timeout_tick = setTimeout('flicker.moveTicker();', 5000)
	}
};
flicker.pauseTicker = function () {
	if (total_loop_tick == 0) {
		move_amount_tick = 0
	}
};
flicker.resumeTicker = function () {
	move_amount_tick = 1
};
flicker.changeDirection = function (total_divs, dir) {
	flicker.direction = dir;
	flicker.speedy = 1;
	if (flicker.flicker_running == 0) {
		clearTimeout(flicker.the_timeout);
		flicker.moveFlicker(total_divs, flicker.direction)
	}
};
flicker.getStyleObject = function (objectId) {
	if (document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style
	} else if (document.all && document.all(objectId)) {
		return document.all(objectId).style
	} else if (document.layers && document.layers[objectId]) {
		return document.layers[objectId]
	} else {
		return false
	}
};
flicker.flickerCookie = function (id, i) {
	var flicker_cookie = flicker.readCookie();
	if (!flicker_cookie) {
		flicker.writeCookie(id, i)
	} else {
		var cookieValues = new Array();
		cookieValues = flicker_cookie.split('|');
		var user = cookieValues[0];
		var flicker_index = cookieValues[1];
		if (user != id || i != flicker_index) {
			flicker.writeCookie(id, i)
		}
	}
};
flicker.readCookie = function () {
	var cookie_name = "msfflicker=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') {
			c = c.substring(1, c.length)
		}
		if (c.substring(0, 10) == 'msfflicker') {
			return c.substring(cookie_name.length, c.length)
		}
	}
	return null
};
flicker.writeCookie = function (i) {
	var value = flicker.direction + '|' + i;
	var name = 'msfflicker';
	var date = new Date();
	var expdate = date.getTime();
	expdate += 3600 * 1000;
	date.setTime(expdate);
	var expires = "; expires=" + date.toGMTString();
	document.cookie = name + '=' + value + expires + "; path=/"
}; 

