﻿/* LazyLoad Javascript File*/

//  
//  This script is to accompany the LazyLoadSingleImageAsset or the Image Asset Control
//  
//  Description: This script handles loading the images after the page has loaded.
//
//  Required Params:
//      e: event args
//      imageurl: the actual url of the final image to be loaded
//      width: the width of the final image to be loaded
//      height: the height of the image to be loaded
//
//

function LazyLoadImage(e, imageurl, height, width) {

    if ($.browser.msie)
        var image = e.srcElement;
    else
        var image = e.currentTarget;

    $(image).after('<img id="lazyLoadSpinner" class="lazyloadSpinner" src="/_different/i/loading.gif" />');

    // remove the inital onload event
    $(image).removeAttr("onload");
    $(image).attr("height");
    
    // add the new onload animation
    $(image).load(function() {

        if ($(image).hasClass("lazyloading")) {
            
            $(image).removeClass("lazyloading");
            $(image).attr("style", "display:none");

            $(image).removeAttr("style");
            $(image).fadeIn(200);
            
        }
    });

    $(image).removeAttr("src");
    $(image).attr("src", imageurl);
    
}












//function LazyLoadImage(e, imageurl, height, width) {

//    if ($.browser.msie)
//        var image = e.srcElement;
//    else
//        var image = e.currentTarget;

//    $(image).after('<img id="lazyLoadSpinner" class="lazyloadSpinner" src="/_different/i/loading.gif" />');

//    // remove the inital onload event
//    $(image).removeAttr("onload");

//    //$(image).attr("style", "display:none");

//    // add the new onload animation
//    $(image).load(function() {

//        if ($(image).attr("complete") != null) {

//            $(image).removeAttr("style");

//            if ($(image).hasClass("lazyloading")) {
//                $(image).removeClass("lazyloading");
//            }
//        }
//    });

//    // load the new image
//    $(image).attr("src", imageurl);
//    $(image).ready(function() {

//        //$("#lazyLoadSpinner").remove();

//        //        if(width > 700)
//        //            $("#fancy_content .lazyloadSpinner").attr("style", "height:0em"); 
//        //        else
//        //            $("#fancy_content .lazyloadSpinner").attr("style", "height:0em"); 

//    });
//}

