Cramer = {}
Cramer.Behavior = (function(){
function init() {
    if (arguments.callee.done) return;
    arguments.callee.done = true;
    if (_timer) clearInterval(_timer);

//YOUR INIT CODE GOES HERE

	if ($("flash-content")) {
		//var links = getElementsByClass("activePage");
		var links = $("persona-navigator").getElementsByTagName("a");
		
		printCollection = {};
		
		for (var i=0; i<links.length; i++) {
			var theHref = links[i].href;
			var splitString = theHref.split('?');
			var queryString = splitString[1];
			var theParams = queryString.split('&');
			/* CHANGE BY SID DABRAL */ //var topicID = theParams[0].split('=')[1];
			/* CHANGED TO: */ var topicID = theParams[1].split('=')[1];
			var section = theParams[2].split('=')[1];
			printCollection["" + section + ""] = topicID;
		};	
		
		var so = new SWFObject("_assets/flash/YhFlash.swf?file=_assets/xml/profiles.xml", "mymovie", "710", "458", "8", "#336699");
		so.addParam("wmode", "transparent");
		so.addParam("allowScriptAccess", "always");
		so.addVariable("file", "_assets/xml/profiles.xml");
		so.write("flash-content");
		if(document.location.search !="") {
			setTimeout(switchSWF, 500);
			var query = window.location.search.substring(1);
			var params = query.split('&');
			for (var i=0; i<params.length; i++) {
				var pos = params[i].indexOf('=');
				if (pos > 0) {
					if (params[i].substring(0,pos) == "section") {
						switchDisplay(params[i].substring(pos+1))
					}
				}
			}
		}
	}
		/* analytics triggers */
	if ($("results")) {
		doctorResults();
	};
    var anchors=getElementsByClass("icon-print");
        for (i=0;i<anchors.length;i++) {
          anchors[i].onclick=trackPrintClicks;    
    };
    if ($("map-click")) {
          $("map-click").onclick=trackMapClicks;    
    };	
    	
	//document.body.innerHTML+="<div id='cloak-div'></div><div id='msg'><div id='msg-top'><div id='blurb'></div></div><div id='msg-bottom'></div></div>";
	
	//to be installed when the flash is ready for prime time
	//if (document.body.className=="secondary") {
		//	initToolTip();
		//}

//bug fix for background image flickers in Internet Explorer
/*@cc_on @*/
/*@if (@_win32)
	document.execCommand("BackgroundImageCache", false, true);  
/*@end @*/

};
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, false);
};
/*@cc_on @*/
/*@if (@_win32)
    document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
    var script = $("__ie_onload");
    script.onreadystatechange = function() {
        if (this.readyState == "complete") {
            init(); // call the onload handler
        }
    };
/*@end @*/
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            init(); // call the onload handler
        }
    }, 10);
};
window.onload = init;

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
};
function insertAfter(parent, node, referenceNode) {
      parent.insertBefore(node, referenceNode.nextSibling);
};
function preloadImages(){
	var pics = new Array()
	for(var i=0;i<arguments.length;i++){
        pics[i]=new Image();
        pics[i].src=arguments[i];
		}
};
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
};
function getElementsByClass(theclass,node,tag) {
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)"+theclass+"(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
	return classElements;
};
function getHTTPObject() {
	var xmlhttp;
	try {
		xmlhttp = new XMLHttpRequest();
	}
	catch(er) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	return xmlhttp;
};
function getText(e) {
    var t = "";
	e = e.childNodes || e;
	for ( var j = 0; j < e.length; j++ ) {
        t += e[j].nodeType != 1 ?
            e[j].nodeValue : text(e[j].childNodes);
    }
    return t;
};
//YourHernia

function box(msg){
scroll = new function(){
		var scrollOffset = new Array;
		if (self.pageYOffset){
			scrollOffset[0] = self.pageXOffset;
			scrollOffset[1] = self.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop){
			scrollOffset[0] = document.documentElement.scrollLeft;
			scrollOffset[1] = document.documentElement.scrollTop;	
		}
		else if (document.body){
			scrollOffset[0] = document.body.scrollLeft;
			scrollOffset[1] = document.body.scrollTop;	
		}	
	return scrollOffset;
	};
	docHeight = (typeof( window.innerHeight ) == 'number') ? docHeight = window.innerHeight : docHeight = document.documentElement.clientHeight;
	docWidth = (typeof( window.innerWidth ) == 'number') ? docWidth = window.innerWidth : docWidth = document.documentElement.clientWidth;
	$("blurb").innerHTML=msg;	
	$("cloak-div").style.visibility="visible";
	$("cloak-div").style.height=(docHeight)+scrollOffset[1]+"px";
	$("cloak-div").style.width=(docWidth+scrollOffset[0])+"px";
	$("msg").style.left=(docWidth/2)-(200+scrollOffset[0])+"px";
	$("msg").style.top=(docHeight/2)-($("msg").offsetHeight/2)+scrollOffset[1]+"px";
	$("msg").style.visibility="visible";
	//setTimeout("clear_msg()",10000);
	
};
function switchDisplay(theClass){
	switch (theClass) {
		case "weekend" :
			$("pageContent").className=theClass;
			break;
		case "career" :
			$("pageContent").className=theClass;
			break;
		case "family" :
			$("pageContent").className=theClass;
			break;
		case "intimacy" :
			$("pageContent").className=theClass;
			break;
		case "health" :
			$("pageContent").className=theClass;
			break;
		case "life" :
			$("pageContent").className=theClass;
			break;
	};
};
function initToolTip() {
	document.body.innerHTML += "<div id='tt'></div>"
	var as = $("persona-navigator").getElementsByTagName("li");
	for (var i=0; i < as.length; i++){
		as[i].onmouseover = function(){ 
			var pos = findPos(this);
			$("tt").style.left=(pos[0] -145) +"px";
			$("tt").style.top=(pos[1] +50) +"px";
			$("tt").style.display="block";
			$("tt").innerHTML = this.getElementsByTagName("A")[0].innerHTML;
		};
		as[i].onmouseout = function(){
			$("tt").style.display="none";
		};
	}
};
function talkToFlash(target,profile) {
	thisMovie(target).goHome(profile);
};

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	}
	else {
		return document[movieName];
	}
};
function switchSWF(){
	var query = window.location.search.substring(1);
	var params = query.split('&');
	for (var i=0; i<params.length; i++) {
		var pos = params[i].indexOf('=');
		if (pos > 0) {
			if (params[i].substring(0,pos) =="section") {
				talkToFlash('mymovie',params[i].substring(pos+1))
			}
		}
	}
}

function printPage(personaId){

	/* CHANGE BY SID DABRAL */ //window.open("pagebuilder.aspx?topicID="+ printCollection[personaId] + "&page=Utility:Print");
	/* CHANGED TO: */ window.open("pagebuilder.aspx?topicID="+ printCollection[personaId] + "&page=Site:Print");
}

/* Google Analytics */
function setPageName(){
    var pageName = "";
    if ($("doctor-results-page")){
        pageName =  "Doctor View: " + getText($("doctor-results-page"));
    } else {
        pageName =  getText(document.getElementsByTagName("h2")[0]);
    }
    return pageName;
};
function doctorResults(){
    var docs = getElementsByClass("doctor-results");
    for (var i=0; i < docs.length; i++) {
        pageTracker._trackPageview("Search: " + getText($("search-query")).toLowerCase() + " : " + getText(docs[i]));
    };
};
function trackPrintClicks(){
    var thelink=this.href;
   pageTracker._trackPageview("Print: " + getText(document.getElementsByTagName("h2")[0]));
   var callback= function() {   
        document.location.href=''+thelink+'';
   };
   setTimeout(callback,200);
   return false;
};
function trackMapClicks(){
   var thelink=this.href;
   pageTracker._trackPageview("Map Click: " + getText($("doctor-results-page")) );
   var callback= function() { 
        document.location.href=''+thelink+'';
   };
   setTimeout(callback,200);
   return false;
};

if(typeof deconcept=="undefined"){var deconcept={};}if(typeof deconcept.util=="undefined"){deconcept.util={};}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil={};}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params={};this.variables={};this.attributes=[];if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10]||"";},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15]||"";},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=[];var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+(this.getAttribute("style")||"")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+(this.getAttribute("style")||"")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

//PRIVATE SITE SPECIFIC FUNCTIONS GO HERE
	
	return {
//PUBLIC METHODS AND ATTRIBUTES GO HERE
// IN THE RETURNED OBJECT
    publicSetPageName : function() { return setPageName();},
	switchDisplay : function(theClass) { switchDisplay(theClass); },
	talkToFlash : function(target,profile) { talkToFlash(target,profile);},
	thisMovie : function(movieName) { thisMovie(movieName); },
	printPage : function(personaId) { printPage(personaId); }
	};
})();

function switchDisplay(theClass){
	Cramer.Behavior.switchDisplay(theClass);
}

function talkToFlash(target,profile){
	Cramer.Behavior.talkToFlash(target,profile);
}

function thisMovie(movieName){
	Cramer.Behavior.thisMovie(movieName);
}


