//========================================================================================
// Define global variables
//========================================================================================

var win = window;
var doc = document;
var frm, o, overlay, po2, po3, po4;

//========================================================================================
// Add external files
//========================================================================================

doc.writeln('<link rel="stylesheet" type="text/css" href="http://www.offordandsons.co.uk/includes/oas.css">');
doc.writeln('<script type="text/java'+'script" src="http://www.offordandsons.co.uk/includes/jquery.bgiframe.min.js"></script>');
doc.writeln('<script type="text/java'+'script" src="http://www.offordandsons.co.uk/includes/excanvas.js"></script>');
doc.writeln('<script type="text/java'+'script" src="http://www.offordandsons.co.uk/includes/jquery.corner.js"></script>'); 
doc.writeln('<script type="text/java'+'script" src="http://www.offordandsons.co.uk/includes/jquery.browser.min.js"></script>');
doc.writeln('<script type="text/java'+'script" src="http://www.offordandsons.co.uk/includes/jquery.flash.js"></script>');

//========================================================================================
// Add new jQuery functions
//========================================================================================

//Preload images
function preloadImages() { 
    $.each(br, function(i, v){
        if (v != undefined) {
            //$('<img/>')[0].src = basePath+"images/"+v.image;
            pic = new Image(); 
            pic.src = basePath+"images/"+v.image;
        }                                          
    });
}               

//========================================================================================
// DOM loaded
//========================================================================================

function bannerRotate() {

    n = Math.round(Math.random()*(brCount));
    if (n == 0) {n = 1;}
    if (n > brCount) {n = brCount;}
    
    if (br[n].url) { 
        $("#bannerrotate").fadeOut("slow", function() {
            if (br[n].url.indexOf("www") > -1) {
                $("#bannerrotate").html("<p class=\"title\">"+Base64.decode(br[n].title)+"</p><p class=\"description\">"+Base64.decode(br[n].description)+"</p><a href=\""+br[n].url+"\" target=\"_new\"><img src=\"images/"+br[n].image+"\" alt=\""+br[n].image+"\"></a>");
            } else {
                $("#bannerrotate").html("<p class=\"title\">"+Base64.decode(br[n].title)+"</p><p class=\"description\">"+Base64.decode(br[n].description)+"</p><img src=\"images/"+br[n].image+"\" alt=\""+br[n].image+"\" onclick=\"o.fbt('"+br[n].url+"');\" style=\"cursor:pointer;\">");
            }
            $("#bannerrotate").fadeIn("slow");  
        });
    }                      
    setTimeout("bannerRotate()", 8000);  
}

$(doc).ready(function() {
            
    //Get form
    frm =  doc.frmMain;
    
    //Disable right click
    $(document)[0].oncontextmenu = function() {return false;}
    
    if (showBanner == "1") {setTimeout("bannerRotate()", 0);}
    
    //Hover over search button
    $("#btnsearch").hover(
        function(){$(this).css("background-image", "url(images/btnsearchover.jpg)")},
        function(){$(this).css("background-image", "none")}).click(
        function(){$("form#gosearch").submit();});
        
    $("input[name=search]").bind("keypress", function(event) {
        var code=event.charCode || event.keyCode;
        if (code==13) {$("form#gosearch").submit();}
    }).focus(function(event){
        if ($(this).val() == searchDefault) {
            $(this).val("");
        }
     }).blur(function(event){
        if ($(this).val() == "") {
            $(this).val(searchDefault);
        }
     });

    //Apply click event to product family listing
    /*$(".prodfamily").click(function(){
        $("#family").val($(this).attr("id"));
        $("form#fbt").submit();
    });*/
    
    //Animate product sub-menu
    $("#submenu .brand").click(function() {
        if ($(this).hasClass("alink")) {return true;}
        $("#submenu li.current").removeClass("current").children().slideToggle();
        $(this).addClass("current").children().slideToggle(); 
    });
    
    $(".expand").click(function(){
        $(".expcol").addClass("current").children().slideDown();
    });
    
    $(".collapse").click(function(){
        $(".expcol").removeClass("current").children().slideUp();
    });
    
    //Apply click event to product info button
    $(".info").click(function(){
        o.getInfo($(this).parent().parent().attr("id"));        
    });

    //Apply click event to product add to cart button
    $(".atc").click(function(event){
        v = $(this).parent().parent().attr("id").split("~");
        if (v[2] == "0" || v[2] == "POA" || v[2] == "SOLD" || v[2] == "") {
            alert("Sorry, but this item cannot be added to your cart.\n\nPlease call us on 01962 867772 for further information.");
            return false;
        }
        if (v[1] == "1") {
            o.addToCart(v[0], false);
        } else if (v[1] == "2") {
            if ($.browser.name == "msie" && $.browser.version < 7) {
                overlay.showMain(340, 270, "hidden");
            } else {
                overlay.showMain(340, 270, "auto");
            }
            o.doAjax("po2", "&id="+v[0], overlay.objBody, "", "", false);
        } else if (v[1] == "3") {
            if ($.browser.name == "msie" && $.browser.version < 7) {
                overlay.showMain(600, 270, "hidden");
            } else {
                overlay.showMain(600, 270, "auto");
            }
            o.doAjax("po3", "&id="+v[0]+"&price="+v[2], overlay.objBody, "", "", false);
        } else if (v[1] == "4") {
            if ($.browser.name == "msie" && $.browser.version < 7) {
                overlay.showMain(700, 270, "hidden");
            } else {
                overlay.showMain(700, 270, "auto");
            }
            o.doAjax("po4", "&id="+v[0]+"&price="+v[2], overlay.objBody, "", "", false);
        }
    });
       
    //Apply click event to close image
    $("#overlay, #overlayclose").click(function(){
        overlay.hideAll(true);
    });
                 
    //$(window).scroll(function () {
    //    if (overlay.objOverlay == null || overlay.keepCenter == false) {return true;}
    //    overlay.showMain(null, null); 
    //});

    
    $("#btnPaypal").click(function(){
        $("form#frm_paypal_checkout").submit();
    });
    
}); 

//========================================================================================
// Common object literal
//========================================================================================

o = {

    doSearch : function(term) {
       $("input[name=search]").val(Base64.decode(term));
       $("form#gosearch").submit();
    },

    //Launch page with random number in URL to stop page caching
    goPage : function(url) {
        var rnd = new Date();
        window.location.href = url; //+"?"+Base64.encode("rnd="+rnd.getTime());
    },
    
    //Save family, brand, type to fields ready for form posting
    fbt : function(fbt) {   
        $("#family").val("");
        $("#brand").val("");
        $("#type").val("");
        fbt = fbt.split("~");
        $("#family").val(fbt[0]);
        $("#brand").val(fbt[1]);
        $("#type").val(fbt[2]);
        $("form#fbt").submit();
    },
    
    //Show popup of product information
    getInfo : function(id) {
        overlay.showMain(840, 600, "auto");
        this.doAjax("sp", "&id="+id.split("~")[0], overlay.objBody, "", "", false); 
    },
    
    //Empty cart
    emptyCart : function(showcart) {
        if (confirm("Are you sure you wish to empty your shopping cart?")) {
            //this.doAjax("et", "", "#viewcart", "", "", false);
            this.doAjax("et", "", ".padderlr", "", "", false);                       
        }
    },
    
    //View cart
    viewCart : function() {
        //overlay.showMain(850, 0);
        //this.doAjax("vc", "", overlay.objBody, "", "", false);
        o.goPage("/cart.php");
    },
    
    //View cart. Shows nicely in status bar using this function name
    checkoutCart : function() {
        this.viewCart();
    },
    
    //Update tiny cart
    showTinyCart : function() {
        this.doAjax("stc", "", "#viewcart", "", "", false); 
    },
    
    //Add product to cart
    addToCart : function(id, closeOverlay) {
        this.doAjax("atc", "&family="+$("#family").val()+"&brand="+$("#brand").val()+"&type="+$("#type").val()+"&id="+id, "#viewcart", "Item added to cart.", "Sorry, but the item could not be added to your cart.", closeOverlay);  
    },
    
    //Increment item in cart
    plusCart : function(id, extra) {
        //this.doAjax("ic", "&id="+id+"&extra="+extra, overlay.objBody, "", "", false);
        this.doAjax("ic", "&id="+id+"&extra="+extra, ".padderlr", "", "", false);
    },

    //Decrement item in cart
    minusCart : function(id, extra) {
        //this.doAjax("dc", "&id="+id+"&extra="+extra, overlay.objBody, "", "", false);
        this.doAjax("dc", "&id="+id+"&extra="+extra, ".padderlr", "", "", false); 
    },

    //Show product selected from cart
    showProduct : function(id) {
        $("input[name='search']").val(Base64.decode(id));
        $("form#gosearch").submit(); 
    },
    
    //Perform ajax call and place result where required
    doAjax : function(action, param, destination, msgSuccess, msgFailure, closeoverlay) {
        $.ajax({url: basePath+"/includes/ajax.php?action="+action+param,
            cache: false,
            success: function(s){
            //alert(destination + " : " + s);
                $(destination).html(s);
                if (action == "et" || action == "ic" || action == "dc") {
                    //o.showTinyCart();
					var rnd = new Date();
					window.location.href = "cart.php?"+Base64.encode("rnd="+rnd.getTime());
                }
                if (msgSuccess != "") {alert(msgSuccess);}
                if (closeoverlay) {overlay.hideAll(true);}
            },
            error: function(s){
                $(destination).html("error");
                if (msgFailure != "") {alert(msgFailure);}     
            }
        });
    },
    
    infoatc : function(v) {
        v = v.split("~");
        if (v[2] == "0" || v[2] == "POA" || v[2] == "SOLD") {
            alert(cannotAddToCart.replace(/{%nl%}/g, "\n"));
            return false;
        }
        
        if (v[1] == "1") {
            o.addToCart(v[0], true);
        } else if (v[1] == "2") {
            overlay.hideAll(true);
            if ($.browser.name == "msie" && $.browser.version < 7) {
                overlay.showMain(340, 260, "hidden");
            } else {
                overlay.showMain(340, 260, "auto");
            }
            o.doAjax("po2", "&id="+v[0], overlay.objBody, "", "", false);
        } else if (v[1] == "3") {
            overlay.hideAll(true);
            if ($.browser.name == "msie" && $.browser.version < 7) {
                overlay.showMain(700, 260, "hidden");
            } else {
                overlay.showMain(700, 260, "auto");
            }
            o.doAjax("po3", "&id="+v[0]+"&price="+v[2], overlay.objBody, "", "", false);
        } else if (v[1] == "4") {
            overlay.hideAll(true);
            if ($.browser.name == "msie" && $.browser.version < 7) {
                overlay.showMain(700, 260, "hidden");
            } else {
                overlay.showMain(700, 260, "auto");
            }
            o.doAjax("po4", "&id="+v[0]+"&price="+v[2], overlay.objBody, "", "", false);
        }
    }

}

po2 = {

    //Get price for price option 2 products
    getPrice : function() {
        v = $("#sizes").val().split("~");
        if (v[2] == "" || v[2] == undefined) {
            $("#price").html("");
        } else {
            $("#price").html("&pound;"+v[2]);
        }
    },
    
    //Add price option 2 to cart
    addToCart : function() {
        v = $("#sizes").val().split("~");
        if (v[2] == undefined) {
            alert("Please select the size you wish to purchase.");
        } else {
            o.doAjax("atcpo2", "&family="+$("#family").val()+"&brand="+$("#brand").val()+"&type="+$("#type").val()+"&id="+v[0]+"&extra="+v[1]+"&price="+v[2], "#viewcart", "Item added to cart.", "Sorry, but the item could not be added to your cart.", true); 
        }
    }

}

po3 = {

    family : "",
    brand : "",
    type : "",
    metal : "",
    profile : "",
    weight : "",
    width : "",
    size : "",
    diamond : "",
    price : "",
    
    //Get details for price option 3
    getExtra : function(id) {
        this.metal = $("#metal").val();
        this.profile = $("#profile").html();
        this.weight = $("#weight").val();
        this.width = $("#width").val();
        this.size = $("#size").val();
        this.diamond = $("#diamond").val();
        this.price = $("#price").html();
        this.family = $("#family").val();
        this.brand = $("#brand").val();
        this.type = $("#type").val();
    },
    
    //Get price for price option 3 products
    getPrice : function(id) {
        this.getExtra();  
        o.doAjax("pricepo3", "&family="+this.family+"&brand="+this.brand+"&type="+this.type+"&metal="+this.metal+"&id="+id+"&weight="+this.weight+"&width="+this.width+"&size="+this.size+"&diamond="+this.diamond, "#price", "", "", false); 
        this.getExtra();
    },
 
    //Add price option 3 to cart
    addToCart : function(id) {
        
        this.getExtra();
        
        s = this.metal+", profile "+this.profile+", "+this.weight+", "+this.width+"mm wide, size "+this.size;
        if (this.diamond == undefined) {
        } else {
            s += ", "+this.diamond+" diamonds";  
        }     
        s = Base64.encode(s)+"&metal="+this.metal+"&profile="+this.profile+"&weight="+this.weight+"&width="+this.width+"&size="+this.size+"&diamond="+this.diamond+"&price="+this.price;   

        if (this.price == "POA" || this.price == "SOLD") {
            alert(cannotAddToCart.replace(/{%nl%}/g, "\n"));
        } else {
            o.doAjax("atcpo3", "&family="+this.family+"&brand="+this.brand+"&type="+this.type+"&metal="+this.metal+"&id="+id+"&extra="+s, "#viewcart", "Item added to cart.", "Sorry, but the item could not be added to your cart.", true); 
        }
    }
}

po4 = {

    family : "",
    brand : "",
    type : "",
    metal : "",
    size : "",
    carat : "",
    colour : "",
    clarity : "",
    price : "",
    
    //Get details for price option 4
    getExtra : function(id) {
        this.metal = $("#metal").val();
        this.size = $("#size").val(); 
        this.carat = $("#carat").val(); 
        this.colour = $("#colour").val(); 
        this.clarity = $("#clarity").val(); 
        this.family = $("#family").val();
        this.brand = $("#brand").val();
        this.type = $("#type").val();
        this.price = $("#price").html();
    },
    
    //Get price for price option 4 products
    getPrice : function(id) {
        this.getExtra();
        o.doAjax("pricepo4", "&id="+id+"&metal="+this.metal+"&carat="+this.carat+"&colour="+this.colour+"&clarity="+this.clarity, "#price", "", "", false); 
    },
    
    //Add price option 4 to cart
    addToCart : function(id) {
        this.getExtra();
        s = this.metal+",  "+this.carat.split("ct")[0]+"ct, "+this.colour+", "+this.clarity+", size "+this.size;     
        s = Base64.encode(s)+"&metal="+this.metal+"&profile="+this.profile+"&weight="+this.weight+"&width="+this.width+"&size="+this.size+"&diamond="+this.diamond+"&price="+this.price;   
        if (this.price == "0" || this.price == "POA" || this.price == "SOLD") {
            alert(cannotAddToCart.replace(/{%nl%}/g, "\n"));
        } else {
            o.doAjax("atcpo4", "&family="+this.family+"&brand="+this.brand+"&type="+this.type+"&metal="+this.metal+"&id="+id+"&extra="+s, "#viewcart", "Item added to cart.", "Sorry, but the item could not be added to your cart.", true); 
        }
    }
    
}

overlay = {

    //Define public properties
    objOverlay : null,
    objPopup : null,
    objClose : null,
    objContent : null,
    objBody : null,
    pw : 0,
    ph : 0,
    keepCenter : true,

    //Show main overlay
    showMain : function(pw, ph, ovf) {
        if (pw != null) {
            this.pw = pw;
            this.ph = ph;
        } else {
            pw = this.pw;
            ph = this.ph;
        }
                
        //Create main overlay
        objOverlay = $("#overlay");
        ww = $(win).width();
        wh = $(win).height();
        
        //Make sure we fit into the users window
        if (ph > wh) {
            //ph = (wh - 80);
            this.keepCenter = false;
        }
        
        dh = $(doc).height();
        st = $(win).scrollTop(); 
        //st = 0;
        objOverlay.css("width", ww+"px").css("height", dh+"px");
                
        //Create overlay popup
        objPopup = $("#overlayPopup");                 
        pl = ((ww/2)-(pw/2));
        pt = st + ((wh/2)-(ph/2)); 
        if (pt < 0) {pt=20;}
        objPopup.css("width", pw+"px").css("height", ph+"px").css("top", pt+"px").css("left", pl+"px");
        
        //Position close button
        objClose = $("#overlayclose");
        iw = 23;
        ih = 23;
        objClose.css("top", (pt-(iw/2))+"px").css("left", ((pl+pw)-(ih/2))+"px"); 
        
        //Create overlay content area
        b = 10*2;
        objContent = $("#overlayMain");
        objContent.css("overflow", ovf);
        cl = ((ww/2)-((pw-b)/2));
        ct = st + ((wh/2)-((ph-b)/2));
        if (ct < 0) {ct=20;}   
        objContent.css("width", (pw-b)+"px").css("height", (ph-b)+"px").css("top", ct+"px").css("left", cl+"px");
        
        //Remember this elements
        this.objOverlay = objOverlay;
        this.objPopup = objPopup;
        this.objClose = objClose;
        this.objContent = objContent;
        this.objBody = objContent.find("div"); 
         
        //Show everything
        //if (objOverlay.is(':hidden')) {
            objOverlay.show();
            objPopup.show();
            objClose.show();
            objContent.show();
        //}
    },
    
    //Hide main overlay
    hideAll : function(clear) {
    
        o.showTinyCart();
        
        //Hide elements
        this.objOverlay.hide();
        this.objPopup.hide();
        this.objClose.hide();
        this.objContent.hide();
        
        //Reset pointers
        this.objOverlay = null;
        this.objPopup = null;
        this.objClose = null;
        this.objContent = null;
        if (clear) {
            this.objBody.html("<img src=\""+basePath+"images/busy.gif\">");
        }
    }
    
}

//========================================================================================
// Base 64 encoding and decoding
//========================================================================================

/* BASE64 */
var Base64 = {
 
    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
 
    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;
 
        input = Base64._utf8_encode(input);
 
        while (i < input.length) {
 
            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);
 
            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;
 
            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }
 
            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
 
        }
 
        return output;
    },
 
    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;
 
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
        while (i < input.length) {
 
            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));
 
            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;
 
            output = output + String.fromCharCode(chr1);
 
            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }
 
        }
 
        output = Base64._utf8_decode(output);
 
        return output;
 
    },
 
    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";
 
        for (var n = 0; n < string.length; n++) {
 
            var c = string.charCodeAt(n);
 
            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }
 
        }
 
        return utftext;
    },
 
    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;
 
        while ( i < utftext.length ) {
 
            c = utftext.charCodeAt(i);
 
            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }
 
        }
 
        return string;
    }
}

objTooltip = {

    showTip : function(jobj, obj) {
        var id = jobj.parent().attr("id");
        var clickElementx;
        //var o = eval("objCustom.tooltip.fld."+id);
        //if (typeof(o) != "object"){return;}
        //ovalTipipTitle = o.title; //eval("objCustom.tooltip.fld."+id".title");
        //ovalTipipBody = o.body; //eval("objCustom.tooltip.fld."+id".body");
        //ovalTipipWidth = o.width; //eval("objCustom.tooltip.fld."+id".width");
        ovalTipipTitle = "Help"
        ovalTipipBody = "Body"
        ovalTipipWidth = 350;
        
        var de = document.documentElement;
        var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
        var hasArea = w - this.getAbsoluteLeft(obj);
        var clickElementy = this.getAbsoluteTop(obj) - 3; //set y position

        if(hasArea>((ovalTipipWidth*1)+75)){
            //$("body").append("<div id='ovalTip' style='width:"+ovalTipipWidth*1+"px'><div id='ovalTip_arrow_left'></div><div id='ovalTip_close_left'>"+ovalTipipTitle+"</div><div id='ovalTip_copy'><div class='ovalTip_loader'><div></div></div>");//right side
            $("body").append("<div id='ovalTip' style='width:"+ovalTipipWidth*1+"px'><div id='ovalTip_arrow_left'></div><div id='help'><div class='ovalTip_loader'><div></div></div>");//right side
            var arrowOffset = this.getElementWidth(obj) + 11;
            clickElementx = this.getAbsoluteLeft(obj) + arrowOffset; //set x position
        }else{
            //$("body").append("<div id='ovalTip' style='width:"+ovalTipipWidth*1+"px'><div id='ovalTip_arrow_right' style='left:"+((ovalTipipWidth*1)+1)+"px'></div><div id='ovalTip_close_right'>"+ovalTipipTitle+"</div><div id='ovalTip_copy'><div class='ovalTip_loader'><div></div></div>");//left side
            $("body").append("<div id='ovalTip' style='width:"+ovalTipipWidth*1+"px'><div id='ovalTip_arrow_right' style='left:"+((ovalTipipWidth*1)+1)+"px'></div><div id='help'><div class='ovalTip_loader'><div></div></div>");//right side
            clickElementx = this.getAbsoluteLeft(obj) - ((ovalTipipWidth*1) + 15); //set x position
        }

            
        if ($.browser.name == "msie" && $.browser.version < 7) {
            $('#ovalTip').bgiframe();
        }
        $('#ovalTip').css({left: clickElementx+"px", top: clickElementy+"px"});
        $('#ovalTip').show();
        //$('#ovalTip_copy').html(ovalTipipBody);
        o.doAjax("help", "&id="+ Base64.encode(id), "#help", "", "", false);
    },

    getElementWidth : function(o) {return o.offsetWidth;},
        getAbsoluteLeft : function(obj) {
        oLeft = obj.offsetLeft;                // Get left position from the parent object
        while(obj.offsetParent !== null) {    // Parse the parent hierarchy up to the document element
            oParent = obj.offsetParent;    // Get parent object reference
            oLeft += oParent.offsetLeft;    // Add parent left position
            obj = oParent;
        }
        return oLeft;
    },

    getAbsoluteTop : function(o) {
        oTop = o.offsetTop;                    // Get top position from the parent object
        while(o.offsetParent !== null) {        // Parse the parent hierarchy up to the document element
            oParent = o.offsetParent;        // Get parent object reference
            oTop += oParent.offsetTop;        // Add parent top position
            o = oParent;
        }
        return oTop;
    }

};
