/* the new core */

var G={gecko:navigator.product=='Gecko',flashVer:'10.0.0',hasFla:false,autoFla:false,ie6:(!!document.all && !(typeof window.XMLHttpRequest=='object')),
init:function(){
var o,i
G.detectFlash()
try{document.execCommand('BackgroundImageCache', false, true)}catch(err){}
for(var n in G)if(G[n].init)G[n].init()
o=window.fnstack;if(o)for(i=0;i<o.length;i++)o[i]()
},
event:function() {
	var o=this,v
    o.name=arguments[0]
    o.subscribe=function(fn){if(!v)v=[];v.push(fn)}
    o.fire=function(sender,args){if(v)for(var i=0;i<v.length;i++)v[i](sender,args)}
},
set:function(a,b,c){for(var o in b)a[o]=b[o];if(c){for(var o in c)a.style[o]=c[o]};return a},
create:function(a,b,c,d){var o=(d||document).createElement(a);G.set(o,b);G.set(o.style,c);return o},
append:function(a,b,c,d){var o=b.tagName?b:G.create(b,c,d,a.ownerDocument);a.appendChild(o);return o},
time:function(){return new Date().getTime()},
fn:function(a){return(0.5-Math.cos(a*Math.PI)/2)},
middle:function(o,a,b){o=o.split(a);return(o.length<2)?'':o[1].split(b)[0]},
pos:function(a){var x=0,y=0;if(a.y)return{x:a.x,y:a.y};while(a!=null){x+=a.offsetLeft;y+=a.offsetTop;a=a.offsetParent};return{x:x,y:y}},
stop:function(a){if(a){clearTimeout(a);a=null}},
sub:function(a,b,c){var o=a.split(b);return(o.length>1)?o[1].split(c)[0]:''},
remove:function(a){var o=a.tagName?a:Tme.get(a);o.parentNode.removeChild(o)},
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},
detectFlash:function(){if(G.middle(document.cookie,'acc_type=',';')=='html'){G.noFlash=true;return};var o=G.flash._o;G.hasFla=o.has(G.flashVer);G.autoFla=o.has('6.0.65')&&(o.ua.win||o.ua.mac)}
}
function $(a){return document.getElementById(a)}
function $$(a,b){return (b||document).getElementsByTagName(a)}
window.onload=G.init

G.viamichelin={
createNamedElement:function(a,b,c,d,n){var o=null;try{o=(d||document).createElement('<'+a+' name="'+n+'">');}catch(err){}if (!o || o.nodeName != a.toUpperCase()){o=(d||document).createElement(a);o.name= n;}G.set(o,b);G.set(o.style,c);return o}
}

G.sifr={movie:'/images/toyota-display.swf',
bc:'999999',
cGroup:{corp:'e50000','urban-iq':'92539a','urban-aygo':'c90123','urban-aygo2':'00a0e0','urban-cruiser':'c90123',life:'ae9f6d',life2:'ae9f6d',recreation:'7e6f5d',energy:'5cbac8',together:'c47e3d',work:'808b83','drive-2010':'c90123'},on:0,
init:function(){
	var m=this,cn=$$('body')[0].className,o=$('img-focus'),i
	m.set($('hdrt'),{css:'.sIFR-root{color:#'+m.bc+';font-weight:bold;text-align:right}strong{color:#'+m.cGroup[cn||'corp']+'}',size:16,offsettop:0,thickness:20})
	if(o){
		m.items=$$('li',o)
		o=$$('h2',o);for(i=0;i<o.length;i++)m.setTitle(o[i])
		m.prev=G.set($('sm-prev'),{onclick:m.doPrev})
		m.next=G.set($('sm-next'),{onclick:m.doNext})
		m.go(0)
	}
	o=$('one-focus');if(o){m.setTitle($$('h1',o)[0])}
	o=$('gr-title');if(o)m.set(o,{css:'.sIFR-root{color:#'+m.bc+';font-weight:bold}strong{color:#'+m.cGroup[cn||'corp']+'}',size:16,offsettop:0,thickness:20})
	o=$$('h2')
	for(i=0;i<o.length;i++){
		if(o[i].className=="h1")m.set(o[i],{css:'.sIFR-root{color:#'+m.bc+';font-weight:bold}strong{color:#'+m.cGroup[cn||'corp']+'}',size:16,offsettop:0,thickness:20})
	}
},
escape:function(a){
	var c,s='',t='',i=0
	a=a.replace(/\r/g,'').replace(/\n/g,'').replace(/\%/g, '%2525').replace(/&nbsp;/g,' ').replace(/&amp;/g,'%26')
	while(i<a.length){
		c=a.charAt(i)
		switch(c){
		case '&':t+='&';break
		case ';':s+=(t+';');t='';break
		case '+':s+='%2B';break
		default:
			if(t=='')s+=('&#'+c.charCodeAt(0)+';')
			else t+=c
		}
		i++
	}
	return s+t
},
set:function(a,b){
	var m=this,o,v=[],p,s;if(!a)return
	a.style.visibility='visible'
	if(G.noFlash)return
	o={movie:m.movie,height:a.offsetHeight,width:a.offsetWidth}
	for(p in b)v.push(p+'='+b[p])
	s=m.escape(a.innerHTML)
	v.push('content='+s)	
	v.push('version=beta2')
	v.push('width='+o.width)
	v.push('height='+o.height)
	o.flashvars=v.join('&amp;')
	G.flash.render([o,a])
},
doPrev:function(){G.sifr.go(-1);return false},
doNext:function(){G.sifr.go(1);return false},
go:function(a){
	var m=this,v=m.on+a,n=m.items.length
	if(!(v>-1 && v<n))return
	if(v!=m.on)m.items[m.on].style.display='none'
	m.items[v].style.display='block'
	m.prev.style.visibility=(v>0)?'visible':'hidden'
	m.next.style.visibility=(v<n-1)?'visible':'hidden'
	m.on=v
},
setTitle:function(o){
	var m=this,ta=m.getStyle(o,'text-align'),c=m.getColor(o,'color'),so=$$('strong',o)[0],s=m.getColor(so||o,'color'),cn=o.className
	if(so)so.removeAttribute('style')
	if(cn=='BL'||cn=='BR'){
		if(o.offsetHeight==38)o.style.top=o.offsetTop+38+'px'
	}
	m.set(o,{css:'.sIFR-root{color:'+c+';font-weight:bold;text-align:'+ta+'}strong{color:'+s+'}',size:32},true)
},
getStyle:function(a,b){
	var m=this,v=''
	if(a.currentStyle)v=a.currentStyle[m.ieProp(b)]
	else if(window.getComputedStyle)v=document.defaultView.getComputedStyle(a,null).getPropertyValue(b)
	return v
},
ieProp:function(a){var v=a.split('-'),i;if(v.length<2)return a;for(i=1;i<v.length;i++)v[i]=v[i].substr(0,1).toUpperCase()+v[i].substr(1);return v.join('')},
colorHex:function(a){
	var m=this,v=a.replace(/[#| ]/g,'')
	if(v.indexOf('rgb(')==0){v=v.split('(')[1].split(')')[0].split(',');v=m.hex(v[0])+m.hex(v[1])+m.hex(v[2])}
	else if(v.length==3){v=v.split('');v=v[0]+v[0]+v[1]+v[1]+v[2]+v[2]}
	return '#'+v
},
hex:function(a){return (a*1).toString(16)},
getColor:function(a,b){var m=this;return m.colorHex(m.getStyle(a,b))}
}





/* homepage showroom */
G.shr={
init:function(){
	var m=this,o=$('nav-sr'),i,p,x,pp,o2,f=parseInt;if(!o)return
	o=$$('a',o);p=m.last=o[o.length-1]
	x=f((950-p.offsetLeft-p.offsetWidth)/o.length)
	pp='8px '+f(x/2)+'px 9px '+f(.5+x/2)+'px'
	for(i=0;i<o.length-1;i++){G.set(o[i],{onmouseover:m.over,onmouseout:m.out,index:i},{padding:pp})}
	x=950-p.offsetLeft-p.offsetWidth;	if(G.ie6)x-=2.9
	p.style.padding='8px '+f(x/2)+'px 9px '+f(x/2)+'px'
	o2=$('cnav-dd');o2.style.zIndex=999;m.dds=o2=$$('li',o2)
	for(i=0;i<o2.length;i++){
		x=o[i].offsetLeft;x=(x<1172)?x:1172
		G.set(o2[i],{onmouseover:m.subover,onmouseout:m.subout},{left:x+'px'})
	}
},
over:function(){
	var m=G.shr,o=m.dds[this.index]
	if(G.halt)return
	G.stop(m.timer)
	if(m.a)m.a.style.display='none'
	o.style.display='block'
	m.a=o
},
out:function(){var m=G.shr;m.timer=setTimeout(m.stop,250)},
subover:function(){var m=G.shr;G.stop(m.timer)},
subout:function(e){
	var m=G.shr,t,o,q=window.event
	e=e||q
	t=(q)?e.srcElement:e.target
	o=(e.relatedTarget)?e.relatedTarget:e.toElement
	if(o){while(o.parentNode){if(o==m.a)return;o=o.parentNode}}
	m.stop()
},
stop:function(){var m=G.shr;if(m.a)m.a.style.display='none'}
}





/* Form in overlayer (testdrive form) */
G.extForm={
launch:function(a,b){
	var m=G.extForm,o=$('ctai')
	if(!o||m.open==true)return
	G.append(o,'iframe',{src:a,allowTransparency:'true',frameBorder:'0'},{width:'616px',height:(b||'300')+'px'})
	o.style.display='block'
	m.open=true
},
close:function(){var m=G.extForm,o=$('ctai');o.innerHTML='';o.style.display='none';m.open=false}
}

G.cta={
init:function(){
	var m=this,o=$$('a'),i,sDiv=false,s=G.sub(window.location.href,'form=','#')
	if(s!='')sDiv=true
	for(i=0;i<o.length;i++){if(o[i].className=='cta'){o[i].onclick=m.launch;sDiv=true}}
	if(sDiv)m.div=G.append(document.body,'div',{id:'ctai'})
	if(s!='')m.launch('auto',decodeURIComponent(s))
},
launch:function(a,b){
	var m=G.cta,v=m.link=(a=='auto')?b:this.href,o=m.div,ct=$('cta-curtain')
	if(!o)o=m.div=G.append(document.body,'div',{id:'ctai'})
	G.ieFix.hide()
	o.innerHTML=''
	m.frame=G.append(o,'iframe',{allowTransparency:'true',frameBorder:'0'})
	if(ct)G.set(ct.style,{filter:'alpha(opacity=20)',display:'block'})
	o.style.display='block'
	if($('cntop'))$('cntop').scrollIntoView()
	else if($('c'))$('c').scrollIntoView()
	m.frame.src=v
	return false
},
setSrc:function(){var m=G.cta;m.frame.src=m.link},
close:function(){
	var o=$('ctai'),ct=$('cta-curtain')
	G.ieFix.hide(true)
	try{G.flash.show()}catch(e){}
	o.innerHTML=''
	o.style.display='none'
	if(ct)ct.style.display='none'
}
}

G.flash={items:[],
init:function(){setTimeout(G.flash.exec,200)},
events:new function(){this.rendered=new G.event("rendered")},
exec:function(){
	if(G.noFlash)return
	var m=G.flash,o=m.items,i;if(o.length<1)return
	if(m._o.has(G.flashVer))for(i=0;i<o.length;i++)m.render(o[i],i)
	else m.alert()
},
add:function(a,b){this.items.push([a,b])},
doPop:function(a,b,c){window.open(a,b,c)},
setBw:function(a,b,c){
	var o=$('obj_flash_0'),oL=$('bwL'),oH=$('bwH'),v=a=='low'
	document.cookie='bandwidth='+a+';path=/;'
	if(oL)oL.className=v?'':'a'
	if(oH)oH.className=v?'a':''
	if(c)dcsTrk('WT.bw_md=Manual&WT.bw_tp='+(v?'Low_bw':'Hi_bw'))
	if(G.noFlash){
	document.cookie='acc_type=flash;path=/;'
		location=location
	}
	if(b && o){
		try{if(a=='low')o.setLowBandwidth();else o.setHighBandwidth()}catch(e){}
	}
},
getBw:function(){
	return(G.middle(document.cookie,'bandwidth=',';'))
},
testBw:function(){
	alert(G.flash.getBw())
},
hide:function(){
	var q=G.flash.items,i
	for(i=0;i<q.length;i++){if(q[i][0].wmode=='window')$(q[i][1]).style.visibility='hidden'}
},
show:function(){
	var q=G.flash.items,i
	for(i=0;i<q.length;i++){if(q[i][0].wmode=='window')$(q[i][1]).style.visibility='visible'}
},
render:function(a,b){
	var s=true,v=[],q=G.set({wmode:'transparent',quality:'high',AllowScriptAccess:'always',allowfullscreen:'true',bgcolor:'#000000'},a[0]),x,pp
	pp=location.search.substr(1);if(pp!='')q.flashvars+='&amp;'+pp
	if(G.gecko)q.flashvars+='&amp;agent=Firefox'
	v.push('<object type="application/x-shockwave-flash" id="obj_flash_'+b+'" 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>')
	if(a[1].tagName)a[1].innerHTML=v.join('\n')
	else try{$(a[1]).innerHTML=v.join('\n')}catch(e){s=false}
	if(s)this.events.rendered.fire(null,{elementid:a[1],id:'obj_flash_'+b})
},
alert:function(){
	var m=this,o=m._o,q,v='/sys/flash_html_detection.aspx',cnv
/*
	flash auto update
if(o.has('6.0.65')&&(o.ua.win||o.ua.mac)){m.render([{height:340,width:770,movie:'inc/expressInstall.swf',flashvars:'MMredirectURL='+location.href  },'flash1'])};else{} 
*/
	cnv=$('cnv')||$('c')
	q=G.append(cnv,'iframe',{id:'fl-install',src:v,allowTransparency:'true',frameBorder:'0'})
},
_o:function(){
var SF="Shockwave Flash",SX="ShockwaveFlash.ShockwaveFlash",win=window,D=document,B=navigator,N=null,F=false,T=true,
detectIEWin=function(a,b,c){
	var x
	try{x=new window.ActiveXObject(b)}catch(e){return}
	try{x.AllowScriptAccess='always'}catch(e){}
	try{a.num=x['GetVariable']('$version')}catch(e){if(c)a.num=c}
},
i$=function(a){return typeof a!='undefined'};var ua=function(){var w3cdom=i$(D.getElementById)&&i$(D.getElementsByTagName)&&i$(D.createElement)&&i$(D.appendChild)&&i$(D.replaceChild)&&i$(D.removeChild)&&i$(D.cloneNode),playerVersion=[0,0,0],d=N;
if(i$(B.plugins)&&typeof B.plugins[SF]=='object'){d=B.plugins[SF].description;if(d){d=d.replace(/^.*\s+(\S+\s+\S+$)/,"$1");playerVersion[0]=parseInt(d.replace(/^(.*)\..*$/,"$1"),10);playerVersion[1]=parseInt(d.replace(/^.*\.(.*)\s.*$/,"$1"),10);playerVersion[2]=/r/.test(d)?parseInt(d.replace(/^.*r(.*)$/,"$1"),10):0}}
else if(i$(win.ActiveXObject)){
	var v={},vv,i=20,x
	v.num=-1
	detectIEWin(v,SX)
	while((v.num==-1)&&(i>0)){
		switch(i){
			case 6:x='WIN 6,0,21,0';break
			case 3:x='WIN 3,0,18,0';break
			case 3:x='WIN 2,0,0,11';break
			default:x='WIN '+i+',0,0,0'
		}
		detectIEWin(v,SX+'.'+i,x)
		i--
	}
	if(v.num==-1)v.num=x
	vv=v.num.split(' ')[1].split(',')
	playerVersion=[vv[0],vv[1],vv[2]]
}
var u=B.userAgent.toLowerCase(),p=B.platform.toLowerCase(),webkit=/webkit/.test(u)?parseFloat(u.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):F,ie=F,windows=p?/win/.test(p):/win/.test(u),mac=p?/mac/.test(p):/mac/.test(u);/*@cc_on;ie=true;@if(@_win32)windows=true;@elif(@_mac)mac=true;@end;@*/
return {w3cdom:w3cdom,pv:playerVersion,webkit:webkit,ie:ie,win:windows,mac:mac}
}()

function hasPlayerVersion(rv){var pv=ua.pv,v=rv.split(".");v[0]=parseInt(v[0],10);v[1]=parseInt(v[1],10);v[2]=parseInt(v[2],10);return(pv[0]>v[0]||(pv[0]==v[0]&&pv[1]>v[1])||(pv[0]==v[0]&&pv[1]==v[1]&&pv[2]>=v[2]))?T:F};return{get:function(){return{major:ua.pv[0],minor:ua.pv[1],release:ua.pv[2]}},has:hasPlayerVersion,ua:ua}}()
}

