var phrase_object_array=new Array()

var phrase_usestr=""
var phrase_split="|"
var phrase_count=0
var phrase_timer
var build_timer
var last_phrase
var last_phrasepos
var phrase_element="ticker_space"

function next_phrase(){
	
	if(phrase_object_array.length>0){
		if(phrase_object_array.length==1){
			last_phrasepos=0
			
			ob =phrase_object_array[0]
			
			cl=FIND(phrase_element)
			if(typeof cl!="undefined"){
				build_phrase(0)
			}
		}else{
			if(phrase_roll==1){
				return
			}
			if(phrase_count==phrase_object_array.length){
				phrase_usestr=phrase_split+last_phrase+phrase_split
				phrase_count=0
				
			}
			x= Math.round(Math.random()*(phrase_object_array.length-1));
			
			while(phrase_usestr.indexOf(phrase_split+x.toString()+phrase_split)!=-1){
				x= Math.round(Math.random()*(phrase_object_array.length-1));
			}
			last_phrase=x.toString()
			phrase_usestr=phrase_split+x.toString()+phrase_split
			phrase_count=phrase_count+1
			if(x-1<0){
				//x=0
			}else{
				//x=x-1
			}
			last_phrasepos=x
			
			ob =phrase_object_array[x]
			
			cl=FIND(phrase_element)
			
			//cl.innerHTML=ob.name
			
			//phrase_timer=setTimeout("next_phrase()",6000)
			if(typeof cl!="undefined"){
				if(phrase_roll==0){
					build_phrase(0)
				}
			}
		}
	}
	//weird_build_char(0,0)
}

function build_phrase(charpos){
	if(phrase_roll==0){
	//cl=FIND("phrase_cell")
	cl=FIND(phrase_element)
		if(typeof cl!="undefined"){
			if(typeof cl=="object"){
				ob =phrase_object_array[last_phrasepos]
	//alert(last_phrasepos)
				thisphrase=ob.name
	//cl.innerHTML="<span class=\"latest_updates_text\">"+thisphrase.substring(0,charpos+1)+"</span><span class=\"dingbat\">4</span>"
	//backstr="<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\"><tr><td class=\"sub_menu_phrase\" valign=\"bottom\"><span class=\"menu_text\">"
	//backstr2="</span></td></tr></table>"
				ding="<img src=\""+pthstr+"assets/dingbats/floater_link.gif\" width=\"13\" height=\"9\" border=\"0\">"
			
				targ=ob.target
				if(ob.target.indexOf("http://")==-1 && ob.target.indexOf("../")==-1){
					targ="../"+targ
				}
				if(targ.indexOf("event_ID=")!=-1){
					backstr="<a href=\""+targ+"\">"
				}else{		
					if(targ.indexOf("news_ID=")!=-1){
						backstr="<a href=\"javascript:MM_openBrWindow('"+targ+"','floater','status=yes,scrollbars=yes,resizable=yes,width=640,height=480')\">"
					}else{
						if(targ.indexOf("floating_panels")!=-1){
							backstr="<a href=\"javascript:MM_openBrWindow('"+targ+"','floater','status=yes,scrollbars=yes,resizable=yes,width=400,height=440')\">"
						}else{
							backstr="<a href=\""+targ+"\" target=\"_blank\">"
						}
					}
				}
				backstr2="</a>"
				phrase_str=thisphrase.substring(0,charpos+1)
				if(phrase_str.indexOf("£")!=-1){
					
					pos1=phrase_str.indexOf("£")
					pos2=phrase_str.indexOf("£")+1
					leftstr=phrase_str.substring(0,pos1)
					if(pos2<phrase_str.length-1){
						rightstr=phrase_str.substring(pos2,phrase_str.length)
					}else{
						rightstr=""
					}
					phrase_str=leftstr+"&pound;"+rightstr
					
				}
				cl.innerHTML=backstr+ding+phrase_str+backstr2
				if(charpos+1<thisphrase.length){
					clearTimeout(phrase_timer)
					clearTimeout(build_timer)
					if(phrase_roll==0){
						build_timer=setTimeout("build_phrase("+(charpos+1)+")",20)
					}
			//weird_build_char(charpos+1,3)
				}else{
					clearTimeout(phrase_timer)
					clearTimeout(build_timer)
					if(phrase_roll==0){
						phrase_timer=setTimeout("next_phrase()",5000)
					}
				}
			}
		}
	}
}

function weird_build_char(charpos,spos){
	cl=FIND(phrase_element)
	ob =phrase_object_array[last_phrasepos]
	thisphrase=ob.name
	chr=""
	if(thisphrase.charAt(charpos+1)==" "){
		spos=0
	}
	for(i=0;i<spos;i++){
		chr=chr+"&nbsp;"
	}
	chr=chr+thisphrase.charAt(charpos+1)
	cl.innerHTML=thisphrase.substring(0,charpos)+chr
	if(spos>0){
			build_timer=setTimeout("weird_build_char("+(charpos)+","+(spos-1)+")",20)
	}else{
			build_timer=setTimeout("build_phrase("+(charpos+1)+")",20)
	}
	
}

var phrase_roll=0

function phrase_rollOn(thisone){
	//ob=FIND(thisone)
	//if(ob.innerHTML!=""){
	phrase_roll=1
	clearTimeout(phrase_timer)
	
	
	//thisone.className="latest_updates_over"
	
	
	//}
}
function phrase_rollOff(thisone,thistime){
	//ob=FIND(thisone)
	//if(ob.innerHTML!=""){
	phrase_roll=0
	//thisone.className="latest_updates"
	if(!thistime){
	phrase_timer=setTimeout("next_phrase()",1000)
	}else{
	phrase_timer=setTimeout("next_phrase()",thistime)
	}
	//}
}
function phrase_Click(thisone){
	x=last_phrase
	if(x-1<0){
		//x=0
	}else{
		//x=x-1
	}
	
	ob =phrase_object_array[x]
	
	thistarget=ob.target
	w=ob.window_width
	h=ob.window_height
	
	if(thistarget!=""){
		if(thistarget.indexOf("javascript:")!=-1){
			func=thistarget.substring(thistarget.indexOf("javascript:")+("javascript:").length,thistarget.length)
			eval(func)
		}else{
			if(!w){
				if(thistarget=="top"){
					ob=FIND("sc_home")
					if(ob.innerHTML!=""){
						window.parent.document.location.reload()
					}
				
				}else{
				
					window.parent.frames["content"].document.location="../"+thistarget
				}
			}else{
			MM_openBrWindow("../"+thistarget,"floater","status=yes,scrollbars=yes,resizable=yes,width="+w+",height="+h)
			}
		}
	}
}

function phrase_item_object(nm,targ,lp){

	this.name=nm
	this.target=targ
	this.listpos=lp

	
}