var currFact = 0;
var arrFacts = new Array(
"78% of physicians now get clinical information online.",

"63% of connected online physicians participated in various pharma-sponsored promotional marketing programs.",

"Internet CME now constitutes 27% of all CME activities, with a 60% increase in the number of online physician registrants from last year.",

"Online CME is now second only to live meetings as primary care physicians&#8217; most preferred form of CME.",

"In a controlled study of the effectiveness of eCME vs. live workshops, physicians in the eCME group actually scored slightly higher.",

"The percentage of (CME) credit hours earned at out-of-town meetings is now only 41%."
);

var globalNav;

function initHome() {
	// Load Flash
	var flashvars = {};
	var params = {};
	params.wmode = "transparent";
	var attributes = {};
	attributes.id = "homeSWF";
	swfobject.embedSWF("images/home.swf", "home-swf", "679", "246", "9.0.0", false, flashvars, params, attributes);	
	
	 // Initialize Quick Facts
	var rand=Math.floor(Math.random()*arrFacts.length); 
	$('quickfact').replace("<p id='quickfact'>"+arrFacts[rand]+"</p>");
	currFact = rand;
	}
	
function quickFacts() {
	currFact = currFact+1;
	if(currFact == arrFacts.length) {
		currFact = 0;
		}
	$('quickfact').replace("<p id='quickfact'>"+arrFacts[currFact]+"</p>");
	}		

function defaultNavState() {
	if($(navOn) != undefined) {
		$(navOn).setAttribute('src','/_resources/images/'+navOn+'_on.gif');
		}
	}


function navOver(id) {
	if(id != navOn) {
		$(id).setAttribute('src','/_resources/images/'+id+'_over.gif');
		}
	
	if(ie == 1) {
		pos = $(id).cumulativeOffset();
		if(id == "nav_about") {
			$('fly-about').style.left = pos[0] + "px";
			$('fly-about').style.top = (pos[1] + 36) + "px";
			}
		
		if(id == "nav_services") {
			$('fly-services').style.left = pos[0] + "px";
			$('fly-services').style.top = (pos[1] + 36) + "px";
			}
		}			
	}
	
function navOut(id) {
	if(id != navOn) {
		$(id).setAttribute('src','/_resources/images/'+id+'_off.gif');
		}
	}



function homeFlashLearnHow() {
	toggleThis('pop-advantage');
	$('flash-wrap').replace(
	'<div id="flash-wrap"><div id="home-swf"><a href="javascript:toggleThis(\'pop-advantage\');"><img src="/images/home_noflash.jpg" alt="Begin Your Path To The Top With The ExtendMed Advantage - Learn How" width="679" height="246" /></a>	</div>');
	}

function toggleThis(id) {
	$(id).toggle();
	}


function initGlobalNav() {
	globalNav = $('global-nav').childElements();
	
	globalNav.each(function(item) {
		var navItem = item.down('img');
		if(navItem != undefined) {
			// mouseover event to trigger the call to navOver()
			Event.observe(navItem,'mouseover',function() {
				itemID = navItem.identify();
				navOver(itemID);
				}.bind(item));
	
			// mouseout event to remove highlight state from top nav if item is not current on-state
			Event.observe(item,'mouseout',function() {
				itemID = navItem.identify();
				navOut(itemID);
				}.bind(item));
			}
		});	
		
	defaultNavState();	
	}
	
function selectTab(id,num) {
	tabs = $(id+'-tabs').childElements();
	content = $(id+'-content').childElements();
	
	tabs.each(function(s) {
		s.removeClassName('on');
		});
	
	tabs[num].addClassName('on');
	
	content.each(function(s) {
		s.style.display="none";
		});
		
		content[num].style.display="block";
	}


/* ===== Start Highlight Boxes ===== */
/*

/*
createElement function found at http://simon.incutio.com/archive/2003/06/15/javascriptWithXML
*/

function createElement(element) {
    if (typeof document.createElementNS != 'undefined') {
        return document.createElementNS('http://www.w3.org/1999/xhtml', element);
    }
    if (typeof document.createElement != 'undefined') {
        return document.createElement(element);
    }
    return false;
}

function insertTop(obj) {
    // Create the two div elements needed for the top of the box
    d=createElement("div");
    d.className="bt"; // The outer div needs a class name
    d2=createElement("div");
    d.appendChild(d2);
    obj.insertBefore(d,obj.firstChild);
}

function insertBottom(obj) {
    // Create the two div elements needed for the bottom of the box
    d=createElement("div");
    d.className="bb"; // The outer div needs a class name
    d2=createElement("div");
    d.appendChild(d2);
    obj.appendChild(d);
}

function wrapHLBox(d) {
    var thediv, outer, i1, i2;
    // Save the original outer div for later
        thediv = d;
    //     Create a new div, give it the original div's class attribute, and replace 'boxWrap' with 'cb'
        outer = createElement('div');
        outer.className = thediv.className;
        outer.className = thediv.className.replace('box-wrap', 'cb');
    // Change the original div's class name and replace it with the new div
        thediv.className = 'i3';
        thediv.parentNode.replaceChild(outer, thediv);
    // Create two new div elements and insert them into the outermost div
        i1 = createElement('div');
        i1.className = 'i1';
        outer.appendChild(i1);
        i2 = createElement('div');
        i2.className = 'i2';
        i1.appendChild(i2);
    // Insert the original div
        i2.appendChild(thediv);
    // Insert the top and bottom divs
        insertTop(outer);
        insertBottom(outer);
    }


function initBoxWrap() {
	if(iesix == 0) { // modern browser?
	    var boxHL = $$('div.box-wrap');
    
	    // Loop through the found div elements    
    	boxHL.each(function(d) {
        	wrapHLBox(d);
	        });
    	}
    }

/* ===== End Highlight Boxes ====== */


Event.observe(window,'load',initGlobalNav);
Event.observe(window,'load',initBoxWrap);

if(navOn == "nav_home") {
	Event.observe(window,'load',initHome);	
	}