/****************************************
    Website Coded by Gelo Factory LLC
           All Rights Reserved
           (c)  Copyright 2008
         http://gelofactory.com/
****************************************/

if (location.href.indexOf('localhost') != -1) {
    var _RLT_base_url = "http://localhost";
} else if (location.href.indexOf('72.47.248.33') != -1 || location.href.indexOf('rcrdlbldev.com') != -1) {
    var _RLT_base_url = "http://rcrdlbldev.com";
} else {
    var _RLT_base_url = "http://rcrdlbl.com";
}

_RLT = {
    swf_url: "/widgets/swf/single_track.swf",
    controller_swf_url: "/widgets/swf/single_track_controller.swf",
    dl_lock: false,
    dl_lock_to: 100,
    orig_h: 25,
    margin_bottom: 10,
    err_flag: false,
    err_load: "The RCRD LBL Single Track widget could not be loaded.",
    err_func: "The RCRD LBL Single Track widget encountered an error.",

    render: function(id, via_track_page) {
        var div_el = document.getElementById("rl_trk_"+id);
        via_track_page = (typeof(via_track_page) == "undefined") ? false : via_track_page;
        if (div_el) {
            div_el.innerHTML = "<p>Loading<span style='text-decoration: blink'>_</span></p>";
            var render_f = function() {
                div_el.style.height = _RLT.orig_h+"px";
                div_el.style.marginBottom = _RLT.margin_bottom+"px";
                var query_suf = "";
                if (via_track_page) query_suf += "&s=true";
                div_el.innerHTML =
                                '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="400" height="100%" id="rl_trk_swf_'+id+'" align="top">' +
                                '<param name="allowScriptAccess" value="always" />' +
                                '<param name="movie" value="'+_RLT_base_url+_RLT.swf_url+'?i='+id+query_suf+'" />' +
                                '<param name="quality" value="high" />' +
                                '<param name="bgcolor" value="#ffffff" />' +
                                '<embed src="'+_RLT_base_url+_RLT.swf_url+'?i='+id+query_suf+'" quality="high" bgcolor="#ffffff" width="400" height="100%" align="top" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />' +
                                '</object>';
/*
                if (!document.getElementById("rl_trk_cntrllr")) {
                    div_el.innerHTML +=
                                    '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="1" height="1" id="rl_trk_cntrllr" align="top">' +
                                    '<param name="allowScriptAccess" value="always" />' +
                                    '<param name="movie" value="'+_RLT_base_url+_RLT.controller_swf_url+'" />' +
                                    '<param name="quality" value="high" />' +
                                    '<param name="bgcolor" value="#ffffff" />' +
                                    '<param name="wmode" value="transparent" />' +
                                    '<embed src="'+_RLT_base_url+_RLT.controller_swf_url+'" quality="high" bgcolor="#ffffff" wmode="transparent" width="1" height="1" align="top" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />' +
                                    '</object>';
                }
*/
            };
            if (!via_track_page) {
                var old_onload = window.onload;
                if (typeof window.onload != 'function') {
                    window.onload = render_f;
                } else {
                    window.onload = function() {
                        if (old_onload) old_onload();
                        render_f();
                    };
                }
            } else {
                render_f();
            }
        } else {
            _RLT.failure(id);
        }
    },

    resize: function(id, h) {
        var div_el = document.getElementById("rl_trk_"+id);
        if (div_el) {
            div_el.style.height = (((typeof(h) != "undefined") && (parseInt(div_el.style.height, 10) < h)) ? h : _RLT.orig_h) + "px";
        } else {
            _RLT.failure(id);
        }
    },

    download: function(id, h, t) {
        _RLT.addDLForm(id);
        if (!_RLT.dl_lock) {
            var div_el = document.getElementById("rl_trk_"+id);
            if (div_el) {
                _RLT.dl_lock = true;
                setTimeout(function() { _RLT.dl_lock = false; }, _RLT.dl_lock_to);
                form_el = document.getElementById(div_el.id+"_dl");
                if (form_el) {
                    if (navigator.userAgent.toLowerCase().indexOf("msie") != -1) {
                        form_el.elements[0].value = h;
                        form_el.elements[1].value = t;
                    } else {
                        form_el.h.value = h;
                        form_el.t.value = t;
                    }
                    form_el.submit();
                } else {
                    _RLT.failure(id);
                }
            } else {
                _RLT.failure(id);
            }
        }        
    },

    addDLForm: function(id) {
        var form_el = document.getElementById("rl_trk_"+id+"_dl");
        if (!form_el) {
            var div_el = document.getElementById("rl_trk_"+id);
            if (div_el) {
                var f = document.createElement("form");
                var h = document.createElement("input");
                var t = document.createElement("input");
                f.setAttribute("action", _RLT_base_url+"/download.php");
                f.setAttribute("method", "POST");
                f.setAttribute("id", div_el.id+"_dl");
                h.setAttribute("type", "hidden");
                h.setAttribute("name", "h");
                h.setAttribute("value", "");
                f.appendChild(h);
                t.setAttribute("type", "hidden");
                t.setAttribute("name", "t");
                t.setAttribute("value", "");
                f.appendChild(t);
                div_el.appendChild(f);
            } else {
                _RLT.failure(id);
            }
        }
    },

    failure: function(id) {
        if (!_RLT.err_flag) {
            var div_el = document.getElementById("rl_trk_"+id);
            alert((div_el) ? _RLT.err_func : _RLT.err_load); 
            _RLT.err_flag = true;
        }
    }
};
