  function ToggleSendToFriend() {
    sendToFriendForm = document.getElementById('SendToFriendForm');
    sendToFriendButton = document.getElementById('SendToFriendButton');

    if (sendToFriendForm.style.visibility == "hidden") {
      sendToFriendForm.style.visibility = "visible";
      sendToFriendForm.style.display = 'block';
    } else {
      sendToFriendForm.style.visibility = "hidden";
      sendToFriendForm.style.display = 'none';
    }

    //sendToFriendForm.style.left = getposOffset(sendToFriendButton, "left") - sendToFriendForm.offsetWidth + sendToFriendButton.offsetWidth;
    sendToFriendForm.style.left = getposOffset(sendToFriendButton, "left") - (sendToFriendForm.offsetWidth / 2) + (sendToFriendButton.offsetWidth / 2);
    sendToFriendForm.style.top = getposOffset(sendToFriendButton, "top") + sendToFriendButton.offsetHeight;
  }
  
  function ToggleAddComment() {
    commentMenu = document.getElementById('CommentMenu');
    commentButton = document.getElementById('CommentButton');

    commentMenu.style.left = getposOffset(commentButton, "left");
    commentMenu.style.top = getposOffset(commentButton, "top") + commentButton.offsetHeight;

    if (commentMenu.style.visibility == "hidden") {
      commentMenu.style.visibility = "visible";
      commentMenu.style.display = 'block';
    } else {
      commentMenu.style.visibility = "hidden";
      commentMenu.style.display = 'none';
    }
  }
  
  function ToggleGalleryThumbnail(pictureID) {
    largeThumbDiv = document.getElementById('SecondaryThumbDiv' + pictureID);
    smallThumb = document.getElementById('SmallThumb' + pictureID);

    if (largeThumbDiv.className == "secondaryThumbnailHidden") {
      largeThumbDiv.className = "secondaryThumbnailPopup";
      largeThumbDiv.style.left = getposOffset(smallThumb, "left") - ((largeThumbDiv.offsetWidth - smallThumb.offsetWidth) / 2) + "px";
      largeThumbDiv.style.top = getposOffset(smallThumb, "top")  - ((largeThumbDiv.offsetHeight - smallThumb.offsetHeight) / 2) + "px";
      setTimeout(function() { largeThumbDiv.style.visibility = "visible"; }, 5);
    } else {
	  largeThumbDiv.className = "secondaryThumbnailHidden";
    }
  }
  
  function ToggleRateMenu() {
    rateMenu = document.getElementById('RateMenu');
    rateButton = document.getElementById('RateButton');

    rateMenu.style.left = getposOffset(rateButton, "left");
    rateMenu.style.top = getposOffset(rateButton, "top") + rateButton.offsetHeight;

    if (rateMenu.style.visibility == "hidden") {
      rateMenu.style.visibility = "visible";
      rateMenu.style.display = 'block';
    } else {
      rateMenu.style.visibility = "hidden";
      rateMenu.style.display = 'none';
    }
  }

  function ToggleSearchMenu() {
    searchMenu = document.getElementById('SearchMenu');
    searchButton = document.getElementById('SearchButton');

    searchMenu.style.left = getposOffset(searchButton, "left");
    searchMenu.style.top = getposOffset(searchButton, "top") + searchButton.offsetHeight;

    if (searchMenu.style.visibility == "hidden") {
      searchMenu.style.visibility = "visible";
      searchMenu.style.display = 'block';
    } else {
      searchMenu.style.visibility = "hidden";
      searchMenu.style.display = 'none';
    }
  }

function getposOffset(what, offsettype){
  var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
  var parentEl=what.offsetParent;
  while (parentEl!=null){
    totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
    parentEl=parentEl.offsetParent;
  }
  return totaloffset;
}

function ToggleMenuOnOff (menuName) {
    menu = document.getElementById(menuName);

    if (menu.style.display == 'none') {
      menu.style.display = 'block';
    } else {
      menu.style.display = 'none';
    }

}

function OpenWindow (target) { 
  window.open(target, "_Child", "toolbar=no,scrollbars=yes,resizable=yes,width=400,height=400"); 
}

function OpenPostWindow (target) { 
  window.open(target, "_Child", "resizable=yes,width=500,height=700"); 
}

/*
window.onload = Init;
function Init()
{
	var maxWidth = 550;
	var maxHeight = 350;
	var imgs = document.getElementsByTagName("img");
	for(var i=0; i<imgs.length; i++)
	{
		var img = imgs[i];
		if(img.width > maxWidth)
		{
			img.height = maxWidth/img.width*img.height;
			img.width = maxWidth;
		}
		else if(img.height > maxHeight)
		{
			img.width = maxHeight/img.height*img.width;
			img.height = maxHeight;
		}
		if(img.parentElement.tagName != "A")
		{
			img.onclick = function(){window.open(this.src)}
			img.style.cursor = "pointer";
			img.style.cursor = "hand";
		}
	}
} 
--*/

function ResizeImage(imageid,limitWidth,limitHeight) 
{     
    var image = new Image(); 
    image.src = imageid.src; 
     
    if(image.width <= 0 && image.height <= 0) return; 
     
    if(image.width/image.height >= limitWidth/limitHeight) 
    { 
        if(image.width > limitWidth) 
        { 
            imageid.width = limitWidth; 
            imageid.height = (image.height*limitWidth)/image.width; 
        } 
    } 
    else if(image.height > limitHeight) 
    { 
            imageid.height = limitHeight; 
            imageid.width = (image.width*limitHeight)/image.height;      
    } 
     
    if (imageid.parentElement.tagName != "A") 
    { 
        imageid.onclick = function(){window.open(this.src);} 
        imageid.style.cursor = "hand"; 
    } 
} 

window.onload = InitImages; 

function InitImages() 
{ 
    var maxWidth = 400; 
    var maxHeight = 500; 
     
    var imgs = document.getElementsByTagName("img"); 
     
    for(var i=0; i < imgs.length; i++) 
    { 
        var img = imgs[i]; 
         
        if(img.width>maxWidth||img.height>maxHeight) 
            ResizeImage(img, maxWidth, maxHeight); 
    } 
}