//  <!----------------------------------------------------------------------------------->
//  <!--                                                                               -->
//  <!-- This code was created by Mark West.                                           -->
//  <!-- Feel free to read it and find out how I did stuff, but if you knick anything  -->
//  <!-- substantial, then please credit me in your code, and let me know that my code -->
//  <!-- has been useful!  Thanks.  Mark (www.mixedcasesspaces.co.uk).                 -->
//  <!--                                                                               -->
//  <!----------------------------------------------------------------------------------->

var isIE = false;
var fade_step = 0.1;
var fade_step_content = 0;
var season = "spring";

// called when the index.html page loads:
function indexpage_init()
{
  if (navigator.appName.indexOf("Microsoft")!=-1)
  {
    isIE=true;
  }
  
  // set all elements we will be fading in to fully transparent:
  for (i=10;i<20;i++)
  {
    if (isIE)
    {
      document.getElementById("fade_obj_"+i).style.position="absolute"; // have to do this for IE for transparency to work
    }
  }

  // load first page:
  document.getElementById("hidden").src="welcome.html";

  // set all elements we will be fading in to fully transparent:
  for (i=0;i<26;i++)
  {
    if (document.getElementById("fade_obj_"+i))
    {
      if (isIE)
      {
        document.getElementById("fade_obj_"+i).filters.alpha.opacity=0;
      }
      else
      {
        document.getElementById("fade_obj_"+i).style.MozOpacity=0;
      }
    }
  }

  calculate_season();

  display_side_images();

  // display page and hide loading message:
  document.getElementById("loading").style.display="none";
  document.getElementById("all").style.display="inline";

  // fade in menus and images etc
  setTimeout("do_fade_in()",10);
}

// called by each page when it loads, to set the parent's menu option as 'current' and display content:
function subpage_init(option)
{
  try
  {
    // set all menu options to non-current:
    for (i=10;i<20;i++)
    {
      parent.document.getElementById("fade_obj_"+i).className="link";
    }

    // set the current link to link_current:
    parent.document.getElementById(option).className="link_current";

    // hide content ready to fade it in:
    if (isIE)
    {
      parent.document.getElementById("fade_obj_25").filters.alpha.opacity=0;
    }
    else
    {
      parent.document.getElementById("fade_obj_25").style.MozOpacity=0;
    }

    // load page contents into the display div in the main page (cunning!):
    parent.document.getElementById("display_div").innerHTML=document.body.innerHTML;

    // if the page is one of the gallery pages, hide the usual side images, otherwise update them:
    if ((option=="fade_obj_17") || (option=="fade_obj_18"))
    {
      parent.document.getElementById("images_div").style.display="none";
      parent.document.getElementById("fade_obj_25").style.width="450px";
    }
    else
    {
      parent.document.getElementById("images_div").style.display="inline";
      parent.document.getElementById("fade_obj_25").style.width="245px";
      parent.display_side_images();
    }

    // fade in content:
    parent.fade_step_content = 0.1;
    parent.do_fade_in_content();

    parent.hide_loading();
  }
  catch (err)
  {
    // simply ignore any problems, they are probably caused by opening a page outside of the parent frame.
  }
}

function do_fade_in()
{
  // set all elements we will be fading in current transparency:
  for (i=0;i<25;i++)
  {
    if (document.getElementById("fade_obj_"+i))
    {
      if (isIE)
      {
        document.getElementById("fade_obj_"+i).filters.alpha.opacity=(fade_step*100)-(i*10);
      }
      else
      {
        document.getElementById("fade_obj_"+i).style.MozOpacity=(fade_step-(i*0.1));
      }
    }
  }

  // increase fade level:
  fade_step = fade_step+0.1;

  // call next fade in step:
  if (fade_step<=3.5)
  {
    setTimeout("do_fade_in()",10);
  }
}

function do_fade_in_content()
{
  if (isIE)
  {
    document.getElementById("fade_obj_25").filters.alpha.opacity=(fade_step_content*100);
  }
  else
  {
    document.getElementById("fade_obj_25").style.MozOpacity=fade_step_content;
  }

  // increase fade level:
  fade_step_content = fade_step_content+0.05;

  // call next fade in step:
  if (fade_step_content<=1)
  {
    setTimeout("do_fade_in_content()",30);
  }
}

function show_loading()
{
  try
  {
    document.getElementById("loading").style.display="inline";
  }
  catch (err)
  {
    // simply ignore any problems, they are probably caused by opening a page outside of the parent frame.
  }
}

function hide_loading()
{
  document.getElementById("loading").style.display="none";
}

function calculate_season()
{
  // The month is used to calculate which seasonal images to display.
  var month = new Date().getMonth()+1;

  if ((month>=3) && (month<6)) { season = "spring"; }
  else if ((month>=6) && (month<9)) { season = "summer"; }
  else if ((month>=9) && (month<12)) { season = "autumn"; }
  else { season = "winter"; }
}

function display_side_images()
{
  // select indoor or outdoor display, randomly:
  var in_out = "indoor";
  if (Math.floor(Math.random()*2)) { in_out = "outdoor"; }

  // select three images from this display at random:
  var random_image1=(Math.floor(Math.random()*8))+1;
  var random_image2=random_image1+1;
  var random_image3=random_image1+2;
  if (random_image1==7) {random_image3=1;};
  if (random_image1==8) {random_image2=1;random_image3=2;};


//  if (isIE)
//  {
//    document.getElementById("fade_obj_2").filters.alpha.opacity=0;
//    document.getElementById("fade_obj_3").filters.alpha.opacity=0;
//    document.getElementById("fade_obj_4").filters.alpha.opacity=0;
//  }
//  else
//  {
//    document.getElementById("fade_obj_2").style.MozOpacity=0;
//    document.getElementById("fade_obj_3").style.MozOpacity=0;
//    document.getElementById("fade_obj_4").style.MozOpacity=0;
//  }


  document.getElementById("fade_obj_2").src="displays/"+in_out+"/"+season+"/"+random_image1+".jpg";
  document.getElementById("fade_obj_3").src="displays/"+in_out+"/"+season+"/"+random_image2+".jpg";
  document.getElementById("fade_obj_4").src="displays/"+in_out+"/"+season+"/"+random_image3+".jpg";

  document.getElementById("images_div").title=in_out+" displays for "+season;
}

