var zIndex = 0;
var pScale = .84;

var floatedImgs=[];

function initZoom () {
    var zoomedImg = null;
    var focusedImg = null;

    $(".column-item").one("mouseover", function() {
        focusedImg = $(this).find('a').stop(); 
        
        zoomedImg = zoomIn(focusedImg);
        //floatedImgs.push(zoomedImg);
        
    });
    
}

function zoomIn(focusedImg){
    
    resetZoom();
    
    $(focusedImg).unbind();
    //$(focusedImg).addClass('hover zoom', 200);
    
    var floatImg = $(focusedImg).clone();
    
    var pos = $(focusedImg).find('.slider-data').offset();

    var oWidth = $(focusedImg).find('img').width();
    var oHeight = $(focusedImg).find('img').height();
    
    floatedImgs.push({
        floatImg:floatImg,
        focusedImg: focusedImg,
        oWidth: oWidth,
        oHeight: oHeight
    });
    
    var aWidth = oWidth / pScale;
    var aHeight = oHeight / pScale;
    var aLeft = -1 * ((pos.left * .99) - pos.left);
    var aTop = -1 * ((pos.top * .99) - pos.top);
    
    $(focusedImg).hide();

    $(floatImg).find('.slider-data').css('position', 'absolute');
    $(floatImg).find('.slider-data').css('top', pos.top);
    $(floatImg).find('.slider-data').css('left', pos.left);
    $(floatImg).find('.slider-data').css('z-index', ++zIndex);
    
    //$(floatImg).addClass('hover zoom', 200);

    var url = $(focusedImg).parent().find('a').attr('href');    
    $(floatImg).click(function(){document.location = url;});
    
    $(floatImg).mouseout(function(){ zoomOut(floatImg, focusedImg, oWidth, oHeight); });
    
    $('body').append(floatImg);
    $(floatImg).addClass('hover zoom');
    return floatImg;
}

function zoomOut(floatImg, focusedImg, oWidth, oHeight){
    
    floatedImgs.pop();
    
    $(floatImg).stop(); 
    var pos = $(focusedImg).offset();
    
    $(floatImg).find('img').animate({
            width: oWidth,
            height: oHeight,
            marginTop: 0,
            marginLeft: 0
        }, 
        400, 
        function(){ $(floatImg).remove();
                $(focusedImg).addClass('orig');
                $(focusedImg).removeClass('hover zoom');
                $(focusedImg).show();
                $(focusedImg).mouseover(function(){ zoomIn(focusedImg); });
        });
}

function resetZoom(){
    for (var i=0; i < floatedImgs.length; i++) {
        if (floatedImgs[i] != null){
                zoomOut( floatedImgs[i].floatImg, 
                    floatedImgs[i].focusedImg,
                    floatedImgs[i].oWidth,
                    floatedImgs[i].oHeight );
                floatedImgs[i]=null;
        }
        
    };
}

function unbindZoom() {
    $(".column-item").unbind();
    $(".orig").unbind();
}

/* easySlider1.5.js (with a hacked in callback)*/    
(function(a){a.fn.easySlider=function(b){var c={prevId:"prevBtn",prevText:"Previous",nextId:"nextBtn",nextText:"Next",controlsShow:true,controlsBefore:"",controlsAfter:"",controlsFade:true,firstId:"firstBtn",firstText:"First",firstShow:false,lastId:"lastBtn",lastText:"Last",lastShow:false,vertical:false,speed:800,auto:false,pause:2e3,continuous:false,beforeTransition:function(){},afterTransition:function(){}};var b=a.extend(c,b);this.each(function(){function d(f,k){var m=j;switch(f){case"next":j=m>=i?b.continuous?0:i:j+1;break;case"prev":j=j<=0?b.continuous?i:0:j-1;break;case"first":j=0;break;case"last":j=i;break;default:break}var n=Math.abs(m-j);var o=n*b.speed;c.beforeTransition();if(!b.vertical){p=j*g*-1;a("ul",e).animate({marginLeft:p},{delay:o,complete:function(){c.afterTransition()}})}else{p=j*h*-1;a("ul",e).animate({marginTop:p},{delay:o,complete:function(){c.afterTransition()}})}if(!b.continuous&&b.controlsFade){if(j==i){a("a","#"+b.nextId).hide();a("a","#"+b.lastId).hide()}else{a("a","#"+b.nextId).show();a("a","#"+b.lastId).show()}if(j==0){a("a","#"+b.prevId).hide();a("a","#"+b.firstId).hide()}else{a("a","#"+b.prevId).show();a("a","#"+b.firstId).show()}}if(k){clearTimeout(l)}if(b.auto&&f=="next"&&!k){l=setTimeout(function(){d("next",false)},n*b.speed+b.pause)}}var e=a(this);var f=a("li",e).length;var g=a("li",e).width();var h=a("li",e).height();e.width(g);e.height(h);e.css("overflow","hidden");var i=f-1;var j=0;a("ul",e).css("width",f*g);if(!b.vertical){a("li",e).css("float","left")}if(b.controlsShow){var k=b.controlsBefore;if(b.firstShow){k+='<span id="'+b.firstId+'"><a href="javascript:void(0);">'+b.firstText+"</a></span>"}k+=' <span id="'+b.prevId+'"><a href="javascript:void(0);">'+b.prevText+"</a></span>";k+=' <span id="'+b.nextId+'"><a href="javascript:void(0);">'+b.nextText+"</a></span>";if(b.lastShow){k+=' <span id="'+b.lastId+'"><a href="javascript:void(0);">'+b.lastText+"</a></span>"}k+=b.controlsAfter;a(e).after(k)}a("a","#"+b.nextId).click(function(){d("next",true)});a("a","#"+b.prevId).click(function(){d("prev",true)});a("a","#"+b.firstId).click(function(){d("first",true)});a("a","#"+b.lastId).click(function(){d("last",true)});var l;if(b.auto){l=setTimeout(function(){d("next",false)},b.pause)}if(!b.continuous&&b.controlsFade){a("a","#"+b.prevId).hide();a("a","#"+b.firstId).hide()}})}})(jQuery)
