/* Toyota v8 core javascript - 2007-02-27  */

function generateMainMenu(){
	nav_div = document.getElementById('nav5');
	li = nav_div;
	i=0;
	for(j=0;j<JsTopMenu.length;j++){
		if (j<5){
			//alert(JsTopMenu[j].label +' : '+ li.childNodes[i].hasChildNodes());
			if (li.childNodes[i].childNodes[0]){
				//alert(JsTopMenu[i].label);
				if (JsTopMenu[j].menu_class != ''){
					li.childNodes[i].id = "nav-on";
				}
				li.childNodes[i].childNodes[0].href = JsTopMenu[j].url;
				li.childNodes[i].childNodes[0].innerHTML = JsTopMenu[j].label;
				if (JsTopMenu[j].target != undefined){
					li.childNodes[i].childNodes[0].target = JsTopMenu[j].target;
				}
				//alert(li.childNodes[i].className);
			}
			if (!li.childNodes[i].hasChildNodes()){
				j-=1;
			}
			i+=1;
		}
	}
}


/* IE 5.0 fix */
if(!Array.prototype.push){
Array.prototype.push=function(a){this[this.length]=a}
window.noScript=true
}

/* global namespace: Tme */
var Tme={
init:function(){var o=this,n;for(n in o)if(o[n].init)o[n].init()},
get:function(a,b){return(b||document).getElementById(a)},
tags:function(a,b){return(b||document).getElementsByTagName(a)},
set:function(a,b){for(var o in b)a[o]=b[o];return a},
create:function(a,b,c,d){
	var g=Tme,o=(d||document).createElement(a);
	g.set(o,b);
	//alert(b.target);
	g.set(o.style,c);
	//alert(o.outerHTML);
	return o
},
append:function(a,b,c,d){var o=b.tagName?b:Tme.create(b,c,d);a.appendChild(o)},
remove:function(a){var o=a.tagName?a:Tme.get(a);o.parentNode.removeChild(o)},
time:function(){return new Date().getTime()},
fn:function(a){return(0.5-Math.cos(a*Math.PI)/2)},
absTop:function(a){var y=0;if(a.y)return a.y;while(a!=null){y+=a.offsetTop;a=a.offsetParent};return y},
absLeft:function(a){var x=0;if(a.x)return a.x;while(a!=null){x+=a.offsetLeft;a=a.offsetParent};return x},
opacity:function(a,b){Tme.set(a.style,{'filter':'alpha(opacity='+b+')',opacity:b/100})},
expand:function(a){a.style.display='block'},
collapse:function(a){a.style.display='none'}
}

Tme.request={
_r:function(){return window.XMLHttpRequest?new XMLHttpRequest():window.ActiveXObject?new ActiveXObject('Microsoft.XMLHTTP'):null},
get:function(a){var o=this._r();o.open('GET',a,false);o.send(null);return o}
}

Tme.set(String.prototype,{middle:function(a,b){var o=this.split(a);return(o.length<2)?'':o[1].split(b)[0]}})
try{document.execCommand('BackgroundImageCache', false, true)}catch(err){}

SafeAddOnload('Tme.init');
SafeAddOnload('generateMainMenu');


/* open link in new window */
Tme.links={init:function(){
	var g=Tme,o=g.tags('a'),i,p
	for(i=0;i<o.length;i++){p=o[i];if(p.className=='external'){p.title='New window: '+(p.title||p.href);p.target='_blank'}}
}}

/* unobtrusive flash */
Tme.flash={items:[],
init:function(){var o=this.items,i;for(i=0;i<o.length;i++)this.render(o[i]);return true},
add:function(a,b){this.items.push([a,b])},
render:function(a){
	var v=[],q=Tme.set({wmode:'transparent',quality:'high'},a[0]),x,pp
	pp=/([&|?|;]rsbid=)([^&]*)/i.exec(location.search)
	if(pp)q.flashvars+='&rsbid='+pp[2]
	v.push('<object type="application/x-shockwave-flash" width="'+q.width+'" height="'+q.height+'" data="'+q.movie+'">')
	for(x in q){switch(x){case'height':case'width':break;default:v.push('<param name="'+x+'" value="'+q[x]+'" />')}}
	v.push('</object>')
	Tme.get(a[1]).innerHTML=v.join('\n')
}
}

/* top navigation */
Tme.nav={pos:[],size:192,
init:function(){
	if(window.noScript)return
	var o=this,qn=Tme.get('nav'),q,i,p,pp
	if(!qn || !window.JsTopMenu)return
	q=Tme.tags('a',qn)
	o.sub=Tme.create('iframe',{frameBorder:0})
	qn.appendChild(o.sub)
	o.doc=(o.sub.contentWindow||o.sub).document
	pp=Tme.get('logo').src.middle('//','/')
	o.doc.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html><head><style>html,body{margin:0;padding:0;overflow:hidden;font-family:verdana,sans serif;font-size:12px;line-height:14px}body{border:solid 1px #666;border-top:0;border-left:solid 1px #ddd;padding:3px 0 15px 0}a{display:block;color:#999;padding:3px 6px;text-decoration:none}a:hover{color:#e50000}div{height:1px;line-height:1px;overflow:hidden;background:url(http://'+pp+'/Images/dot.gif);margin:3px 6px}span{display:block;font-size:9px;line-height:12px;color:#999;padding:9px 6px 0 6px}</style></head><body></body></html>')
	o.doc.close()
	o.body=Tme.tags('body',o.doc)[0]
	o.body.onmouseover=o.subover;o.body.onmouseout=o.out
	for(i=0;i<q.length;i++){
		p=q[i];p.index=i
		switch(i){
			case 0:o.shift=1-p.parentNode.offsetLeft;o.pos[i]=0;break
			case q.length-1:o.pos[i]=o.shift+p.parentNode.offsetLeft+p.offsetWidth-o.size;break
			default:o.pos[i]=o.shift+p.parentNode.offsetLeft
		}
		p.onmouseover=o.over;p.onmouseout=o.out
	}
},
over:function(){
	//alert('fdgfdg');
	var o=Tme.nav
	var q=window.event?event.srcElement:this
	if(JsTopMenu.length > q.index){
		var nn=JsTopMenu[q.index].children
		var i,sb=o.body,qq
		if(o.timer)o.stop()
		o.xx=q
		o.origid=q.parentNode.id
		q.parentNode.id='nav-on'
		o.body.innerHTML=''
		if(nn){
			for(i=0;i<nn.length;i++)sb.appendChild(o.item(nn[i]))
			qq=JsTopMenu[q.index].description
			if(qq)sb.appendChild(Tme.create('span',{innerHTML:qq},null,o.doc))
			Tme.set(o.sub.style,{left:o.pos[q.index]+'px',width:((q.index=='0')?194:192)+'px',display:'block'})
			o.sub.style.height=o.doc.body.clientHeight+1+'px'
			o.drop()
		}
	}
},
subover:function(){var o=Tme.nav;if(o.timer)clearTimeout(o.timer)},
out:function(){var o=Tme.nav;if(o.xx)o.timer=setTimeout(o.stop,250)},
stop:function(){
	var o=Tme.nav
	o.xx.parentNode.id=o.origid
	clearTimeout(o.timer);o.timer=null
	o.sub.style.display='none'
},
item:function(a){
	var o=Tme.nav.doc,n=null
	if(a.label=='--SEPARATOR--')return Tme.create('span',{innerHTML:'<div style="background-image:url(http://designs.bilinfocms.dk/1/graphics_2007/dot_tcm200-508946.gif);width:100%;margin:0px;margin-bottom:7px;"></div>'},n,o)
	
	if (a.target != '' && a.target != undefined){
		curr_target = a.target;
	}else{
		curr_target = '_parent';
	}
	if (curr_target == '_self'){
		curr_target = '_parent';
	}
	return Tme.create('a',{href:a.url,target:curr_target,innerHTML:a.label},n,o)
},
drop:function(){
	var o=Tme.nav,s=o.sub
	Tme.set(s.style,{height:0,display:'block'})
	Tme.set(s,{h2:o.doc.body.clientHeight+1,start:Tme.time(),end:350})
	s.step=function(){
		var t=Tme.time()-s.start,q,g,g2
		if(t>s.end){s.style.height=s.h2+'px';clearInterval(s.timer);s.timer=null}
		else{q=Tme.fn(t/s.end);s.style.height=parseInt(q*s.h2)+'px'}
	}
	s.timer=setInterval(s.step,10)
}
}


/* highlights zoom function */
Tme.keyinfo={
init:function(){
	var g=Tme,o=g.get('key-info');if(!o)return
	try{var o=g.tags('a',o),i;for(i=0;i<o.length;i++){if(o[i].className=='zoom')o[i].onclick=g.keyinfo.zoomIn}}
	catch(e){}
},
zoomIn:function(){
	var g=Tme,o=g.keyinfo,q,u='px',d=document.body,p=this
	q=g.create('div',{id:'key-detail',onclick:o.close},{top:g.absTop(p)+u,left:g.absLeft(p)+u})
	g.append(q,'img',{src:p.href})
	g.append(q,'div',{innerHTML:g.tags('span',p)[0].innerHTML})
	g.append(d,q)
	p.blur()
	return false
},
close:function(){Tme.remove('key-detail')}
}

/* section homepages */
Tme.secnav={
init:function(){
	var g=Tme,t=this,o=t.js=window.JsLevel2Menu,i;if(!o)return
	t.sub=g.create('div',{id:'section-sub'})
	g.append(g.get('mainfocus'),t.sub)
	t.menu=g.tags('a',g.get('carnav'))
	t.min=g.get('carnav').offsetLeft
	for(i=0;i<o.length;i++)g.set(t.menu[i],{id:i,onmouseover:t.over,onmouseout:t.out})
},
over:function(){
	var g=Tme,t=g.secnav,q=window.event?event.srcElement:this,x=q.parentNode.offsetLeft-t.min+'px',v='ERROR: Image and Summary required!',p
	p=t.js[q.id]
	if(p.image && p.summary){
		v='<img src="' + p.image + '" /><div>'+p.summary+'</div>'
		t.sub.innerHTML=v
		g.set(t.sub.style,{left:x,display:'block'})
	}
},
out:function(){Tme.secnav.sub.style.display='none'}
}

/* webtrends */
Tme.dcs={init:function(){
	var w=window,o
	if(w.DcsL&&w.dcsT){
		w.DcsV={'dcssip':w.location.hostname}
		new Image().src=dcsT()
	}
}}

/* touchclarity */
Tme.Tcl={init:function(){
	var w=window,o=this
	if(w.TcId){
		if (typeof tc_logging_active == 'undefined') tc_logging_active = true;
		tc_site_id=TcId
		tc_server_url='toyota.touchclarity.com'
		tc_log_path = '/applications/touchclarity'
		Tme.append(Tme.tags('body',o.doc)[0],'script',{type:'text/javascript',src:tc_log_path+'/logging-code.js'})
	}
}}

/* newsticker */
Tme.ticker={speed:50,delay:2000,lines:[],num:0,chars:0,
init:function(){
	var g=Tme,o=this,os=o.source=g.get('newsticker'),v,i,ph,pn;if(!os)return
	v=g.tags('a',os);for(i=0;i<v.length;i++)o.lines.push({href:v[i].href,label:v[i].innerHTML})
	o.target=g.tags('div',os)[0];o.render()
},
render:function(){
	var o=Tme.ticker,p=o.lines[o.num],d=o.speed
	if(o.chars>p.label.length){o.chars=0;o.num++;if(o.num>=o.lines.length)o.num=0;d=o.delay}
	else o.target.innerHTML='<a href="'+p.href+'">'+p.label.substring(0,o.chars++)+'</a>'
	setTimeout(o.render,d)
}
}

/* smooth scroll to read more */
Tme.more={to:300,end:800,
init:function(){
	var g=Tme,m=g.more,o=g.get('read-more')
	if(!o || !document.documentElement)return
	o=g.tags('a',o)[0]
	o.onclick=m.click
},
click:function(){
	var g=Tme,m=g.more,v=document.documentElement.scrollTop
	if(v>=m.end)return false
	m.from=v
	m.start=g.time()
	m.step=function(){
		var t=Tme.time()-m.start,q,g,g2,de=document.documentElement
		if(t>m.end){de.scrollTop=m.to;clearInterval(m.timer);m.timer=null}
		else{q=Tme.fn(t/m.end);de.scrollTop=m.from+q*(m.to-m.from)}
	}
	m.timer=setInterval(m.step,10)
	return false
}
}

/* old functions */
var N=null,W=window
function $escape(a){return encodeURIComponent(a)}
function $tags(a,b){return a.getElementsByTagName(b)}
function $get(a){return document.getElementById(a)}
function $tag(a,b,c){var v=['<'+a],q;if(c){for(q in c)v.push(S+q+'="'+c[q]+'"')};v.push((b!=N)?'>'+b+'</'+a+'>':' />');return v.join(E)}
function pop_glos(a){W.open(a,'popup_window','width=410,height=300,resizable=yes,scrollbars=yes')}
function pop(sLink){openpopup(sLink,750,500)}
function openpopup(sLink,iWidth,iHeight,left,name){
	if(left==N)left=0
	G_day=new Date()
	G_seed=G_day.getTime()
	iRand=parseInt(((G_seed-(parseInt(G_seed/1000,10)*1000))/10)/100*100000+1,10)
	if(name!=N)iRand=name
	winleft=((screen.width-iWidth)/2)-left
	winUp=(screen.height-iHeight)/2
	W.open(sLink,iRand,'resizable=yes,scrollbars=yes,width='+iWidth+',height='+iHeight+',left='+winleft+',top='+winUp)
}


var AjxRemote={_reg:[],
_request:function(){
	var o=this
	return W.XMLHttpRequest?new XMLHttpRequest():W.ActiveXObject?new ActiveXObject('Microsoft.XMLHTTP'):N
},
get:function(a){
	var o=this,r=o._request(),oo
	r.open('GET',a,F)
	r.send(N)
	return r
},
post:function(a,b){
	var o=this,r=o._request(),oo
	r.open('POST',a,F)
	r.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
	r.send(b)
	return r
}
}

/* Ajax poll */
var AjxPoll={
prepare:function(a){
	var o=this,oo=a.parentNode.parentNode,v,oa
	a.onsubmit=function(){
		v=AjxRemote.post(a.action+'&ajaxid='+o.getAjxId(a),o.getFields(a))
		oo.innerHTML=v.responseText
		return F
	}
	oa=$tags(a,'a')
	if(oa.length>0){
		oa=oa[oa.length-1]
		oa.onclick=function(){
			v=AjxRemote.get(oa.href+'&ajaxid='+o.getAjxId(a))
			oo.innerHTML=v.responseText
			return F
		}
	}
},
getAjxId:function(a){
	var o=$tags(a,'input'),i
	for(i=Z;i<o.length;i++){if(o[i].name=="ajaxid"){return o[i].value}}
	return ""
},
getFields:function(a){
	var o=$tags(a,'input'),i,v=[]
	for(i=Z;i<o.length;i++){
		switch(o[i].type){
			case 'radio':if(o[i].checked)v.push($escape(o[i].name)+'='+$escape(o[i].value));break
			case 'hidden':v.push($escape(o[i].name)+'='+$escape(o[i].value));break
		}
	}
	return v.join('&')
}
}

/* Overlayer */
var D=document,Z=0,E=''
function sSub(a,b,c){var o=a.split(b);return(o.length>1)?o[1].split(c)[Z]:E}
function OverlayObj(){this.movies={}}
var p=OverlayObj.prototype

p.showCurtain=function(mode){
	var o=this,oc=hGet('overlayer')
	o.hideElements(mode)
	if(D.all)oc.style.width=D.body.clientWidth
	oc.style.display=mode?'block':'none'
}

p.hideElements=function(mode){
	var o=this,oa=D.getElementsByTagName('select'),i,oh=mode?'hidden':'visible'
	for(i=Z;i<oa.length;i++)oa[i].style.visibility=oh
}

p.show=function(fmn){
	var o=this,om=o.movies[fmn],oo=hGet('ovl_flash'),ww,wh,v=''
	W.scrollTo(0,0); 
	o.showCurtain(om.hide_page)
	if (om.flash_popup){om.width=parseInt(om.width)+2;om.height=parseInt(om.height)+34;om.flashvars+='&sub='+om.file+'&title='+om.title;om.file='/Images/flash_popup.swf';om.flash_popup=false;}
	oo.style.width=om.width
	oo.style.height=om.height
	if(om.top){oo.style.top=om.top}
	else{
		if(D.all)wh=D.body.clientHeight
		else wh=W.innerHeight
		oo.style.top=(wh-om.height)/2
	}
	if(om.left){oo.style.left=om.left}
	else{
		if(D.all)ww=D.body.clientWidth
		else ww=W.innerWidth
		oo.style.left=(ww-om.width)/2
	}
	v='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+om.width+'" height="'+om.height+'">'
	if(om.flashvars)v+='<param name="flashVars" value="'+om.flashvars+'" />'
	v+='<param name="allowScriptAccess" value="sameDomain" />'
	v+='<param name="movie" value="'+om.file+'" />'
	v+='<param name="quality" value="high" />'
	v+='<param name="bgcolor" value="#ffffff" />'
	v+='<param name="wmode" value="transparent">'
	v+='<embed src="'+om.file+'"'
	if(om.flashvars)v+=' flashVars="'+om.flashvars+'"'
	v+=' quality="high" wmode="transparent" bgcolor="#ffffff" width="'+om.width+'" height="'+om.height+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
	v+='</object>'
	oo.style.display='block'
	oo.innerHTML=v
	o.current=om.name;o.allow_drag=om.allow_drag
	o.track('WT.cg_n=E_Overlayer&WT.pn='+om.name+'&WT.pc=opened')
}
p.track=function(a){
	var o=this,om=o.movies[o.current]
	if(om.webtrends && W.dcsTrk)dcsTrk('WT.cg_n=E_Overlayer&WT.pc=flash&WT.cg_s='+om.name+'&WT.pn='+a)
}
p.exec=function(command,args,target){
	var o=this,oo=hGet('ovl_flash'),on=o.current,v,om=o.movies[on]
	switch(command){
	case'close':
		oo.innerHTML='&nbsp;'
		oo.style.display='none'
		o.track('closed')
		o.current=''
		if(om.hide_page)o.showCurtain(F)
		break
	case'jump':
		o.track(args,target)
		D.location.href=args
		break
	case'tag':
		o.track(args)
		break
	case'moveTo':
		v=args.split(',')
		oo.style.left=v[0]
		oo.style.top=v[1]
		break
	}
}

var OVL=new OverlayObj()

function ovl_do(command,args,target){OVL.exec(command,args,target)}
function showOverLayer(fmn){OVL.show(fmn)}

/* functions from v4_menu.js */
var W=window,D=document,T=true,F=false,Z=0,N=null,E='',S=' '
function hGet(a){return(D.getElementById)?D.getElementById(a):N}
function switchlang(url){popupWin01=W.open(url+'?pagename='+location.href,'_new','width=400,height=300')}

/* open minisites */
function msLaunch(a,b){
	try{window.open(a,'minisite','menubar=0,status=0,scrollbars='+(b?b:0)).focus()}
	catch(e){alert('You have to allow popups to open a minisite.')}
}

/* open carconfig */
function open_fullscreen(lnk,sb,nm){
	var n='no',y='yes',s=screen,sw=s.availWidth-0,sh=s.availHeight-0,l,t
	sb=sb.toString().replace(0,n).replace(1,y)
	l=parseInt((sw-s.availWidth-10)/2);	if(l<0){w=sw-10;l=0;sb=y}
	t=parseInt((sh-s.availHeight-10)/2);if(t<0){h=sh-30;t=0;sb=y}
	window.open(lnk,nm,'resizable=no,scrollbars='+sb+',width='+w+',height='+h+',left='+l+',top='+ t)
}
