﻿// ProductDetail.js
// Author: Joseph Tan
// Date Created: 2006-10-11
// Purpose: handle the clicking of the Image Nav Controllers ...

// -----------------------------------------------------------------
// Scroll back and forth the product images
// direction is 1 or -1 
// -----------------------------------------------------------------
function on_navimage_click(product_id, direction)
{
    try 
    {    
        var pr_images        = eval('product_'+ product_id +'_images');
        var pr_image_count   = eval('product_'+ product_id +'_images_count');
        var pr_current_image = eval('product_'+ product_id +'_current_image');
        var pr_image_elem_id = 'current_product_'+product_id  + '_image';
        
        // img_elem is the image whos src needs to be swapped 
        var img_elem = document.getElementById(pr_image_elem_id);
        if ( img_elem )
        {
            pr_current_image += direction;
            if (pr_current_image < 0) 
            {
                pr_current_image += pr_image_count;
            }
            else if (pr_current_image >= pr_image_count)
            {
                pr_current_image = pr_current_image % pr_image_count;
            }
            // this is the statement that does it!
            img_elem.src = pr_images[pr_current_image];
        }
        eval ( 'product_'+ product_id +'_current_image = ' + pr_current_image + ';');
        pr_current_image = eval('product_'+ product_id +'_current_image');
    }
    
    catch (err)
    {
        if (err.description)
            alert ('on_navimage_click error:' + err.description);
        else
            alert ('on_navimage_click error:' + err.message);
    }    
    return false; 
}

var fiv_img;
var fiv_url;

 
function full_image_view () 
{
    if (fiv_img.complete)
    {
        var w  = fiv_img.width +10;
        var h  = fiv_img.height +10;
        var win = window.open( fiv_url, 'PRODUCTBLOWUP', 'menubar=no,scrollbars=no,resizable=yes,location=no,toolbar=no,width='+w+',height='+h, true ) ;
        win.focus();
    }
    else
    {
        setTimeout('full_image_view ()', 500);
    }
}
// -----------------------------------------------------------------
// Open a new window with the largest possible size to see the image 
// -----------------------------------------------------------------
function open_full_image(product_id)
{
    try 
    {    
        var pr_images        = eval('product_'+ product_id +'_images');
        var pr_current_image = eval('product_'+ product_id +'_current_image');
        var url =  pr_images[pr_current_image];
        fiv_url = url.replace (/IW=\d+/,'IW='+screen.width);
        fiv_img = new Image();
        fiv_img.src = fiv_url;
        full_image_view ();
    }
    
    catch (err)
    {
        if (err.description)
            alert ('open_full_image error:' + err.description);
        else
            alert ('open_full_image error:' + err.message);
    }    
    return false; 
}