﻿// rotating postcards

var t;
var counter = 2000;
function rotate_postcards_wrap()
{

    var i;
    var str;
    var current_div_index = document.getElementById("inp_current_postcard_div_index").value;
    document.getElementById("div_postcard_" + current_div_index).style.display="none";
    /*for (i=1;i<=document.getElementById("hid_rep_postcards_rotate_count").value;i++)
    {
       str = "div_postcard_" + i;         
       document.getElementById(str).style.display="none";
    }*/

    if (current_div_index == document.getElementById("hid_rep_postcards_rotate_count").value)
    {
       current_div_index = 1;
       document.getElementById("inp_current_postcard_id").value = document.getElementById("inp_rep_current_postcard_1").value
       document.getElementById("inp_current_postcard_filename").value = document.getElementById("inp_rep_current_postcard_filename_1").value
    }
    else
    {
       current_div_index = parseInt(current_div_index) + 1;
       document.getElementById("inp_current_postcard_id").value = document.getElementById("inp_rep_current_postcard_" + current_div_index).value;

       document.getElementById("inp_current_postcard_filename").value = document.getElementById("inp_rep_current_postcard_filename_" + current_div_index).value;
   }

    document.getElementById("div_postcard_" + current_div_index).style.display="block"
    document.getElementById("inp_current_postcard_div_index").value = current_div_index;
    t = setTimeout("rotate_postcards_wrap()",counter);
      
}
    
function rotate_postcards()
{
    if (document.getElementById("hid_rep_postcards_rotate_count").value != 0)
   { // if there are more than 0 postacards

       if (document.getElementById("inp_postcard_rotate_started").value == 0)
      {
         //start rotating            
         //document.getElementById("div_postcard_1").style.display="block";
          document.getElementById("inp_postcard_rotate_started").value = 1;
         t = setTimeout("rotate_postcards_wrap()",counter);
      }
      else
      {
          document.getElementById("inp_postcard_rotate_started").value = 0;
         clear_timeout();
      }
   }            
}
 
function clear_timeout()
{
   clearTimeout(t);
}

function rotate_postcards_on_load() {

   //alert(document.getElementById("inp_postcard_rotate_onload").value);
    if (document.getElementById("inp_postcard_rotate_onload").value == 0)
   {
       document.getElementById("inp_postcard_rotate_onload").value = 1;      
      rotate_postcards()
   }
   else
   {
         t = setTimeout("rotate_postcards_wrap()",counter);
      
      //document.getElementById("inp_postcard_rotate_onload").value = 0;      
      //rotate_postcards()
     }
   
}

// END rotating postcards


// <rotating_quotes>
var timeout_quotes = 9000;
var timeout_fade_out_start = 7500;
var obj_current;
var interval_id;
var timeout_per_fade_step = 100;
var int_opacity = 1;
var opacity_step = 0.1;
    
function rotate_quotes_on_load() {

    rotate_quotes_wrap();
    setInterval("rotate_quotes_wrap()", timeout_quotes);

}

function rotate_quotes_wrap() {

    var i;
    var int_last_index, int_current_index;
    var obj;

    int_current_index = document.getElementById("uc_header_hid_header_current_quote").value;
    int_last_index = document.getElementById("uc_header_hid_header_cnt_quotes").value;

    //move on to the next one.
    int_current_index = int_current_index * 1 + 1;
    
    //if reached the last one, go back to the first one
    if (int_current_index > int_last_index) {
        int_current_index = 0;
    }

    //save new value
    document.getElementById("uc_header_hid_header_current_quote").value = int_current_index;

    //reset opacity back to opaque and halt the previous fade-out session
    int_opacity = 0.1;
    clearInterval(interval_id);

    // show/hide appropriate divs
    for (i = 0; i <= int_last_index; i++) {

        obj = document.getElementById("header_top_quotes" + i);

        if (i == int_current_index) {
            obj.style.display = "block";
            obj_current = obj;

            //set opacity of each div to opaque
            //apply_opacity(obj);

        }
        else {
            obj.style.display = "none";

            //set opacity of each div to opaque
            //apply_opacity(obj);

        }
    }

    start_fading_in();

    setTimeout("start_fading_out()", timeout_fade_out_start);
}

function start_fading_out() {
    Effect.Fade(obj_current.id, { duration: 1.5, from: 1, to: 0.1 });
    //interval_id = setInterval("proceed_with_fading()", timeout_per_fade_step);
}

function start_fading_in() {
    Effect.Appear(obj_current.id, { duration: 2.0,  from: 0.1, to: 1  });
}

function apply_opacity(obj) {

    //ffox 0 to 1
    obj.style.opacity = int_opacity;
    //ie 0 to 100
    obj.style.filter = 'alpha(opacity = ' + (int_opacity * 100) + ')';
    //obj.filters.alpha.opacity = int_opacity * 100;

}

/*function proceed_with_fading() {

    //apply the current opacity
    apply_opacity(obj_current);

    // fade out
    int_opacity = int_opacity * 1 - opacity_step;
    
    // stop when transparency reached
    if (int_opacity < 0) {
        clearInterval(interval_id);
    }

}*/
// </rotating_quotes>


function to_upper(obj) {

    obj.value = obj.value.toUpperCase();

}
