  // .: Version 1.3.1 :. //

	function _void() {
		return
			false;
	}

  function jCaos() {
		this.GoogleMap=null;
		this.GoogleMapMark=null;

    this.toolboxCode=function(id, index, total) {
      return '<div class="toolbox">'
          +'<span class="boton boton-derecha">'
            +'<a href="javascript:_void();" onclick="jcaos.showPreviousOnSlideShow(\''+id+'\');">'
							+'&nbsp;'
						+'</a>'
          +'</span>'
            +'<span class="indices">'+index+'/'+total+'</span>'
          +'<span class="boton boton-izquierda">'
            +'<a href="javascript:_void();" onclick="jcaos.showNextOnSlideShow(\''+id+'\');">'
							+'&nbsp;'			
						+'</a>'
          +'</span></div>';
    }

    this.processSlideShows=function() {
      var w=document.getElementsByClassName('pase-diapositivas');
      for(var i=0;i<w.length;i++)
        this.processSlideShow(w[i]);
    }

    this.processSlideShow=function(div) {
      var i, w=div.childNodes;
      var counter=0;
      for(i=0;i<w.length;i++)
        if (w[i].tagName=='DIV' &&
             w[i].className=='diapositiva')  {
          if (counter++ > 0)
            w[i].style.display='none';
					else
						w[i].style.display='block';
				}

      var total=counter;
      counter=0;
      for(i=0;i<w.length;i++)
        if (w[i].tagName=='DIV' &&
            w[i].className=='diapositiva')
          w[i].innerHTML+=this.toolboxCode(div.id, ++counter, total);
    }

    this.showNextOnSlideShow=function(id) {
      var w=document.getElementById(id).childNodes;
      var counter=0;
      var divNow=null;
			var divFirst=null;
      for(var i=0;i<w.length;i++)
        if (w[i].tagName=='DIV' &&
            w[i].className=='diapositiva') {
					if (divFirst==null)
						divFirst=w[i];
          if (w[i].style.display!='none' && divNow==null)
            divNow=w[i];
          else if (divNow!=null) {
            divNow.style.display='none';
            w[i].style.display='block';
            return true;
          }
        }

			if (divFirst!=null && divNow!=null) {
				divNow.style.display='none';
				divFirst.style.display='block';
			}
				

      return false;
    }

    this.showPreviousOnSlideShow=function(id) {
      var w=document.getElementById(id).childNodes;
      var counter=0;
      var lastDiv=null;
			var shownDiv=null;
      for(var i=0;i<w.length;i++)
        if (w[i].tagName=='DIV' &&
            w[i].className=='diapositiva') {
          if (w[i].style.display!='none' && lastDiv!=null) {
            lastDiv.style.display='block';
            w[i].style.display='none';
            return true;
          } else
            lastDiv=w[i];
					if (w[i].style.display!='none')
						shownDiv=w[i];
        }
			shownDiv.style.display='none';
			lastDiv.style.display='block';

      return false;
    }

    this.getTimerId=function(div) {
      name=div.className;
      var v='1234567890abcdefghijklmnopqrstvwxyz';
      var str='', i, n=name.length;
      for(i=0;i<n;i++)
        if ( v.indexOf(name.charAt(i))>-1 )
          str+=name.charAt(i);

      return str;
    }

		this.IE7ClearFloats=function() {
			var w=document.getElementsByClassName('preview');
			if (w.length==0)
				return;
			var preview=w[0];
			w=preview.childNodes;
			var x=0;
			var y=0;
			var lastHeight=0;
			for(var i=0;i<w.length;i++)
				//alert(i+'('+x+','+y+')');
				//alert("("+w[i].offsetLeft+","+w[i].offsetTop+')');
				//alert(w[i].className);
				if ((w[i].className.indexOf('spvw-container') >= 0 &&
						w[i].className.indexOf('absolute-spvw-container') == -1) ||
					 w[i].className.indexOf('pair_cover') >= 0 ) {
					if (x >= 620) {
						x=0;
						y-=-lastHeight;
					}
					w[i].style.position='absolute';
					w[i].style.left=x+'px';
					w[i].style.top=y+'px';

					x+=w[i].offsetWidth;
					lastHeight=w[i].offsetHeight - 0;
				}

			y-=-w[w.length-1].offsetHeight;
			if (y > 478)
				preview.style.height=y+'px';
		}

		this.createMoveLink=function(div) {
			div.className+=' spvw-container dynamic-mouse-over';
			var single_preview=document.createElement("div");
				single_preview.className='single_preview cid_'+Math.floor(Math.random()*99999999);

			var movbar=document.createElement("div");
				movbar.className='movbar';
					movbar.style.width=div.offsetWidth+'px';
						movbar.style.left="-"+div.offsetWidth+'px';
					movbar.style.height=div.offsetHeight+'px';
						movbar.style.top=div.offsetHeight+'px';
			
			var A=jfrost.getFirstNestedElement(div, 'A');
			var A_movbar=document.createElement("a");
				A_movbar.style.width=div.offsetWidth+'px';
				A_movbar.style.height=div.offsetHeight+'px';
			A_movbar.href=A.href;
				A_movbar.innerHTML='&nbsp;';
			movbar.appendChild(A_movbar);

			var wInside=div.childNodes;
			//alert(wInside.length);
			var iexplorer=jfrost.isInternetExplorer();
			for(var i=0;i<wInside.length;i++) {
				if (!iexplorer)
					div.removeChild(wInside[i]);
				single_preview.appendChild(wInside[i]);
			}

			single_preview.appendChild(movbar);
			div.appendChild(single_preview);
		}

		this.createMoveLinks=function() {
			var w=document.getElementsByClassName( 'rejilla-movil' );
			for(var i=0;i<w.length;i++)
				this.createMoveLink( w[i] );
		}

    this.moveLinks=function() {
      jfrost.addEventsOnClass(
        'dynamic-mouse-over',
        'DIV',
        {
          'onmouseout': function() {
            var divid=jf.classXPath(this, 'single_preview');
            var timer_id=jcaos.getTimerId( divid );
            if ( jfrost.activeTimer( timer_id ) ) {
              var theTimer=jfrost.getTimer( timer_id );
              theTimer.shouldExit=true;
            } else {
              setTimeout(
                "if ( !jfrost.activeTimer('"+timer_id+"')) { var movbar=jf.classXPath(null, '"+divid.className+"/movbar'); movbar.style.top=null; movbar.style.left=null; };",
                50
              );
            }
          },
          'onmouseover': function() {
            var timer_id=jcaos.getTimerId( jf.classXPath(this, 'single_preview') );
            if (jfrost.activeTimer( timer_id )) {
              var theTimer=jfrost.getTimer( timer_id );
              theTimer.shouldExit=false;
            } else
              jfrost.newBeginnerTimer(
                timer_id,
                {
                  'parentDiv' : this,
                  'shouldExit' : false,
                  'firstTime': function() {
                    this.timer_id=jcaos.getTimerId( jf.classXPath(this.parentDiv, 'single_preview') );
                    this.movbar=jf.classXPath(this.parentDiv, 'single_preview/movbar');
                  },
                  'onExit': function() {
                    jfrost.deleteTimer( this.timer_id );
                    this.movbar.style.top=null;
                    this.movbar.style.left=null;
                  },
                  'lastTime': function() {
                    jfrost.deleteTimer( this.timer_id );
                    if ( !this.shouldExit )
                      return;
                    this.movbar.style.top=null;
                    this.movbar.style.left=null;
                  },
                  'eachTime': function() {
                    this.allQt();
                  },
                  'allQt': function() {
                    var r=this.remaining/this.times;
										//console.debug("offsetTop:"+this.movbar.offsetTop);
										//console.debug("offsetLeft:"+this.movbar.offsetLeft);
                    this.movbar.style.top=(this.movbar.offsetTop*r)+'px';
                    this.movbar.style.left=(this.movbar.offsetLeft*r)+'px';
                  }
                }
              );
          }
        }
      );

    }

		this.drawGoogleMap=function() {
			var options = {
				zoom: 13,
				mapTypeId: google.maps.MapTypeId.ROADMAP
			};

			this.GoogleMap=new google.maps.Map(document.getElementById("googleMapCanvas"), options);
			this.GoogleMap.setCenter( new google.maps.LatLng(42.385187222222, 3.1475028888889) );
		}

		this.centerGoogleMap=function(lat, lng) {
			this.GoogleMap.setCenter(new google.maps.LatLng(lat, lng), 13);
			if (this.GoogleMapMark==null) {
				this.GoogleMapMark=new google.maps.Marker();
				this.GoogleMapMark.setMap(this.GoogleMap);
			}
			this.GoogleMapMark.setPosition( new google.maps.LatLng(lat, lng) );

			return true;
		}

    this.startUp=function() {
			if (jfrost.isInternetExplorer())
				jcaos.IE7ClearFloats();	// .: IE7 has bugs, and we should patch them :. //
			jcaos.createMoveLinks();
      jcaos.moveLinks();
      jcaos.processSlideShows();
    }

    jfrost.addOnLoad( this.startUp );
  }

  jcaos=new jCaos();

