// Image Window

var gobjImageWindow;

window.onload = Document_Initialize;

function Document_Initialize()
{
    Image_Initialize();
}

function openImage(strURL, intWidth, intHeight, strResizable)
{
  var strFeatues = new String("location=yes,menubar=no,resizable=" + strResizable + ",status=no,titlebar=no,toolbar=no,personalbar=no,directories=no,scrollbars=no,width=" + intWidth + ",height=" + intHeight + "");
  
  if (!gobjImageWindow)
  {
    gobjImageWindow = window.open(strURL, 'ImageWindow', strFeatues);
  }
  else
  {
    if (gobjImageWindow.closed)
    {
      gobjImageWindow = window.open(strURL, 'ImageWindow', strFeatues);
    }
    else
    {
      gobjImageWindow.close();
      gobjImageWindow = window.open(strURL, 'ImageWindow', strFeatues);
    }
    gobjImageWindow.focus();
  }
}

// Random Quote

      var gobjImages = new Array(14);
      var gintImages_Counter = new Number(0);
      var gobjImages_Timer;
      var gintImages_Timer_Interval = new Number(0);
      var gstrImages_Target = new String("");

      function Image_Initialize()
      {
        try
        {
            gstrImages_Target = "iTarget";

            document.getElementById(gstrImages_Target).onmouseover = Image_OnMouseOver;
            document.getElementById(gstrImages_Target).onmouseout = Image_OnMouseOut;
        }
        catch (e)
        {
            return null;
        }
        
        gobjImages[0] = 0;

        gintImages_Timer_Interval = 5000;
        gobjImages_Timer = setTimeout("Image_PreCache_Failed()", 30000);

        gobjImages.length = gobjImages.length + 1;

        Image_PreCache("/WarCard/Images/Quotes/CPI_Iraq_quotes1.jpg", 342, 126);
        Image_PreCache("/WarCard/Images/Quotes/CPI_Iraq_quotes2.jpg", 342, 126);
        Image_PreCache("/WarCard/Images/Quotes/CPI_Iraq_quotes3.jpg", 342, 126);
        Image_PreCache("/WarCard/Images/Quotes/CPI_Iraq_quotes4.jpg", 342, 126);
        Image_PreCache("/WarCard/Images/Quotes/CPI_Iraq_quotes5.jpg", 342, 126);
        Image_PreCache("/WarCard/Images/Quotes/CPI_Iraq_quotes6.jpg", 342, 126);
        Image_PreCache("/WarCard/Images/Quotes/CPI_Iraq_quotes7.jpg", 342, 126);
        Image_PreCache("/WarCard/Images/Quotes/CPI_Iraq_quotes8.jpg", 342, 126);
        Image_PreCache("/WarCard/Images/Quotes/CPI_Iraq_quotes9.jpg", 342, 126);
        Image_PreCache("/WarCard/Images/Quotes/CPI_Iraq_quotes10.jpg", 342, 126);
        Image_PreCache("/WarCard/Images/Quotes/CPI_Iraq_quotes11.jpg", 342, 126);
        Image_PreCache("/WarCard/Images/Quotes/CPI_Iraq_quotes12.jpg", 342, 126);
        Image_PreCache("/WarCard/Images/Quotes/CPI_Iraq_quotes13.jpg", 342, 126);
        Image_PreCache("/WarCard/Images/Quotes/CPI_Iraq_quotes14.jpg", 342, 126);
      }

      function Image_PreCache(strImage_Src, intImage_Width, intImage_Height)
      {
        var intImage_Loaded = parseInt(gintImages_Counter + 1);

        gintImages_Counter = intImage_Loaded;

        gobjImages[intImage_Loaded] = new Image(intImage_Width, intImage_Height);
        gobjImages[intImage_Loaded].onload = Image_OnLoad;
        gobjImages[intImage_Loaded].src = strImage_Src;
      }

      function Image_PreCache_Failed()
      {
        clearTimeout(gobjImages_Timer);

        if (gobjImages[0] != -1)
        {
          throw new Error("", "Image_PreCache()" + "\n\n" + "Failed to load Image collection.");
        }
      }

      function Image_OnLoad()
      {
        var intImage_Length = parseInt(gobjImages.length - 1);
        var intImage_Loaded = parseInt(gobjImages[0] + 1);

        gobjImages[0] += 1;

        if (intImage_Length == intImage_Loaded)
        {
          Image_OnReady();
        }
      }

      function Image_OnReady()
      {
        clearTimeout(gobjImages_Timer);

        gobjImages[0] = -1;
        gintImages_Counter = 0;
        
        // Single Random Image
        gobjImages_Timer = setTimeout("Single_Load()", 1);
        
        //SlideShow_Load();

        // SlideShow Random Images
        //gobjImages_Timer = setInterval("SlideShow_Load()", gintImages_Timer_Interval);
      }

      function Image_OnMouseOver()
      {
        clearInterval(gobjImages_Timer);

        document.getElementById(gstrImages_Target).alt = "Mouse Out to Resume Random Image Display";
        document.getElementById(gstrImages_Target).title = "Mouse Out to Resume Random Image Display";
      }

      function Image_OnMouseOut()
      {
        gobjImages_Timer = setInterval("SlideShow_Load()", gintImages_Timer_Interval);

        document.getElementById(gstrImages_Target).alt = "Mouse Over to Pause Image";
        document.getElementById(gstrImages_Target).title = "Mouse Over to Pause Image";
      }
      
      function Single_Load()
      {
        clearTimeout(gobjImages_Timer);
        
        gintImages_Counter = (Math.floor(Math.random() * (gobjImages.length - 1)) + 1);

        if (gintImages_Counter >= gobjImages.length)
        {
          gintImages_Counter = gobjImages.length - 1;
        }

        if (gintImages_Counter <= 0)
        {
          gintImages_Counter = 1;
        }

        document.getElementById(gstrImages_Target).alt = "";
        document.getElementById(gstrImages_Target).title = "";
        document.getElementById(gstrImages_Target).src = gobjImages[gintImages_Counter].src;
      }

      function SlideShow_Load()
      {
        gintImages_Counter = (Math.floor(Math.random() * (gobjImages.length - 1)) + 1);

        if (gintImages_Counter >= gobjImages.length)
        {
          gintImages_Counter = gobjImages.length - 1;
        }

        if (gintImages_Counter <= 0)
        {
          gintImages_Counter = 1;
        }

        document.getElementById(gstrImages_Target).alt = "Mouse Over to Pause Image";
        document.getElementById(gstrImages_Target).title = "Mouse Over to Pause Image";
        document.getElementById(gstrImages_Target).src = gobjImages[gintImages_Counter].src;
      }
      
// Image Swap

function SwapImage(strId, strURL)
{
    document.getElementById(strId).src = strURL;
}