/*	vertical scroller developed by Benjamin Roche
	(http://www.benjaminroche.co.uk)
	for the Schools' ICT Centre
*/
$(document).bind("ready", function(){
	$('.vContainer').each(function(){
		var pImg ="<img src='components/news_ticker/images/paused.png' />";	
		var wait = 6000;
		var scrollspeed = 1000;
		var pause=false;
		var vc = $(this);
		var inner = vc.find('.vContainerInner');
		var innerwidth = vc.width()-50+"px";
		inner.css({"width":innerwidth});
		var maxheight=0;
		var i;
		var tth;
		var tilew;
		var pplaceT;
		var pplaceL;
		var heightarray = new Array();
		var tilecount=0;
		var toptile;
		var tiles = vc.find('.vTile').size();
		vc.find('.vTile').each(function(){
			heightarray[tilecount] = $(this).height();
			tilecount++;		
		});	
		for(i=0; i < heightarray.length;i++){
			if(heightarray[i] > maxheight){
				maxheight = heightarray[i];
			}
		}
		vc.css({'height' : +(maxheight+11)+"px"});	
		if(tiles>1){
			vc.find('.vctrl').hover(function(){
				$(this).toggleClass('o');
				});	
			vc.find('.vctrl').click(function(){
				pause=!pause;
				$(this).toggleClass('p');
			});
		}else{
			vc.find('.vctrl').css({"display":"none"});
			}
	function beginscroll(){
		//console.log("paused = "+pause);
		if(tiles>1){
			if(pause==false){
				toptile = vc.find('.vTile:first');
				tth = toptile.height()+11;
				toptile.clone().appendTo(inner);
				inner.animate({
					top: - tth+"px"
					}, scrollspeed,function(){
						toptile.remove();
						inner.css({"top": 0});
						});
				};
			}
		};
setInterval(function(){beginscroll()},wait);
	
		
			
	});

	if($('#footer').css("position")=="relative"){
		$('#footer').css({"position":"relative"});
	}
});
