/*-----------------------------------
*           MODULE HEADER
*------------------------------------
*
*   Title:   JScript_PopupImage.js
*   Author:  Jonathan Hynds
*   Date:    26/04/2007
*   Project: www.seafishingni.co.uk
*
*------------------------------------
*          DESCRIPTION
*------------------------------------
*  Resizes the image window to the
*  appropriate size when an image is
*  loaded.  Will resize the window to
*  5px larger than the image
*-----------------------------------*/

function resizeWindow(image_url, image_id)
{
    //get the image
    var imageObj = new Image();
    imageObj.src = image_url;
    
    // resize image to under the max allowed
    if(imageObj.width > 800)
    {
        imageObj.height = imageObj.height * (800/imageObj.width);
        imageObj.width = 800;
        
        document.images[image_id].height = imageObj.height 
        document.images[image_id].width = imageObj.width;
    }
    
    
    //get the dimensions
    var img_width  = imageObj.width + 25;
    var img_height = imageObj.height + 120;
    
    //resize the window
    window.resizeTo(img_width,img_height);
  
}

function openCleanWindow(open_url,open_name)
{
    //open a window with no bars
    var newWindow = window.open("",open_name,"toolbar=0,menubar=0,resizable=1,scrollbars=0,location=0,status=0");
    
    //get the curren window coords
    var x = window.screenx;
    var y = window.screeny;
    
    //nav to page
    newWindow.window.location = open_url;
    newWindow.window.screenx = x;
    newWindow.window.screeny = y;
}

function clearLinks(linkId)
{
    //variables
    var i = 0;
    var linkObject = null;

    //debugger;
    //get initial link
    linkObject = document.getElementById(linkId + i);

    while(linkObject != null)
    {
        //set the href
        linkObject.href = "javascript:openCleanWindow('/common/imageviewer/imageviewer.php?id=" + linkObject.name + "','')";

        //inc counter
        i++;

        //get next link
        linkObject = document.getElementById(linkId + i);
    }
}

