  var photoDir = "images/";
	var borderSize = 6;
	var sleepTime = 10000;
  var timerID;
  
	var thisURL = document.location.href;
	var splitURL = thisURL.split("#");
	var photoId = splitURL[1] - 1;
	
	photoId = 0;

  function loadXML() {
    
      var myAjax = new Ajax.Request(
                                    'feed.php',
                                    {
                                      onSuccess: fillArray,
                                      asynchronous: false
                                    }
                                    );
  }
    
  function fillArray(request) {
      
      var response = request.responseXML.documentElement;
      numOfNews = response.getElementsByTagName('news').length;
      for (i=0; i<response.getElementsByTagName('news').length; i++) {
        var anchor    = '<a href="'+ response.getElementsByTagName('link')[i].firstChild.nodeValue +'">+ informaci&oacute;n</a>';
        mysummary     = '<a href="'+ response.getElementsByTagName('link')[i].firstChild.nodeValue +'">' + response.getElementsByTagName('prebody')[i].firstChild.nodeValue + '</a>';
        photoArray[i] = new Array('../'+ response.getElementsByTagName('summary')[i].firstChild.nodeValue, '360', '200', response.getElementsByTagName('title')[i].firstChild.nodeValue, mysummary, anchor, response.getElementsByTagName('link')[i].firstChild.nodeValue);
      }
  }  

  var photoArray = new Array();
  
	loadXML();
	var photoNum = photoArray.length;
	
	API = new Detect();
	
	loadAPI = function(){

    API.Container      = new HTMLobj('ContainerNews');
		API.Photo          = new HTMLobj('Photo');
		API.PhotoContainer = new HTMLobj('PhotoContainer');
		API.Title	         = new HTMLobj('newsTitle');
		API.Caption        = new HTMLobj('newsSummary');
		API.MoreInfo       = new HTMLobj('MoreInfo');
		API.Back	         = new HTMLobj('Back');
		API.Next	         = new HTMLobj('Next');
 		API.Control        = new HTMLobj('Control');
 		API.PhotoLink      = new HTMLobj('PhotoLink');

		cyclePhoto(photoId);
	}
	
	initImageLoad = function () {
	  
	  API.PhotoContainer.show();
	  var loaderTimer = setInterval('showImage()', 300);
	  var counter = 0;
	  
	  showImage = function () {
	      if (counter > 1) {
	         clearInterval(loaderTimer);
           document.getElementById('Back').onclick = nextPhoto;
           document.getElementById('Next').onclick = prevPhoto;
	      } else {
	         counter++;
	      }
	  }
	}
	
	falsify = function(){
		return false;
	}
	
	nextPhoto = function(){

		if(photoId == (photoArray.length - 1)){
			photoId = 0;
		} else {
			photoId++;
		}
		cyclePhoto(photoId);
	}
	
	prevPhoto = function(){
      
		if(photoId == 0){
			photoId = photoArray.length - 1;
		} else {
			photoId--;
		}
		cyclePhoto(photoId);
	}
	
	changeElementClass = function(objId,setClass) {
		document.getElementById(objId).className = setClass;
	}
	
	cyclePhoto = function(photoId){
			
		var wNew = photoArray[photoId][1];
		var hNew = photoArray[photoId][2];
		var wCur = API.Container.getWidth() - borderSize;
		var hCur = API.Container.getHeight() - borderSize;
		var newPhoto = photoArray[photoId][0];
		
		API.Photo.setSrc(newPhoto);		
		API.Photo.sizeTo(wNew,hNew);
    API.PhotoLink.setHref(photoArray[photoId][6]);
	
		document.getElementById('Photo').onload = initImageLoad;
    API.Title.setInnerHtml(photoArray[photoId][3]);
		API.Caption.setInnerHtml(photoArray[photoId][4]);
    API.MoreInfo.setInnerHtml(photoArray[photoId][5]);
		document.getElementById('Back').onclick = falsify;
		document.getElementById('Next').onclick = falsify;
	}
  
  function playNews() {
      
      $('Control').onclick = stopNews;
      timerID = setTimeout("playNews()", sleepTime);
      nextPhoto();
  }

  function stopNews() {
      
      $('Control').onclick = playNews;
      clearTimeout(timerID);
  }
