﻿var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
// Image Swapper Class //

Function.prototype.bind = function(object) {
var method = this
return function() {
        return method.apply(object, arguments) 
    }
}



function ImageSwapper(largeboxid,lowurl,highurl)
{
    this.LargeBoxId = largeboxid;
    this.LargeBox = document.getElementById( largeboxid );
    if( this.LargeBox == null ) return;
    this.List = Array();
    this.CurrentHigh = highurl;
    this.CurrentLow = lowurl;
    
    var lowPreload = new Image();
    lowPreload.src = lowurl;
    
    this.Preload ( lowurl );
    
}

ImageSwapper.prototype.Preload = function(url)
{
    var preloadImg = new Image();
    preloadImg.src = url;
    if( IE6 ) 
    {
        var im = document.createElement( "img" );
        im.src = url;
        im.style.width = "1px";
        im.style.height = "1px";
        im.style.visibility = "hidden";
    }
}

ImageSwapper.prototype.AddControl = function (id,lowurl,highurl)
{
    
    var newBox = document.getElementById( id );
    if( newBox == null ) return;
    var data = {
        id : id,
        img: newBox,
        low: lowurl,
        high : highurl
    }; 
    this.Preload( lowurl );
    this.Preload ( highurl );
    
    
    
    this.List.push( data );
    
    
    newBox.onclick = this.ImageClick.bind( { tag : newBox , eng : this  } );
}

ImageSwapper.prototype.DataById = function(id)
{
    for(k in this.List)
    {
        if( this.List[k].id == id ) return this.List[k];
    }
    return null;
}

ImageSwapper.prototype.ImageClick = function ()
{
     var img = this.tag;
     var eng = this.eng;
     
     var data = eng.DataById( img.id );
     var oldHigh = eng.CurrentHigh;
     var oldLow =  eng.CurrentLow;
     
     
     document.getElementById(eng.LargeBoxId).src = data.high ;
     eng.CurrentHigh =  data.high;
     eng.CurrentLow = data.low;
     
     data.high = oldHigh;
     data.low = oldLow;
     document.getElementById(data.id).src = oldLow;
     
 //    window.status = "High: "+eng.CurrentHigh;
}

