var last_width = null;
var last_height = null;
var open_section = null;

  $('link#common').attr('rel', 'stylesheet');

$(document).ready(function() {
  if (($.sniff.browser.isIE && $.sniff.system.isMac) || $.sniff.browser.isNetscape) {
    window.location.href = "/wsreq/index.aspx";
  }

  $('a[rel=external]').attr('target', '_blank');

  checkSize();
});

$(window).resize(function(){
  checkResize();
});

function openFeatureStory() {
  buildIFrame('cms/default/CLIO.aspx','news');
}

function openSecondFeatureStory() {
  buildIFrame('cms/business_news.aspx?page=6');
}

function newsInterface() {
   buildIFrame('cms/food_for_thought.aspx', 'news');
}

function careersInterface() {
  buildIFrame('http://tbe.taleo.net/NA2/ats/careers/jobSearch.jsp?org=COMMONHEALTH&cws=1', 'careers');
}

function contactInterface() {
  buildIFrame('contact_frame/Default.aspx', 'contact');
}

function buildIFrame(src, section) {
  open_section = section;
  $('.'+section).show();
  $('#internal_frame').html("<iframe src="+src+" width='600' height='424' frameborder='no' style='background: #fff; overflow-x:hidden;overflow-y:auto;'allowtransparency='false'></iframe>");
  $('#framer').fadeIn('slow', function(){
    if ($.sniff.browser.isIE) {
      this.style.removeAttribute('filter');
    }
  });
}

function hideHTML() {
  $('.'+open_section).fadeOut('fast');
  $('#framer').fadeOut('fast');
}

function loadFlashMovie(ver) {
  $('#seo_elements').hide();
  $('#footer').hide();
  $('#seo').attr('disabled', 'disabled');
  $('#seo_elements').hide();
  $('#common').attr('disabled', '');
  $('#movie').show();

  var so = new SWFObject("../index.swf", "CHWebSite", "100%", "100%", ver, "#FFFFFF");
  so.addParam("wmode", "transparent");
  so.write("movie");
}

function unloadFlashMovie(reason) {
  $('#movie').hide();
  $('#framer').hide();
  $('#common').attr('disabled', 'disabled');
  $('#seo').attr('disabled', '');
  if (reason == 'flash') {
    $('.noflash').html("sorry, you need to update your flash player to the latest version to view our site. <a style='color: #fff; font-weight:bold;' href='http://get.adobe.com/flashplayer/' rel='external'>get adobe flash player</a>");
  } else {
    $('.noflash').html("your browser window is smaller than required, please resize it larger if possible.");
  }
  $('.noflash').show();
}

function checkSize() {
  if ( $(document).width() < 1000 || $(document).height() < 575) {
    last_width = $(document).width();
    last_height = $(document).height();

    unloadFlashMovie('size');
  } else if (config.flash_player_version.major < parseInt(config.minimum_flash_required)) {
    unloadFlashMovie('flash');
  } else {
    loadFlashMovie(config.minimum_flash_required);
  }
}

function checkResize() {
  if (last_width != null && last_height != null) {
    if (last_width < 1000 || last_height < 575) {
      if ($(document).width() >= 1000 && $(document).height() >= 575) {
        last_width = $(document).width();
        last_height = $(document).height();
        if (config.flash_player_version.major < parseInt(config.minimum_flash_required)) {
          unloadFlashMovie('flash');
        }
        else {
          loadFlashMovie(config.minimum_flash_required);
        }
      }
    }
  }
}
