//Updata Image Changer Javascript
//18 August 2009
//BPages - www.bpages.co.uk



// when the DOM is ready:
$(document).ready(function () {
	/****Image Slider Constants - Change These****/
	/****Wait Time****/
	var wait = 2000;
	/****Transition Time****/
	var trans = 1000;
							
							
	// find the elements in div.featureset
	if($('div.featureset').length==1){
		var fade = $('div.featureset').children();

		var transition = function(cur){
			var prev = (cur == 0) ? fade.length - 1 : cur - 1;
			var next = (cur == fade.length - 1) ? 0 : cur + 1;
			var nnext = (next == fade.length - 1) ? 0 : next + 1;
		
			$(fade[cur]).css("position", "absolute");
			$(fade[next]).insertAfter(fade[cur]);
		
			$(fade[cur]).fadeOut(trans, function(){
				$(fade[cur]).css("position", "static");
				$(fade[cur]).show();
				$(fade[cur]).insertAfter(fade[prev]);
				window.setTimeout(function(){
					transition(next, nnext);				
				}, wait);
			});
		};

		window.setTimeout(function() {
			transition(0);
		}, trans);
	}

	//init + start the scroller animation
	initAnimation();
	startAnimation();
});

var lines;
var line;
var lineHref;
var ojsScroller;
function initAnimation(){
	lines=0;
	line=new Array();
	lineHref=new Array();
	ojsScroller = document.getElementById("jsScroller");
	if(ojsScroller!=null)
	{
		var aElements = ojsScroller.getElementsByTagName("a");
		var i;
		for (i=0;i<aElements.length;i++)
		{
	    	line[i]=aElements[i].innerHTML;   
	    	lineHref[i] = aElements[i].href;   
		}
		ojsScroller.style.display = "none";


		lines=line.length //--Number of lines

		//if IE 4+ or NS6
		if (document.all||document.getElementById){
	    		//var oNewUl = document.createElement("ul")
			//ojsScroller.parentNode.appendChild(oNewUl);

	    		//var oNewLi = document.createElement("li")
			//oNewUl.appendChild(oNewLi);

	    		var oNewAnc = document.createElement("a")
	    		oNewAnc.id= "jsInsertBanner";
	    		oNewAnc.href=lineHref[0];
    	    		//oNewLi.appendChild(oNewAnc);
			ojsScroller.parentNode.appendChild(oNewAnc);
		}
	}
	temp=""
	nextchar=-1;
	nextline=0;
	cursor=""
}


function startAnimation()
{
    //if IE 4+ or NS6
    if (document.all||document.getElementById)animate();
}

function animate()
{    
    if (temp==line[nextline] && temp.length==line[nextline].length  && nextline!=lines - 1)
    {        
        nextline++;
        nextchar=-1;
        document.getElementById("jsInsertBanner").innerHTML=temp;        
        temp="";
        setTimeout("nextstep()",1500)
    }
    else if (nextline==lines -1 && temp==line[nextline] && temp.length==line[nextline].length)
    {        
        nextline=0;
        nextchar=-1;
        document.getElementById("jsInsertBanner").innerHTML=temp;        
        temp="";
        setTimeout("nextstep()",1500)
    }
    else
    {
        nextstep()
    }
}

function nextstep()
{
	var oBanner = document.getElementById("jsInsertBanner");
	if(oBanner!=null)
	{
    		if (oBanner.href != lineHref[nextline])oBanner.href = lineHref[nextline];
    		cursor=""
    		nextchar++;    
    		var ln = line[nextline];
    		if(ln!=null)
    		{
    			temp+=ln.charAt(nextchar);
    		}
    		//alert(temp);    
    		document.getElementById("jsInsertBanner").innerHTML=temp+cursor
    		setTimeout("animate()",25)
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}