function MouseEnter(image)
{
  if (image.parentNode.nodeName.toLowerCase()=='a')
  {
    var src = "images/"  + image.name + "Blur.gif";
    image.src = src;
  }
}

function MouseLeave(image)
{
  if (image.parentNode.nodeName.toLowerCase()=='a')
  {
      var src = "images/"  + image.name + ".gif";
      image.src = src;
  }
}


function resize_main_image(image) {
//function to resize the next image to fit in the maximum space. Max space defined in img tag of galleryMainImage.
var nextImage = new Image();
nextImage.src = image;
var elem = document.getElementById("galleryMainImage");
var orig_width = nextImage.width;
var orig_height = nextImage.height;
var maxheight = parseInt(document.getElementById("galleryMainImage").getAttribute("maxheight"));
var maxwidth = parseInt(document.getElementById("galleryMainImage").getAttribute("maxwidth"));

//alert ('Orig Size WH:'+ orig_width +'*'+ orig_height );
//alert ('Elem Size WH:'+ elem.width +'*'+ elem.height );

if (orig_width > orig_height) {
if (orig_width > maxwidth ) { elem.width = maxwidth ; elem.height = orig_height*(maxwidth /orig_width);}
} else {
if (orig_height > maxheight) { elem.height = maxheight; elem.width = orig_width*(maxheight/orig_height);};
}
} 



function PageLoad(imagePath)
{
  // go through hiding the focus rectangle on all anchor tags
  var theahrefs = document.getElementsByTagName("a");
  if (!theahrefs)
  {
    return;
  }
  for(var x=0; x!=theahrefs.length; x++)
  {
    theahrefs[x].onfocus = function stopLinkFocus() 
                            {
                                this.hideFocus=true;
                            };
  }
  
  thumbsDiv = document.getElementById("thumbs");
  if (thumbsDiv != null)
  {
      tr = thumbsDiv.firstChild.firstChild.firstChild;
      // insert go left button
      td = tr.firstChild;
      anchor = td.firstChild;
      td.className = "galleryButton";
      anchor.href = "javascript: moveGalleryRight('"+imagePath+"')";

      // insert thumbs
      
      td = td.nextSibling;     
      for (i=1; i<8; i++)
      {
        anchor = td.firstChild;
        td.className = "thumb";
        image = anchor.firstChild;
        image.setAttribute("index", i.toString());
        image.src = "images/"+imagePath+"/"+i.toString()+"Thumb.jpg";
        image.id = "thumb"+i.toString();
        anchor.href="javascript:showGalleryImage('"+imagePath+"', "+i.toString()+")"; 
        td = td.nextSibling;
      }
      
      // insert go right button
      anchor = td.firstChild;
      td.className = "galleryButton";
      anchor.href = "javascript: moveGalleryLeft('"+imagePath+"')";
  }

	imageCount = parseInt(document.getElementById("thumbs").getAttribute("imageCount"));
	firstimage = parseInt(document.getElementById("galleryMainImage").getAttribute("firstimage"));

	//load the first image
	var image = document.getElementById("galleryMainImage");
	image.src = "images/"+imagePath+"/"+firstimage.toString()+".jpg";

	//preload the other images

	// counter
	var i = 0;
	// start preloading
	imageObj = new Image();
	for(i=0; i<=(imageCount.toString()-1) ; i++) 
	{
		imageObj.src= "images/"+imagePath+"/"+ i +".jpg";
	}


resize_main_image(image.src);
}





function showGalleryImage(imagePath, index)
{
  var image = document.getElementById("galleryMainImage");
  image.src = "images/"+imagePath+"/"+index.toString()+".jpg";
  resize_main_image(image.src);
}

function moveGalleryLeft(imagePath)
{
  rightImage = document.getElementById("thumb7");
  imageCount = parseInt(document.getElementById("thumbs").getAttribute("imageCount"));
  if (parseInt(rightImage.getAttribute("index")) < imageCount)
  {
      thumbsDiv = document.getElementById("thumbs");

      tr = thumbsDiv.firstChild.firstChild.firstChild;
      td = tr.firstChild.nextSibling;     

      for (i=1; i<8; i++)
      {
        anchor = td.firstChild;
        image = anchor.firstChild;
        index = parseInt(image.getAttribute("index")) + 1;
        image.setAttribute("index", index);
        image.src = "images/"+imagePath+"/"+index.toString()+"thumb.jpg";
        anchor.href="javascript:showGalleryImage('"+imagePath+"', "+index.toString()+")";
        
        td = td.nextSibling;
      }
  }
}

function moveGalleryRight(imagePath)
{
  leftImage = document.getElementById("thumb1");
  if (parseInt(leftImage.getAttribute("index")) > 1)
  {
      thumbsDiv = document.getElementById("thumbs");

      tr = thumbsDiv.firstChild.firstChild.firstChild;
      td = tr.firstChild.nextSibling;     

      for (i=1; i<8; i++)
      {
        anchor = td.firstChild;
        image = anchor.firstChild;
        index = parseInt(image.getAttribute("index")) - 1;
        image.setAttribute("index", index);
        image.src = "images/"+imagePath+"/"+index.toString()+"thumb.jpg";
        anchor.href="javascript:showGalleryImage('"+imagePath+"', "+index.toString()+")";
        
        td = td.nextSibling;
      }
  }
}

function StopAudio( o ) 
{ 
    if(is_ie&&is_major>=4&&eval('document.'+o))
    {
        var e=eval('document.'+o);
        if(e.src&&e.src!=''&&e.ReadyState&&e.ReadyState>=4)
        {
            e.stop();
        }
    }
    else
    {
        if(is_nav&&is_major>=3&&(is_major<4||eval('document.'+o)))
        {
            eval('document.'+o+'.stop()');
        }
    }
}
 
function PlayAudio( o ) 
{ 
//    StopAudioAll();
    // replace embed tag
    div = document.getElementById('AudioPlayer');

 //   if (div.firstChild.src != 'reels/'+o+'.mp3')
 //   {
        html = '<EMBED name="AudioPlayer" src="reels/'+o+'.mp3" autostart="true" hidden="true" volume="100" width="0" height="0"/>';
        div.innerHTML = html;
 //   }
    if(is_ie&&is_major>=4&&eval('document.AudioPlayer'))
    {
        var e=eval('document.AudioPlayer');
        if(e.src && (e.src!='') && e.ReadyState && (e.ReadyState>=4))
        {
            if (is_major>=5)
            {
                e.play();
            }
            else
            {
            e.run();
            }
        }
    }
    else
    {
        if(is_nav&&is_major>=3&&(is_major<4||eval('document.AudioPlayer')))
        {
            eval('document.AudioPlayer.play(false)');
        }
    }
} 

function StopAudioAll()
{
    div = document.getElementById('AudioPlayer');
    div.innerHTML=" ";
    StopAudio('AudioPlayer'); 
} 