function slideSwitch() {
  try {
    last_active = $$('#flash_header img.last_active').first()
    if (last_active){
      last_active.removeClassName('last_active')
    }
    var active = $$('#flash_header img.active').first()
    var next = (active.next() == null) ? $$('#flash_header img').first() : active.next()
    next.hide()
    active.addClassName('last_active')
    active.removeClassName('active')
    next.addClassName('active')
    new Effect.Appear(next, {duration: 3.0})
  }catch(e){}
}


function flip_gallery_photo(photo_id){
  $(photo_id).siblings().each(function(preview_photo){
    preview_photo.hide()
  })
  $(photo_id).show()
}
// closing/opening hidden content
var zindex = 999;
function getNextZIndex(){
  return zindex++;
}

function create_bookmark() {
  title = document.title; 
  url = window.location.href;
  if (window.sidebar) { // Mozilla Firefox Bookmark
    window.sidebar.addPanel(title, url,"");
  } else if( window.external ) { // IE Favorite
    window.external.AddFavorite( url, title); 
  }else if(window.opera && window.print) { // Opera Hotlist
    return true; 
  }
}

function email_friend() {
  mail_str = "mailto:?subject=Check out the " + document.title;
  mail_str += "&body=I thought you might be interested in " + document.title;
  mail_str += ". Right click your mouse to view: " + location.href;
  location.href = mail_str;
}

function toggle_hidden(action, element){
  try{
    var hidden_divs = $$('.hidden_content')
    for (i=0; i<hidden_divs.length; i++){
      if(hidden_divs[i].descendants().include(element)){
        var hidden = hidden_divs[i].select('.hidden')[0];
        var visible = hidden_divs[i].select('.visible')[0];
        // wish scripaculououos was working with elements instead of element ids
        if (action == "open"){
          hidden.style.display = 'block';
          visible.style.display = 'none';
        }else{
          hidden.style.display = 'none';
          visible.style.display = 'block';
        }
      }
    }
  } catch(e) {
    alert (e.description)
  }
}


//Check if we're in IE 6
var agt       = navigator.userAgent.toLowerCase();
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie6    = (is_ie && agt.indexOf("msie 6.")!=-1 );    


// Activate background image caching on IE6 to prevent image flicker
if (is_ie6) {
  document.execCommand('BackgroundImageCache', false, true);
}

function dropDown(){
  if (document.all&&document.getElementById) {
    navRoot = document.getElementById("first_level_nav");
    for (i=0; i<navRoot.childNodes.length; i++) {
      node = navRoot.childNodes[i];
      if (node.nodeName=="LI") {
        node.onmouseover=function() {
          this.className+=" over";
        }
        node.onmouseout=function() {
          this.className=this.className.replace(" over", "");
        }
      }
    }
  }
}



function manageCountryStateSelect(){
  $$("input[name=country]").each(function(input){
    // preparing country dropdown for replacement
    var countryDropdown = new Element(
      'select', {
        'name':     input.name,
        'tabindex': input.tabIndex
      }
    );
    countryDropdown.onchange = new Function ("evt", "loadStates(this)")
    fillSelectFromArray(countryDropdown, country_options_for_select())
    input.replace(countryDropdown)
  })
}

function fillSelectFromArray(select, options) {
  // clear select
  $A(select.options).each(function(item){
    Element.remove(item)
  })
  
  options.each(function(item){
    key = select.options.length
    select.options[key] = new Option(item)
    select.options[key].value = item
  })
}

function loadStates(select){
  // find parent form element
  var form = null
  var options = null
  $$("form").each(function(form){
    if(select.descendantOf(form)){
      $$("input[name=state]").concat($$("input[name=province]")).concat($$("select[name=state]")).concat($$("select[name=province]")).each(function(input){
        if(input.descendantOf(form)){
          if(select.value == 'Canada'){
            var options = provinces_options_for_select()
          }else if(select.value == 'United States'){
            var options = states_options_for_select()
          }
          if(options){
            var statesDropdown = new Element(
              'select', {
                'name':     input.name,
                'tabindex': input.tabIndex
              }
            );
            fillSelectFromArray(statesDropdown, options)
            input.replace(statesDropdown)
          }else{
            if(input.type != 'text'){
              var statesDropdown = new Element(
                'input', {
                  'type':     'text',
                  'name':     input.name,
                  'tabindex': input.tabIndex
                }
              );
              input.replace(statesDropdown)
            }
          }
        }
      })
    }
  })
}

function country_options_for_select(){
  return ["", "Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua And Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegowina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Congo, the Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard and McDonald Islands", "Holy See (Vatican City State)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran, Islamic Republic of", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", "Kyrgyzstan", "Lao People's Democratic Republic", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya", "Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova, Republic of", "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Palestinian Territory, Occupied", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation", "Rwanda", "Saint Barthelemy", "Saint Helena", "Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and the S.S Islands", "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan, Province of China", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Timor-Leste", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Viet Nam", "Virgin Islands, British", "Virgin Islands, U.S.", "Wallis and Futuna", "Western Sahara", "Yemen", "Zambia", "Zimbabwe"]
}

function states_options_for_select(){
  return ['Alabama', 'Alaska', 'AmericanSamoa', 'Arizona', 'Arkansas', 'ArmedForcesAmericas', 'ArmedForcesEurope', 'ArmedForcesPacific', 'California', 'Colorado', 'Connecticut', 'Delaware', 'DistrictofColumbia', 'Florida', 'Georgia', 'Guam', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'NewHampshire', 'NewJersey', 'NewMexico', 'NewYork', 'NorthCarolina', 'NorthDakota', 'NorthernMarianas', 'Ohio', 'Oklahoma', 'Oregon', 'Palau', 'Pennsylvania', 'PuertoRico', 'RhodeIsland', 'SouthCarolina', 'SouthDakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'VirginIslands', 'Virginia', 'Washington', 'WestVirginia', 'Wisconsin', 'Wyoming']
}

function provinces_options_for_select(){
  return ['Alberta', 'British Columbia', 'Manitoba', 'New Brunswick', 'Newfoundland and Labrador', 'Northwest Territories', 'Nova Scotia', 'Nunavut', 'Ontario', 'Prince Edward Island', 'Quebec', 'Saskatchewan', 'Yukon']
}

window.onunload = function(e) {
  var title =  $('content').style.fontSize;
  createCookie("textsize", title, 365);
}

window.onload = function(){
  setInterval("slideSwitch()", 6000)
  dropDown();
  manageCountryStateSelect();
}
