function iecheck() {
  if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
    var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
    var iever = (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) <= 7 );
  }
  return iever;
}

CoreWidget = new function() {
  var BASE_URL = 'http://dev.reidab.com/core/';
  var STYLESHEET = BASE_URL + "css/core_widget.css"
  var CONTENT_URL = BASE_URL + 'index.php?js=true';
  var ROOT = 'core_widget_content';
  var stored_data = '';
  var showing_index = -1;

  function requestStylesheet(stylesheet_url) {
    stylesheet = document.createElement("link");
    stylesheet.rel = "stylesheet";
    stylesheet.type = "text/css";
    stylesheet.href = stylesheet_url;
    stylesheet.media = "all";
    document.lastChild.firstChild.appendChild(stylesheet);
  }

  function requestContent( local ) {
    var script = document.createElement('script');
    script.src = CONTENT_URL;
    document.getElementsByTagName('head')[0].appendChild(script);
  }
  
  function showTip(index) {
    showing_index = index;
    tip = stored_data[index];
    var div = document.getElementById(ROOT);
    div.innerHTML = '';
    if(!!tip.image) div.innerHTML += "<img src='" + BASE_URL + '/images/' + tip.image + "' />";
    div.innerHTML += "<h2>" + tip.title + "</div>";
    div.innerHTML += "<p class='tip_body'>" + tip.message + "</div>";
    div.style.display = 'block'; // make element visible
    div.style.visibility = 'visible'; // make element visible
  }
  
  function storeData(data) {
    stored_data = data;
  }
  
  function showNextTip() {
    nextIndex = showing_index + 1;
    if (nextIndex>=stored_data.length) nextIndex = 0;
    showTip(nextIndex);
    return false;
  }
  
	this.init = function() {
	  this.serverResponse = function(data) {
	    if (!data) return;
	    stored_data = data;
	    showNextTip();
	  }
	  
	  this.next = showNextTip;
	
	  requestStylesheet(STYLESHEET);
	  document.write("<div id='core_widget'><h1>Tip of the Day</h1><div id='widget_body'><div id='" + ROOT + "' style='display: none'></div><a href='#' id='core_next_tip'>Next</a><a id='core_link' href='http://www.corerhythms.com/'><img src='http://dev.reidab.com/core/i/widget_logo.gif' alt='Core Rhythms' /></a></div><div id='widget_bottom'></div></div>");
	  document.getElementById('core_next_tip').onclick = this.next;
	  requestContent();
	  var no_script = document.getElementById('no_script');
	  if (no_script) { no_script.style.display = 'none'; }
	}
}

CoreWidget.init();