function displayPsyoGalleryImage(src, name, full)
{
    $('psyo_gallery_image').src = src;
    $('psyo_gallery_image_name').innerHTML = name;
    $('psyo_gallery_image_full').href = full;
}
var psyoGalleryNavigationNext = null;
var psyoGalleryNavigationPrev = null;
function psyoGalleryDisplayPrev()
{
    var temp = null;
    $$('#psyo_gallery_images li a').each(function(el){
        if (el.href==$('psyo_gallery_image').src)
        {
            if (temp) 
            {
                temp.onclick();
                return true;
            }
        }
        temp = el;
    });    
}
function psyoGalleryDisplayNext()
{
    var temp = null;
    $$('#psyo_gallery_images li a').each(function(el){
        if ((temp) && (temp.href==$('psyo_gallery_image').src))
        {
            el.onclick();
            return true;
        }
        temp = el;
    });    
}    
var psyoGalleryImageHolder = new Array;

function Slideshow(slideshow, timeout) {
  this.slides = [];
  var nl = $(slideshow).getElementsByTagName('div');
  for (var i = 0; i < nl.length; i++) {
    if (Element.hasClassName(nl[i], 'slide')) {
      this.slides.push(nl[i]);
    }
  }
  this.timeout = timeout;
  this.current = 0;

  for (var i = 0; i < this.slides.length; i++) {
    this.slides[i].style.zIndex = this.slides.length - i;
  }

  Element.show(slideshow);
  setTimeout((function(){this.next();}).bind(this), this.timeout + 850);
}
Slideshow.prototype = {
  next: function() {
    for (var i = 0; i < this.slides.length; i++) {
      var slide = this.slides[(this.current + i) % this.slides.length];
      slide.style.zIndex = this.slides.length - i;
    }

    Effect.Fade(this.slides[this.current], {
      afterFinish: function(effect) {
        effect.element.style.zIndex = 0;
        Element.show(effect.element);
        Element.setOpacity(effect.element, 1);
      }
    });
    
    this.current = (this.current + 1) % this.slides.length;
    setTimeout((function(){this.next();}).bind(this), this.timeout + 850);
  }
}

// WoD, w_o_d Window or door
var windowsAndDoorsTpl= new Template("<tr><td>1,#{id}</td><td>#{compass}</td>"+
    "<td><input id='w_o_d_surface_#{id}' value='0' class='w_o_d_surface' /><input type='hidden' id='w_o_d_no_blinds_#{id}' value='#{w_o_d_no_blinds}' name='w_o_d_no_blinds_#{id}' class='w_o_d_no_blinds' /></td>"+
    "<td><select id='w_o_d_blinds_#{id}' name='w_o_d_blinds_#{}id' id='w_o_d_blinds'><option value='n'>ne</option><option value='y'>ano</option></select></td>"+
    "<td><input disabled='disabled' id='w_o_d_gain_#{id}' name='w_o_d_gain_#{id}' class='w_o_d_gain'> W</td>"+
    "</tr>"+
    "<script type='text/JavaScript'>"+
    "Event.observe('w_o_d_surface_#{id}','keyup',function(e){ recalculateWindowsWithBlinds(#{id}); })"+"\n"+
    "Event.observe('w_o_d_blinds_#{id}','change',function(e){ recalculateWindowsWithBlinds(#{id}); })"+"\n"+
    "</script>"
    );
    
    function recalculateWindowsWithBlinds(id)
    {
        var reduce = 0;
        if (($F('w_o_d_blinds_'+id)=='y') && $F('w_o_d_no_blinds_'+id)>70) reduce = $F('w_o_d_surface_'+id)*70;
        else reduce = 0;
        $('w_o_d_gain_'+id).value = ($F('w_o_d_surface_'+id)*$F('w_o_d_no_blinds_'+id)) - reduce;
        getMaxGain();
        calculateCoolingpower();
    }
    
var WoDOtherTpl=new Template("<input name='w_o_d_other_#{id}' id='w_o_d_other_#{id}' class='w_o_d_other'>"+
                            "<script type='text/JavaScript'>"+
                            "Event.observe('w_o_d_other_#{id}','keyup',function(e){recalculateWoDOtherRow(#{id});})"+"\n"+
                             "</script>"
                             );


var OuterWallsTpl=new Template("<input name='outer_wall_#{id}' id='outer_wall_#{id}' class='outer_wall'>"+
                            "<script type='text/JavaScript'>"+
                            "Event.observe('outer_wall_#{id}','keyup',function(e){recalculateWoDOuterRow(#{id});})"+"\n"+
                             "</script>"
                             );

var OuterWallsHeavyTpl=new Template("<input name='outer_wall_heavy_#{id}' id='outer_wall_heavy_#{id}' class='outer_wall_heavy'>"+
                            "<script type='text/JavaScript'>"+
                            "Event.observe('outer_wall_heavy_#{id}','keyup',function(e){recalculateWoDOuterHeavyRow(#{id});})"+"\n"+
                             "</script>"
                             );


var OtherWallsTpl=new Template("<input name='other_wall_#{id}' id='other_wall_#{id}' class='other_wall'>"+
                            "<script type='text/JavaScript'>"+
                            "Event.observe('other_wall_#{id}','keyup',function(e){recalculateOtherWallRow(#{id});})"+"\n"+
                             "</script>"
                             );

function recalculateOtherWallRow()
{
    var sum=0;
    $$('.other_wall').each(function(o){parseInt(o.value)?sum+=parseInt(o.value):0;});
    $('other_wall_surface').value=sum;
    $('other_wall_gain').value=sum*$F('other_wall_constant');
    calculateCoolingpower();
}
 

function recalculateWoDOuterHeavyRow()
{
    var sum=0;
    $$('.outer_wall_heavy').each(function(o){parseInt(o.value)?sum+=parseInt(o.value):0;});
    $('outer_wall_heavy_surface').value=sum;
    $('outer_wall_heavy_gain').value=sum*$F('outer_wall_heavy_constant');
    calculateCoolingpower();
}
 
 
function recalculateWoDOuterRow()
{
    var sum=0;
    $$('.outer_wall').each(function(o){parseInt(o.value)?sum+=parseInt(o.value):0;});
    $('outer_wall_light_surface').value=sum;
    $('outer_wall_light_gain').value=sum*$F('outer_wall_light_constant');
    calculateCoolingpower();
} 
 
 
function recalculateWoDOtherRow()
{
    var sum=0;
    $$('.w_o_d_other').each(function(wod){parseInt(wod.value)?sum+=parseInt(wod.value):0;});
    $('w_o_d_surface_other').value=sum;
    $('w_o_d_gain_other').value=sum*$F('w_o_d_other_constant');
    calculateCoolingpower();
}



function recalculateWoDRowSurface(id)
{
    $('w_o_d_surface_'+id).value=$('w_o_d_width_'+id).value*$('w_o_d_height_'+id).value*$('w_o_d_quantity_'+id).value;
}

function recalculateWoDRow(id)
{
    $('w_o_d_gain_'+id).value=$('w_o_d_no_blinds_'+id).value*$('w_o_d_no_blinds_surface_'+id).value+$('w_o_d_inner_blinds_'+id).value*$('w_o_d_inner_blinds_surface_'+id).value+$('w_o_d_outer_blinds_'+id).value*$('w_o_d_outer_blinds_surface_'+id).value;
    getMaxGain();
    calculateCoolingpower();
}


function getMaxGain()
{
    var maxGain=0;
    $$('.w_o_d_gain').each(function(g){
        if(parseInt(g.value)>parseInt(maxGain))
        {
            maxGain=g.value;
        }
    });
    
    $('w_o_d_gain_max').value=maxGain;
    return maxGain;
}

function calculateCoolingpower()
{
    var sum=0;
    sum+=parseInt(getMaxGain());
    ['w_o_d_gain_other','outer_wall_light_gain','outer_wall_heavy_gain','other_wall_gain','floor_total','persons_total','heaters','hole_total'].each(function(e){
        if ($(e))
        {
            sum+=parseInt($F(e))?parseInt($F(e)):0;
        }
    });
    
    for(i=1;i<6;i++)
    {
        sum+=parseInt($F('roof_total_'+i))?parseInt($F('roof_total_'+i)):0;
    }
    $('cooling_power').value=sum;
    $('psyoForm6Row68').value=sum;
}

