

// -----------------------------------------------------
// Get window width in pixels; returns 0 if unidentifiable.
// -----------------------------------------------------
function getWindowWidth(){
  var ww = 0;
  d = document;
   if ( typeof window.innerWidth != 'undefined' )
     ww = window.innerWidth;  // NN and Opera version
   else
   {
     if ( d.documentElement
       && typeof d.documentElement.clientWidth!='undefined'
       && d.documentElement.clientWidth != 0 )
       ww = d.documentElement.clientWidth;
     else
       if ( d.body
         && typeof d.body.clientWidth != 'undefined' )
         ww = d.body.clientWidth;
     else alert ("Can't identify window width - please tell me which browser you are using.")
   }
   return ww;
}



function GetWidth()
{
        var x = 0;

        if (self.innerHeight)
        {
	    x = self.innerWidth;
	    // hack for Fiewfox 
	    x = x -50;
	    if(x<0){
		x = 0;
	    }
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                x = document.documentElement.clientWidth;
        }
        else if (document.body)
        {
                x = document.body.clientWidth;
        }
        return x;

}



function commentWrite(msg){
    msg = "<!--"+msg+"-->"
	document.write(msg)


}

function rotateimage(initImageCount,bWidth)
{
    frameNo = (frameNo+ 1)%initImageCount;
    var j;
    var tmpString;
    j=frameNo;
    var ww = GetWidth();

    if (curindex==(tempindex=Math.floor(Math.random()*(randomimages[j].length)))){
	curindex=curindex==0? 1 : curindex-1
	    }
    else{
	curindex=tempindex
	    }
  
     eval("document.images.defaultimage"+j).src = randomimages[j][curindex]

	 // After checking the window width, determine how many we're going to continue displaying
	 // Calculate no. which ww can accomodate

     
     // No. of images fittable at the current image width
     var imageWidthCount = Math.floor(ww/(2*bWidth+imageWidth));
   
	 


 for(i=1;i<initImageCount;i++){
	 if(i+1 > imageWidthCount){
	     eval("document.images.defaultimage"+i).width = 0;
	     eval("document.images.defaultimage"+i).height = 0;
	 } else {
	     	      eval("document.images.defaultimage"+i).width = imageWidth;
	     eval("document.images.defaultimage"+i).height = imageHeight;

	 }
     }
}




var delay=5000 //set delay in miliseconds
var curindex=0
     var frameNo=0;
var bWidth = 5;
//commentWrite("tesst")

var preload=new Array(dirCount)
    for(j=0;j<dirCount;j++){
	preload[j] = new Array(randomimages[j].length);
	for (n=0;n<randomimages[j].length;n++)
	    {
	preload[j][n]=new Image()
	preload[j][n].src=randomimages[j][n]
	    }
    }

  var ww = GetWidth();
//ww = this.parentElement.offsetWidth;
var   initImageCount = Math.min(Math.floor(ww/(imageWidth+2*bWidth)),dirCount);


if(initImageCount<dirCount){
    // We either have to reduce the imageWidth 
    var maxAtMinWidthCount = Math.min(Math.floor(ww/(minWidth+2*bWidth)),dirCount);
    var newWidth = Math.floor((ww-(2*bWidth*maxAtMinWidthCount))/maxAtMinWidthCount);
    initImageCount = maxAtMinWidthCount;
    imageWidth = newWidth;
    imageHeight = Math.floor(imageWidth*2/3);

}



for(j=0;j<initImageCount;j++){

  

    document.write('<img  style= "margin: '+bWidth+'px; border-width:0px" name="defaultimage'+j+'"  width="'+imageWidth+'" height="'+imageHeight+'" src="'+randomimages[j][Math.floor(Math.random()*(randomimages[j].length))]+'">');


      
      }

 setInterval("rotateimage(initImageCount,bWidth)",delay)
   
