// MADRID VISION® Copyright. Todos los derechos reservados.

var mTop = {
	gId : function(str){ return document.getElementById(str); },
	Init : function(){
		var itT = ['mIni','mRec','mBil','mAtt','mTur','mEmp'];
		for(i=0; i<itT.length; i++){
			var id = itT[i];
			if(mTop.gId(id).className == 'mTlk'){
				mTop.gId(id).onmouseover = mTop.Over;
				mTop.gId(id).onmouseout = mTop.Out;
			}
			else{
				mTop.gId(id).parentNode.className = 'mTRo';
				mTop.gId(id).parentNode.parentNode.className = 'mTLo';
				mTop.gId(id).parentNode.parentNode.parentNode.className = 'mTCo';
			}
		}
		mTop.linkExt();
	},
	Over : function(){
		this.parentNode.style.backgroundPosition = '100% -23px';
		this.parentNode.parentNode.style.backgroundPosition = '0 -23px';
		this.parentNode.parentNode.parentNode.style.backgroundPosition = '0 -23px';
	},
	Out : function(){
		this.parentNode.style.backgroundPosition = '100% 0';
		this.parentNode.parentNode.style.backgroundPosition = '0 0';
		this.parentNode.parentNode.parentNode.style.backgroundPosition = '0 0';
	},
	//Enlaces en nueva ventana
	linkExt : function(){
		if(!document.getElementsByTagName) return; 
		var anchors = document.getElementsByTagName("a"); 
		for(var i=0; i<anchors.length; i++) { 
			var anchor = anchors[i]; 
			if(anchor.getAttribute("href") && anchor.getAttribute("rel") == "external"){ 
				anchor.target = "_blank";
			}
		}
	}
};

var mSub = {
	gId : function(str){ return document.getElementById(str); },
	mSIE : null,
	mSCont : 'mS',
	mSNum : null,
	mSNone : ['/',
			  '/index.php',
			  '/index2.php',
			  '/en/',
			  '/en/index.php',
			  '/en/index2.php',
			  '/fr/',
			  '/fr/index.php',
			  '/fr/index2.php',
			  '/de/',
			  '/de/index.php',
			  '/de/index2.php'],
	//Panel FAQ
	mSFAQ : null,
	
	Init : function(rut){
		if(navigator.userAgent.toLowerCase().indexOf("msie 5.5") != -1) mSub.mSIE = 'ie55';
		mSub.mSRut = rut;
		//Detectar home (sin submenu)
		var mSN = true;
		for(i=0; i < mSub.mSNone.length; i++)
			if(rut == mSub.mSNone[i]) mSN = false;
		if(mSN){
			mSub.mSNum = mSub.gId(mSub.mSCont).getElementsByTagName('a').length;
			mSub.enableCont(); 
			
			mSub.gId(mSub.mSCont).style.visibility = 'visible';
			mSub.enableSolap();
		}else{
			mSub.viewBot(1);
		}
	},
	enableCont : function(){
		mSub.viewBot(0);
		if(mSub.mSPmt == '') mSub.mSPmt = '0';
		//Contenido ninguna solapa (por defecto, altura de mapa y taquilla). 
		if(mSub.mSNum == 0){
			if(parseInt(mSub.gId('mS0c').scrollHeight) > 406) mSub.gId('mS0c').style.height = mSub.gId('mS0c').scrollHeight + 'px';
			else mSub.gId('mS0c').style.height = '406px';
			mSub.gId('mS0c').style.visibility = 'visible';
		}
		//Contenido al menos 1 solapa
		else{
			var alturCont = parseInt(mSub.gId('mS'+mSub.mSPmt+'c').scrollHeight);
			//Busqueda panel con mayor altura
			var panMax = 0;
			for(i = 0; i < mSub.mSNum; i++){
				//Altura panel FAQ a su altura por defecto: 405
				if(i == 0 && mSub.mSFAQ == 'faqL') mSub.gId('faqL').style.height = 405 + 'px'; 
				
				var panAct = parseInt(mSub.gId('mS'+i+'c').scrollHeight);
				if(panAct > panMax) panMax = panAct;
				//Panel medido, seteado a 0
				mSub.gId('mS'+i+'c').style.height = 0 + 'px';
				if(mSub.mSIE == 'ie55') mSub.gId('mS'+i+'c').style.display = 'none'; //for IE 5.5
			}
			//Altura panel activo como el de mayor altura
			mSub.gId('mS'+mSub.mSPmt+'c').style.height = panMax + 'px';
			mSub.gId('mS'+mSub.mSPmt+'c').style.visibility = 'visible';
			if(mSub.mSIE == 'ie55') mSub.gId('mS'+mSub.mSPmt+'c').style.display = 'block'; //for IE 5.5
			
			//Altura panel FAQ
			if(mSub.mSFAQ == 'faqL') mSub.gId('faqL').style.height = panMax - 1 + 'px';
		}
		mSub.viewBot(1);
	},
	enableSolap : function(){
		for(i=0; i < mSub.mSNum; i++){
			var id = 'mS'+i;
			mSub.gId(id).parentNode.style.backgroundPosition = '100% 0';
			mSub.gId(id).parentNode.parentNode.style.backgroundPosition = '0 0';
			mSub.gId(id).parentNode.parentNode.parentNode.style.backgroundPosition = '0 0';
			mSub.gId(id).onmouseover = null;
			mSub.gId(id).onmouseout = null;
			mSub.gId(id).onclick = null;
			if(mSub.mSPmt == i) mSub.SetAct(id);
			else mSub.SetOtr(id);
		}
	},
	SetAct : function(id){
		mSub.gId(id).className = 'mSlko';
		mSub.gId(id).parentNode.className = 'mSRo';
		mSub.gId(id).parentNode.parentNode.className = 'mSLo';
		mSub.gId(id).parentNode.parentNode.parentNode.className = 'mSCo';
	},
	SetOtr : function(id){
		mSub.gId(id).className = 'mSlk';
		mSub.gId(id).parentNode.className = 'mSR';
		mSub.gId(id).parentNode.parentNode.className = 'mSL';
		mSub.gId(id).parentNode.parentNode.parentNode.className = 'mSC';
		mSub.gId(id).onmouseover = mSub.Over;
		mSub.gId(id).onmouseout = mSub.Out;
		mSub.gId(id).onclick = mSub.Clic;
	},
	Over : function(){
		this.parentNode.style.backgroundPosition = '100% -27px';
		this.parentNode.parentNode.style.backgroundPosition = '0 -27px';
		this.parentNode.parentNode.parentNode.style.backgroundPosition = '0 -27px';
	},
	Out : function(){
		this.parentNode.style.backgroundPosition = '100% 0';
		this.parentNode.parentNode.style.backgroundPosition = '0 0';
		this.parentNode.parentNode.parentNode.style.backgroundPosition = '0 0';
	},
	Clic : function(){
		var pmt = this.id;
		mSub.gId(pmt).blur();
		pmt = pmt.substring(pmt.indexOf('S')+1,pmt.length);
		mSub.mSPmt = pmt;
		mSub.enableCont();
		mSub.enableSolap();
	},
	viewBot : function(x){
		if(x == 0) mSub.gId('bot').style.display = 'none';
		else mSub.gId('bot').style.display = 'block';
	},
	cambioSolap : function(sol){
		var path = window.location.pathname;
		mSub.mSPmt = sol;
		mSub.Init(path);
	}
};

var mPag = {
	gId : function(str){ return document.getElementById(str); },
	itemAct : null,
	
	Init : function(pag){
		if(pag == 'car') mPag.itemAct = 'cLk0';
		else			 mPag.itemAct = 'eLk0';
		
		var pages = ['car', 'eve'];
		for(p=0; p<pages.length; p++){
			var items = mPag.gId(pages[p] + 'L').getElementsByTagName('a');
			for(i=0; i<items.length; i++){
				mPag.gId(items[i].id).onclick = mPag.OpenItem;
			}
			//Primer item
			mPag.gId(items[0].id).className = 'aCs';
			mPag.gId(items[0].id).parentNode.className = 'liCs';
			mPag.gId(items[0].id + '_c').style.display = 'block';
		}
	},
	
	OpenItem : function(it){
		var itClic;
		if(String(it) == '[object Event]' || String(it) == '[object MouseEvent]' || String(it) == 'undefined'){
//		if(String(it) == '[object Event]' || String(it) == 'undefined'){
			itClic = this.id;
			this.blur();
		}else{
			itClic = it;
		}
		//----
		if(mPag.itemAct != itClic){
			//Item a abrir
			mPag.gId(itClic).className = 'aCs';
			mPag.gId(itClic).parentNode.className = 'liCs';
			mPag.gId(itClic + '_c').style.display = 'block';
			
			//Item a cerrar
			mPag.gId(mPag.itemAct).className = 'aC';
			mPag.gId(mPag.itemAct).parentNode.className = 'liC';
			mPag.gId(mPag.itemAct + '_c').style.display = 'none';
			
			mPag.itemAct = itClic;
			//Reajuste de altura de pagina conforme a contenido de FAQ. La primera carga no se reajusta, ya lo hace mSub
			mSub.enableCont();
		}
		else{
			return;
		}
	},
	ResetItem : function(it,pag){
		var items = mPag.gId(pag + 'L').getElementsByTagName('a');
		for(i=0; i<items.length; i++){
			mPag.gId(items[i].id).className = 'aC';
			mPag.gId(items[i].id).parentNode.className = 'liC';
			mPag.gId(items[i].id + '_c').style.display = 'none';
		}
		mPag.itemAct = it;
		mPag.gId(it).className = 'aCs';
		mPag.gId(it).parentNode.className = 'liCs';
		mPag.gId(it + '_c').style.display = 'block';
	}
};


window.onload = function(){
	//Flash Intro
	var path = window.location.pathname;
	if(path == '/' || path == '/index.php' ||
	   path == '/en/' ||
	   path == '/en/index.php' ||
	   path == '/fr/' || 
	   path == '/fr/index.php' ||
	   path == '/de/' ||
	   path == '/de/index.php'){
		setIntro.Init();
	}
	//Flash Rutas
	if(path == '/rutas.php' ||
	   path == '/en/rutas.php' ||
	   path == '/fr/rutas.php' ||
	   path == '/de/rutas.php'){
		setReco.Init();
		var sec = window.location.search;
		if(sec == '?s=1') 		mPag.Init('car');
		else if(sec == '?s=2') 	mPag.Init('eve');
		else 					mPag.Init('car');
	}
	//Idima y animacion Billetes
	if(path == '/billetes/taquilla.php'){ tLang.lg=0; tLang.Init(); tAnim.Init(); }
	if(path == '/en/billetes/taquilla.php'){ tLang.lg=1; tLang.Init(); tAnim.Init(); }
	if(path == '/fr/billetes/taquilla.php'){ tLang.lg=2; tLang.Init(); tAnim.Init(); }
	if(path == '/de/billetes/taquilla.php'){ tLang.lg=3; tLang.Init(); tAnim.Init(); }
	
	//Idioma y ajustes FAQ
	if(path == '/atencion.php'){ fLang.lg=0; fLang.Init(); setTimeout('fLoad.LoadFaq()',2000); mSub.mSFAQ = 'faqL'; }
	if(path == '/en/atencion.php'){ fLang.lg=1; fLang.Init(); setTimeout('fLoad.LoadFaq()',2000); mSub.mSFAQ = 'faqL'; }
	if(path == '/fr/atencion.php'){ fLang.lg=2; fLang.Init(); setTimeout('fLoad.LoadFaq()',2000); mSub.mSFAQ = 'faqL'; }
	if(path == '/de/atencion.php'){ fLang.lg=3; fLang.Init(); setTimeout('fLoad.LoadFaq()',2000); mSub.mSFAQ = 'faqL'; }
	
	mTop.Init();
	var pmt = window.location.search;
		if(pmt.indexOf('s') != -1){
			pmt = pmt.substring(pmt.indexOf('s'),pmt.indexOf('s')+3);
			pmt = pmt.substring(pmt.indexOf('=')+1,pmt.length);
		}else{
			pmt = "";
		}
		//if(pmt.indexOf('r') != -1){ pmt = pmt.substring(pmt.indexOf('r'),pmt.indexOf('s')+3); }
	mSub.mSPmt = pmt;
	mSub.Init(path);
};





