/*****************************************/
/*     Begin Configuration               */
/*****************************************/

var CloudImages = [
      "/uploads/d2/Om/d2OmgYw8aQHbf3sUq8nFQw/clouds_01.png",
      "/uploads/Ud/Ck/UdCkBZJh_7dJWYM9U9NS6Q/clouds_02.png",
      "/uploads/XX/jf/XXjfEzlDz8xplcxh-ZljEw/clouds_03.png",
      "/uploads/S-/ba/S-bauLBfv1kTFZIWv6VBgQ/clouds_04.png"
    ];
var CloudCount = 15;
var CloudMinSpeed = 1;
var CloudMaxSpeed = 4;
var DebugMode = true;

/*****************************************/
/*     End Configuration                 */
/*****************************************/

var WinWidth = 0;
var WinHeight = 0;
var cloudSpeed = [];
var cloudX = [];
var debugLog = "";

function SetWindowDimensions() {
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    WinWidth = window.innerWidth;
    WinHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    WinWidth = document.documentElement.clientWidth;
    WinHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    WinWidth = document.body.clientWidth;
    WinHeight = document.body.clientHeight;
  }
} // SetWindowDimensions()

function GetRandom(min, max) {
  var randomNum = Math.random() * (max-min); 
  return (Math.round(randomNum) + min); 
} // GetRandom()

function GetRandomX() {
  return GetRandom(100, WinWidth - 200);
} // GetRandomX()

function GetRandomY() {
  return GetRandom(-30, 400);
} // GetRandomY()

function StartCloud(cloudIdx, initialPosition) {
  var cloud = document.getElementById("cloud_" + cloudIdx);
  
  if (cloud == null) {
    var rndCloudIdx = GetRandom(0, CloudImages.length - 1);
    document.body.innerHTML += "<img src=\"" + CloudImages[rndCloudIdx] + "\" alt=\"\" title=\"\" class=\"Cloud\" id=\"cloud_" + cloudIdx + "\" /></div>";
    cloud = document.getElementById("cloud_" + cloudIdx);
    if (isLousyBrowser) {
      doPNGTransparencyFix(cloud);
    }
  }

  var newY = GetRandomY();
  if (initialPosition) {
    cloudX[cloudIdx] = GetRandom(-300,WinWidth);
  } else {
    cloudX[cloudIdx] = WinWidth + 1;
  }
  cloudSpeed[cloudIdx] = GetRandom(CloudMinSpeed, CloudMaxSpeed);
  cloud.style.display = "block";
  cloud.style.visibility = "visible";
  cloud.style.top = newY + "px";
  cloud.style.left = cloudX[cloudIdx] + "px";
} // StartCloud()

function MoveClouds() {
  var dbg = "";
  var cloud;
  for (var i = 1; i <= CloudCount; i++) {
    cloud = document.getElementById("cloud_" + i);
    cloudX[i] = cloudX[i] - cloudSpeed[i];
    cloud.style.left = cloudX[i] + "px";
    if (cloudX[i] < -500) { StartCloud(i, false); }
  } // for()
  setTimeout("MoveClouds()", 100);
} // MoveClouds();

function StartAnimation() {
  for (var i = 1; i <= CloudCount; i++) {
    StartCloud(i, true);
  } // for()
  setTimeout("MoveClouds()", 100);
} // StartAnimation()

function PositionMainFrame() {
  //alert(main.style.top)
  //document.getElementById("mainFrame").style.left = 800px;
} // PositionMainFrame();

function Initialize() {
  SetWindowDimensions();
  PositionMainFrame();
  StartAnimation();
} // Initialize()