var maxOptionsInMenuBar = 5;
var widthImage = 400;

function estado(){
   defaultStatus='Autotapicería'
   setTimeout('estado()',300);
}

function resize() {
   var totW = document.body.clientWidth;
   var totH = document.body.clientHeight;

   document.getElementById('divBar').style.width = totW;
   document.getElementById('divButtons').style.left = totW - 146;
   document.getElementById('divButtons').style.height = totH - 130;
   document.getElementById('divData').style.width = totW - 146;
   document.getElementById('divData').style.height = totH - 130 - 80;
   document.getElementById('divFooter').style.width = document.getElementById('divData').offsetWidth;
   document.getElementById('divFooter').style.top = totH - document.getElementById('divFooter').offsetHeight;
   
   document.getElementById('divButtons').style.visibility = 'visible';
   document.getElementById('divBar').style.visibility = 'visible';
   document.getElementById('divFooter').style.visibility = 'visible';
   
   for (i=1; i<=maxOptionsInMenuBar; i++) {
      if (document.getElementById('tdmenu' + i)) {
         document.getElementById('divMenu' + i).style.left = document.getElementById('tdmenu' + i).offsetLeft;
      }
   }
}

function showMenu(opt) {
  document.getElementById('divMenu' + opt).style.display = 'block';
}

function hideMenu(opt) {
  document.getElementById('divMenu' + opt).style.display = 'none';
}

function hideAllMenus() {
  for (i=1; i<=maxOptionsInMenuBar; i++) {
     if (document.getElementById('divMenu' + i)) {
	    document.getElementById('divMenu' + i).style.display = 'none';
	 }
  }
}

function selectMenu(obj) {
  obj.className = 'text_menu_sel';
}

function unselectMenu(obj) {
  obj.className = 'text_menu';
}

function menu(opt) {

    var imgInicio = 'btn_inicio';
	var imgInstalaciones = 'btn_instalaciones';
	var imgTapicerias = 'btn_tapicerias';
	var imgClasicos = 'btn_clasicos';
	var imgSonido = 'btn_sonido';
	var imgTuning = 'btn_tuning';
	var imgLunas = 'btn_lunas';
	var imgContacto = 'btn_contacto';
	
	if (opt == 'inicio')
	    imgInicio += '_';
	if (opt == 'instalaciones')
	    imgInstalaciones += '_';
	if (opt == 'tapicerias')
	    imgTapicerias += '_';
	if (opt == 'clasicos')
	    imgClasicos += '_';
	if (opt == 'sonido')
	    imgSonido += '_';
	if (opt == 'tuning')
	    imgTuning += '_';
	if (opt == 'lunas')
	    imgLunas += '_';
	if (opt == 'contacto')
	    imgContacto += '_';
		
    document.writeln("<tr valign='top'>");
    document.writeln("	  <td width='100%' height='24'>");
    document.writeln("	    <a href='index.html' onMouseOut='swapImgRestore()'onMouseOver=\"swapImage('btn_inicio','','images/btn_inicio_.gif',1)\"><img name='btn_inicio' src='images/" + imgInicio + ".gif' border='0'></a>");
    document.writeln("	  </td>");
    document.writeln("	</tr>");
    document.writeln("    <tr valign='top'>");
    document.writeln("	  <td width='100%' height='24'>");
    document.writeln("	    <a href='index.html' onMouseOut='swapImgRestore()'onMouseOver=\"swapImage('btn_instalaciones','','images/btn_instalaciones_.gif',1)\"><img name='btn_instalaciones' src='images/" + imgInstalaciones + ".gif' border='0'></a>");
    document.writeln("	  </td>");
    document.writeln("	</tr>");
    document.writeln("    <tr valign='top'>");
    document.writeln("	  <td width='100%' height='24'>");
    document.writeln("	    <a href='tapicerias.html' onMouseOut='swapImgRestore()'onMouseOver=\"swapImage('btn_tapicerias','','images/btn_tapicerias_.gif',1)\"><img name='btn_tapicerias' src='images/" + imgTapicerias + ".gif' border='0'></a>");
    document.writeln("	  </td>");
    document.writeln("	</tr>");
    document.writeln("    <tr valign='top'>");
    document.writeln("	  <td width='100%' height='24'>");
    document.writeln("	    <a href='clasicos.html' onMouseOut='swapImgRestore()'onMouseOver=\"swapImage('btn_clasicos','','images/btn_clasicos_.gif',1)\"><img name='btn_clasicos' src='images/" + imgClasicos + ".gif' border='0'></a>");
    document.writeln("	  </td>");
    document.writeln("	</tr>");
    document.writeln("    <tr valign='top'>");
    document.writeln("	  <td width='100%' height='24'>");
    document.writeln("	    <a href='sonido.html' onMouseOut='swapImgRestore()'onMouseOver=\"swapImage('btn_sonido','','images/btn_sonido_.gif',1)\"><img name='btn_sonido' src='images/" + imgSonido + ".gif' border='0'></a>");
    document.writeln("	  </td>");
    document.writeln("	</tr>");
    document.writeln("    <tr valign='top'>");
    document.writeln("	  <td width='100%' height='24'>");
    document.writeln("	    <a href='tuning.html' onMouseOut='swapImgRestore()'onMouseOver=\"swapImage('btn_tuning','','images/btn_tuning_.gif',1)\"><img name='btn_tuning' src='images/" + imgTuning + ".gif' border='0'></a>");
    document.writeln("	  </td>");
    document.writeln("	</tr>");
    document.writeln("    <tr valign='top'>");
    document.writeln("	  <td width='100%' height='24'>");
    document.writeln("	    <a href='index.html' onMouseOut='swapImgRestore()'onMouseOver=\"swapImage('btn_lunas','','images/btn_lunas_.gif',1)\"><img name='btn_lunas' src='images/" + imgLunas + ".gif' border='0'></a>");
    document.writeln("	  </td>");
    document.writeln("	</tr>");
    document.writeln("    <tr valign='top'>");
    document.writeln("	  <td width='100%' height='24'>");
    document.writeln("	    <a href='index.html' onMouseOut='swapImgRestore()'onMouseOver=\"swapImage('btn_contacto','','images/btn_contacto_.gif',1)\"><img name='btn_contacto' src='images/" + imgContacto + ".gif' border='0'></a>");
    document.writeln("	  </td>");
    document.writeln("	</tr>");
}

function preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.TT_p) d.TT_p=new Array();
      var i,j=d.TT_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
      if (a[i].indexOf("#")!=0){ d.TT_p[j]=new Image; d.TT_p[j++].src=a[i];}}
}

function swapImage() { //v3.0
    var i,j=0,x,a=swapImage.arguments; document.TT_sr=new Array; for(i=0;i<(a.length-2);i+=3)
     if ((x=findObj(a[i]))!=null){document.TT_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function swapImgRestore() { //v3.0
    var i,x,a=document.TT_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function findObj(n, d) { //v4.0
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
      d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
    if(!x && document.getElementById) x=document.getElementById(n); return x;
}


function init() {

  preloadImages('images/btn_inicio.gif', 'images/btn_inicio_.gif',
  			    'images/btn_instalaciones.gif', 'images/btn_instalaciones_.gif',
  			    'images/btn_tapicerias.gif', 'images/btn_tapicerias_.gif',
  			    'images/btn_clasicos.gif', 'images/ btn_clasicos_.gif',
  			    'images/btn_sonido.gif', 'images/btn_sonido_.gif',
  			    'images/btn_tuning.gif', 'images/btn_tuning_.gif',
  			    'images/btn_lunas.gif', 'images/btn_lunas_.gif',
  			    'images/btn_contacto.gif', 'images/btn_contacto_.gif');
}

function showFooter() {
   document.writeln("<div id='divFooter'>");
   document.writeln("  <hr>");
   document.writeln("  C/Cormoranes 10 (Polígono Industrial La Estación)");
   document.writeln("  <br>");
   document.writeln("  28320 Pinto (Madrid)");
   document.writeln("  <br>");
   document.writeln("  Tlf: 91 692 54 69");
   document.writeln("  <br>");
   document.writeln("  <a class='email' href='mailto:autotapiceria@autotapiceria.com'>autotapiceria@autotapiceria.com</a>");
   document.writeln("</div>");
}

function buildMenuTapCuero(num) {
   var prefImg = 'images/tapicerias/tapcuero/tapcuero';
   var opt = new Array(7);
   opt[0] = 'Ferrari F355 Berlinetta';
   opt[1] = 'BMW Z4';
   opt[2] = 'VW Golf V GTI';
   opt[3] = 'Ssang Yong Rexton';
   opt[4] = 'BMW Serie 3 E36';
   opt[5] = 'Opel Vectra II';
   opt[6] = 'Renault Megane II';
   var numImgOpt = new Array(7);
   numImgOpt[0] = 8;
   numImgOpt[1] = 3;
   numImgOpt[2] = 7;
   numImgOpt[3] = 5;
   numImgOpt[4] = 5;
   numImgOpt[5] = 6;
   numImgOpt[6] = 4;
   
   buildMenu(prefImg, opt, numImgOpt, num);
}

function buildMenuTapMixtas(num) {
   var prefImg = 'images/tapicerias/tapmixta/tapmixta';
   var opt = new Array(2);
   opt[0] = 'BMW Serie 3 E36';
   opt[1] = 'VW Golf I';
   var numImgOpt = new Array(2);
   numImgOpt[0] = 4;
   numImgOpt[1] = 5;
   
   buildMenu(prefImg, opt, numImgOpt, num);
}

function buildMenuCapotas(num) {
   var prefImg = 'images/tapicerias/capotas/capotas';
   var opt = new Array(1);
   opt[0] = 'Jeep';
   var numImgOpt = new Array(1);
   numImgOpt[0] = 5;
   
   buildMenu(prefImg, opt, numImgOpt, num);
}

function buildMenuSonido(num) {
   var prefImg = 'images/sonido/sonido';
   var opt = new Array(1);
   opt[0] = 'VW Golf';
   var numImgOpt = new Array(1);
   numImgOpt[0] = 7;
   
   buildMenu(prefImg, opt, numImgOpt, num);
}

function buildMenuClasicosAut(num) {
   var prefImg = 'images/clasicos/automoviles/clasicosaut';
   var opt = new Array(5);
   opt[0] = 'VW Escarabajo';
   opt[1] = 'MG';
   opt[2] = 'Mercedes Benz 180 SL';
   opt[3] = 'Mercedes Benz Pagoda';
   opt[4] = 'Mini Cooper';
   var numImgOpt = new Array(5);
   numImgOpt[0] = 5;
   numImgOpt[1] = 6;
   numImgOpt[2] = 11;
   numImgOpt[3] = 7;
   numImgOpt[4] = 7;
   
   buildMenu(prefImg, opt, numImgOpt, num);
}

function buildMenuClasicosCam(num) {
   var prefImg = 'images/clasicos/camiones/clasicoscam';
   var opt = new Array(2);
   opt[0] = 'Dodge Vacas flacas';
   opt[1] = 'Kenworth';
   var numImgOpt = new Array(2);
   numImgOpt[0] = 6;
   numImgOpt[1] = 8;
   
   buildMenu(prefImg, opt, numImgOpt, num);
}

function buildMenuTuning(num) {
   var prefImg = 'images/tuning/tuning';
   var opt = new Array(3);
   opt[0] = 'Opel Astra II';
   opt[1] = 'Peugeot 206';
   opt[2] = 'Renault Megane I';
   var numImgOpt = new Array(3);
   numImgOpt[0] = 10;
   numImgOpt[1] = 12;
   numImgOpt[2] = 8;
   
   buildMenu(prefImg, opt, numImgOpt, num);
}

function buildMenu(pref, list, numImgOpt, num) {
   document.writeln("<div id='divMenu" + num + "'>");
   document.writeln("  <table id='tabMenu" + num + "' width='100%' cellpadding='3' cellspacing='0' border='0'>");
   for (i=0; i<list.length; i++) {
      document.writeln("<tr><td class='text_menu' onmouseover='selectMenu(this)' onmouseout='unselectMenu(this)' onclick='showImages(\"" + pref + "\", " + i + ", \"" + list[i] + "\", " + num + ", " + numImgOpt[i] + ")'>" + list[i] + "</td></tr>");
   }
   document.writeln("   </table>");
   document.writeln("</div>");
}

function showImages(pref, num, tit, numMenu, numImg) {
   hideMenu(numMenu);
   var html = "<br><p class='text_titleopt'>" + tit + "</p>";
   for (i=1; i<=numImg; i++) {
      html += "<img src='" + pref + completeNum(num+1) + "/" + completeNum(i) + ".jpg'>";
   }

   document.getElementById('divData').innerHTML = html;
}

function completeNum(nn) {
   var res = '000000' + nn;
   return res.substr(res.length-2, res.length);
}
