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

if (location.href.indexOf('localhost') != -1) {
  var _RLtrk_baseURL = "http://rcrdlbl.com/";
  var _RLT_base_url  = "http://rcrdlbl.com"
  var _RLtrk_S3URL   = "http://localhost:4400/widgets/swf/";
  var _RLtrk_GA_id   = "UA-13147878-1";
} else if ((location.href.indexOf('rcrdlbldev.com') != -1) || (location.href.indexOf('72.47.248.33') != -1)) {
  var _RLtrk_baseURL = "http://rcrdlbldev.com/";
  var _RLT_base_url  = "http://rcrdlbldev.com"
  var _RLtrk_S3URL   = "http://rcrdlbldev.com/widgets/swf/";
  var _RLtrk_GA_id   = "UA-2739978-4";
  var isTrackerEnabled = true;
} else {
  var _RLtrk_baseURL = "http://rcrdlbl.com/";
  var _RLtrk_S3URL   = "http://rcrdlbl_trk.s3.amazonaws.com/";
  var _RLT_base_url  = "http://rcrdlbl.com";
  var _RLtrk_GA_id   = "UA-2739978-2";
  var isTrackerEnabled = true;
}

_RLT = {
    $: null,
    i: null,       
    jQueryPath: "http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js",
    jQueryUIPath: "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js",
    swfObjectPath: "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js",
    jQueryUICSSPath: "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/flick/jquery-ui.css",
    trackJSONPath: _RLtrk_baseURL+"widgets/json/trk.php?callback=?",
    swfPath: _RLtrk_S3URL+"trk.swf",
    emailCapturePath: _RLtrk_baseURL+"capture/",
    expressInstallSWFPath: _RLtrk_baseURL+"widgets/swf/expressInstall.swf",
    dl_lock: false,
    dl_lock_to: 100,
    
    loadScript: function(type, url, callback) {
      var script = document.createElement((type == "js") ? "script" : "link");
      script.type = "text/"+((type == "js") ? "javascript" : "css");
      if (script.readyState) {  // IE
        script.onreadystatechange = function() {
          if (script.readyState == "loaded" || script.readyState == "complete") {
            script.onreadystatechange = null;
            if (typeof(callback) == "function") callback();
          }
        };
      } else {
        script.onload = function() { if (typeof(callback) == "function") callback(); };
      }
      if (type == "css") script.rel = "stylesheet";
      script[(type == "js") ? "src" : "href"] = url;
      document.getElementsByTagName("head")[0].appendChild(script);
    },
    
    render: function(id) {
      _RLT.i = id;
      
      var html_element_name = "#rl_trk_"+id;
      var w = 300;
      var h = 58;

      var render_func = function(id, html_element_name, w, h) {
        _RLT.$(html_element_name)
          .width(w)
          .height(h)
          .css("margin-bottom", "10px")
          .html("<div id='rl-trk-obj-"+id+"'></div>");
        swfobject.embedSWF(_RLT.swfPath, "rl-trk-obj-"+id, w, h, "9.0.0", _RLT.expressInstallSWFPath, {i:id, n:'main'}, {allowscriptaccess: "always"});
      };      

      if (typeof(jQuery) == "undefined") {
        _RLT.loadScript("js", _RLT.jQueryPath, function() {
          _RLT.loadScript("js", _RLT.swfObjectPath, function() {
            _RLT.$ = jQuery.noConflict();
            render_func(id, html_element_name, w, h);
          });
        });
      } else {
        _RLT.$ = jQuery;
        render_func(id, html_element_name, w, h);
      }
    },
    
    download: function(id, h, t) {
      
     // Capture GA event for Download
     if(isTrackerEnabled){
       var pageTracker = _gat._getTracker(_RLtrk_GA_id);
       pageTracker._initData();                 
       t = entityDecode(t);           
       pageTracker._trackEvent("Track", "Download", 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();
            }
          }
      }  
        
        
    },
    
    
    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);
        }
      }
    },

    showDownloadDialog: function() {  
      var width = 362;
      var height = 300;
      var height_addl = 60;
      var dialogOptions = {draggable: false, resizable: false, width: (width+36), zIndex: 25000};
      _RLT.$("<div title='Download Email'><iframe src='"+_RLT.emailCapturePath+_RLT.i+"' style='border: none; width: "+width+"px; height: "+height+"px; margin: 0 auto;' frameborder='0' scrolling='no' /></div>").dialog(dialogOptions);
    }    
};

/* MySpace Music */
if (location.href.indexOf('myspace.com') != -1) {
  _RLT.loadScript("js", _RLT.jQueryPath, function() {
    _RLT.loadScript("js", _RLT.swfObjectPath, function() {
      _RLT.$ = jQuery.noConflict();
      _RLT.$("#rl-trk-image a").click(function() {
        _RLT.showDownloadDialog();
        return false;
      });
      _RLT.$.getJSON(_RLT.trackJSONPath, function(data) {
        if (data.i) {
          _RLT.i = data.i;
          _RLT.$("#rl-trk").html("<div id='rl-trk-obj'></div>");
          swfobject.embedSWF(_RLT.swfPath, "rl-trk-obj", "300", "58", "9.0.0", _RLT.expressInstallSWFPath, {i: _RLT.i}, {allowscriptaccess: "always"});
        }
      });
      _RLT.$.getScript(_RLT.jQueryUIPath);
      _RLT.loadScript("css", _RLT.jQueryUICSSPath);
    });
  });
}
