SiteDotImage = 'images/dot.gif';

Zoom.OuterID = 'realZOOMOuter';
Zoom.FloaterID = 'realZOOMFloater';
Zoom.HighlightID = 'realZOOMHighlight';

Zoom.DefPositionFloaterID = 'Content';

Zoom.DefViewPortWid = 270;
Zoom.DefViewPortHei = 258;

var OurZoomIndex, OurZoomImage;

var origWidth = 300;
var origHeight = 300;
var floorSize = 1.0;
var ceilingSize = 2.0;

var imageX = 0;
var imageY = 0;
var imageV = 1;

var selects = document.getElementsByTagName('select');

var showFull = false;
var image = false;

OurZoomIndex = Zoom_AllocateZoomImages(1);

function SetupZoomImage( zoom_image_url )
{
    zoom_image_url = (typeof zoom_image_url == 'undefined') ? '' : zoom_image_url;
    
    if ( OurZoomIndex != -1 )
    {
        OurZoomImage = ZoomImages[OurZoomIndex];
        
        OurZoomImage.MainImageID = 'products_image';
        OurZoomImage.MainImageWid = 270;
        OurZoomImage.MainImageHei = 270;
        
        OurZoomImage.ZoomImageURL = zoom_image_url;
        
        OurZoomImage.ZoomImageWid = 1080;
        OurZoomImage.ZoomImageHei = 1080;
        
        Zoom_InitializeImage(OurZoomIndex);
    }
}

function ChangeZoomImage(path,image_main,image_large)
{
    var path_main = '';
    var path_large = '';
    
    if(image_main!='') path_main = path + image_main;
    if(image_large!='') path_large = path + image_large;
    
    Zoom_ChangeImage(OurZoomIndex, path_main, 270,270,path_large,1080,1080);
}

function switchMainImage(path,main_image,large_image)
{
    ChangeZoomImage(path,main_image,large_image);
}

function ChangeProductImage(path, new_image, new_image_large, option_values_id, colorName)
{
    if (new_image != '') //change image
    {
        ChangeZoomImage(path,new_image,new_image_large);
    }
    
    var selects = document.getElementsByTagName('select');
    var color_select = document.getElementById( 'color_select' );
    
    for( i = 0; i < color_select.options.length; i++)
    {
        if (color_select.options[i].value == option_values_id)
        {
            color_select.options[i].selected = 'selected';
        }
    }
    
    //change price
    var price = $('product_price').value;
    
    if (option_values_id != '')
    {
        var addprice = $('color_price'+option_values_id).value;
    } else
    {
        var addprice = 0.00;
    }
    
    var newprice = parseFloat(price) + parseFloat(addprice);
    
    $('product_price_visible').textContent = '$' + newprice.toFixed(2);
    
    //color-name
    $('color-name').textContent = colorName;
}

function scaleIt(v)
{
    if (!image)
    {
        image = new Draggable('products_image', {starteffect:false, reverteffect:false, endeffect:false, snap:containIt});
    }
    
    var centerX = (origWidth*(1-imageV)/2-imageX)/imageV;
    var centerY = (origHeight*(1-imageV)/2-imageY)/imageV;

    imageV = floorSize+(v*(ceilingSize-floorSize));

    image.element.style.width = (imageV*origWidth)+'px';
    image.element.style.height = (imageV*origWidth)+'px';

    imageX = origWidth*(1-imageV)/2-centerX*imageV;
    imageY = origHeight*(1-imageV)/2-centerY*imageV;
    
    containIt(imageX, imageY, image);

    image.element.style.left = imageX+'px';
    image.element.style.top = imageY+'px';
}

function containIt(x,y,draggable)
{
    var pDim = Element.getDimensions(draggable.element.parentNode);
    var eDim = Element.getDimensions(draggable.element);
    
    var xMin = 0, xMax = pDim.width-eDim.width;
    var yMin = 0, yMax = pDim.height-eDim.height;
    
    x = x>xMin ? xMin : x;
    x = x<xMax ? xMax : x;
    y = y>yMin ? yMin : y;
    y = y<yMax ? yMax : y;
    
    //y = yMin;
    imageX = x;
    imageY = y;
    
    return [x,y];
}

function CheckChooseColor()
{
    if ( document.getElementById( 'color_select' ) )
    {
        if ( true == document.getElementById( 'color_select' ).options[0].selected )
        {
            alert('Please choose a color');
            return false;
        }
    }
    
    return true;
}