var last_width = null;
var last_height = null;
var open_section = null;
var min_width = 995;
var min_height = 575;

var config = {
  flash_player_version: deconcept.SWFObjectUtil.getPlayerVersion(),
  minimum_flash_required: "9"
};

$(document).ready(function() {
  if (($.sniff.browser.isIE && $.sniff.system.isMac) || $.sniff.browser.isNetscape) {
    window.location.href = "/wsreq/index.aspx";
  }

  $('#map_address').submit(function() {
      openMaps($('#from_address').val());
    });
	  
  checkSize();
});
$(window).resize(function(){
  checkResize();
});
  


    function openMaps(address) {
      
      var window_left = (screen.width / 2) - 360;
      var window_top = (screen.height / 2) - 240;
      
      
      var newwindow = window.open(
       'http://maps.google.com/maps?f=d&source=s_d&saddr='+address+'&daddr=420+Interpace+Parkway,+Parsippany,+NJ&hl=en',
       'Google_Maps',
       'height=480,width=720,left='+window_left.toString()+',top='+window_top.toString()+',resizable=yes,scrollbars=yes,toolbar=no,status=no' 
      );
      
    }          

function loadFlashMovie(ver) {
  $('#seo_elements,#footer').hide();
  $('#seo').attr('disabled', 'disabled');
  $('#movie_css').attr('disabled', '');
  $('#movie').show();

  var so = new SWFObject("../index.swf", "CHWeb Site", "100%", "100%", ver, "#FFFFFF");
  so.addParam("wmode", "transparent");
  so.addParam("allowFullScreen", "true");
  so.write("movie");
}

function unloadFlashMovie(reason) {
  $('link#blank_seo').attr('rel', 'alternative stylesheet');
  $('link#blank_seo').attr('disabled', 'disabled');
  $('#movie, #framer').hide();
  $('#movie_css').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() {
  test_width = $(document).width();
  test_height = $(document).height();
  if (test_width < min_width || test_height < min_height) {
    last_width = test_width;
    last_height = test_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 < min_width || last_height < min_height) {
      test_width = $(document).width();
      test_height = $(document).height();
      if (test_width >= min_width && test_height >= min_height) {
        last_width = test_width;
        last_height = test_height;
        if (config.flash_player_version.major < parseInt(config.minimum_flash_required)) {
          unloadFlashMovie('flash');
        }
        else {
          loadFlashMovie(config.minimum_flash_required);
        }
      }
    }
  }
}

/**
 * CMS Functions
 * -----------------------------------------------------------------------------
 */
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');
}

//AGENCY OF THE YEAR
function flipperStory1() { buildIFrame('cms/business_news/commonhealth_wins_coveted.aspx','news'); }

//OGILVY & MATHER AND COMMONHEALTH TO MERGE
function ogilvyStory() { buildIFrame('cms/business_news/Ogilvy---Mather-and-CommonHealth-to-Merge-their-He.aspx'); }

//CLIO AWARD
function openFeatureStory() { buildIFrame('cms/business_news/ch_wins_two_clio_awards.aspx','news'); }

function openSecondFeatureStory() { buildIFrame('cms/business_news.aspx?page=11'); }

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'); }

