var idImage=1;
  Layout = {
    ih: 0,
    iw: 0,
    iar: 1,
    war: 1,
    img: '',
    GetWindowSize: function(w) {
            w = w ? w : window;
            var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
            var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
            return [width, height];
    },
    init: function(e) {
      Layout.img = $('imgResize' + idImage);
      Layout.holder = $('divResize');
      Layout.ih = Layout.img.getHeight();
      Layout.iw = Layout.img.getWidth();
      Layout.iar = Layout.iw / Layout.ih;
      Layout.resize(e); 
    },
    resize: function(e) {
      ws = Layout.GetWindowSize(window);
      window_width = ws[0];
      window_height = ws[1];
      window_ratio = window_width / window_height;
      
      image_width = Layout.iw;
      image_height = Layout.ih;
      image_ratio = Layout.iar;
      
      new_image_width = window_width;
      new_image_height = ( new_image_width / image_width ) * image_height;
      width_diff = 0;
      height_diff = -( new_image_height - window_height ) / 2;
      
      if( new_image_height < window_height ) {
        new_image_height = window_height;
        new_image_width = ( new_image_height / image_height ) * image_width;
        height_diff = 0;
        width_diff = -( new_image_width - window_width ) / 2;
      }
      
      niw = Math.ceil(new_image_width);
      nih = Math.ceil(new_image_height);
      
      image_to_resize = $('imgResize' + idImage);
      Element.setStyle( image_to_resize, { width: niw+"px", height: nih+"px", top: height_diff+'px', left: width_diff+'px' } );
      
    }
  }
  Event.observe(window, 'resize', function() { Layout.resize(); } );
  Event.observe(window, 'load', function() {
    pe = new PeriodicalExecuter(function(pe) {
      Layout.init();
      pe.stop();
      pee = new PeriodicalExecuter( function(pee) {
        Layout.resize();
      }, 7);
    }, 0.3);
  });
  
  
var totalImg = 7;
function changeElement(id){
	var previousId = (id > totalImg) ? totalImg : id-1;
	//idImage = id;
	hideElement(previousId);
}
function hideElement(id){
	var nextId = (id+1 > totalImg) ? 1 : id+1;
	//idImage = id;
	//document.getElementById("img_random"+id).fadeOut(1000);
	document.getElementById("img_random"+id).style.display='none';
	document.getElementById("img_random"+nextId).style.display='block';
	window.setTimeout('showElement('+nextId+');');
}
function showElement(id){
	//document.getElementById("img_random"+id).fadeIn(1000);
	idImage = id;
	//alert('phrase'+id);
	document.getElementById("img_random"+id).style.display='block';
	document.getElementById("phrase"+id).style.display='block';
	//zwindow.setTimeout("changeElement("+(id+1)+");", 5000);
}
