ï»¿// ecsite.js file for Executive Connection, Copyright Â© 2007-2009 BlueVertex LLC
  dojo.registerModulePath('dijit', '/clientcached/Iv0DircE/js/dijit');
  dojo.registerModulePath('dojox', '/clientcached/Iv0DircE/js/dojox');
  dojo.registerModulePath('ecsite', '/clientcached/Iv0DircE/js/ecsite');

  dojo.provide("ecsite");
  dojo.require("dojo.date.locale");
  dojo.require("dojo.fx");
  dojo.require("dojo.fx.easing");
  dojo.require("dojo.i18n");
  dojo.require("dojox.analytics.Urchin");
  dojo.require("dojox.gfx");
  dojo.require("dojox.gfx.utils");

  dojo.require("dijit.Tooltip")
  
  //if (dojo.isIE) {
  //	  dojo.require("ecsite.css3MC");
  //}
  
  //dojo.require("MochiKit.MochiKit");

var app = null;
dojo.addOnLoad(function() {
	
	ecsite_CreatePrototypes();
	
	app = new ecsite.Application();
	
});

//----- The code in this file (ecsite_extensions.js) is separated out so that it can be used either during the Maven build or at runtime.

var ecsite_Propline_AddCalculateCoordinates = new Object();
ecsite_Propline_AddCalculateCoordinates.calculateCoordinates = function(carouselWidth, carouselHeight, ulOrdinal, ulZIndex, liOrdinal, liCount, itemHeight, itemWidth, itemZIndex, maxItemHeight, maxItemWidth, animProgress) {
		var length = liCount;
		var centerx = carouselWidth / 2
		var centery = carouselHeight / 2;
		var offsetx = itemWidth / 2;
		var offsety = itemHeight / 2;
		var radiusx = centerx - maxItemWidth / 2;
		var radiusy = centery - maxItemHeight / 2;
		var angle = liOrdinal * 2 * Math.PI / length;
		var offsettheta = Math.PI / (length * (2 - (length % 2)));
		var cosval = Math.cos(2 * Math.PI * animProgress * 10 + angle + offsettheta);
		var posx = centerx - offsetx + Math.sin(2 * Math.PI * animProgress * 10 + angle + offsettheta) * radiusx;
		var posy = centery - offsety + cosval * radiusy;
		
		var posz = null;
		var intUlZIndex = isNaN(parseInt(ulZIndex)) ? 100 : parseInt(ulZIndex);
		var intItemZIndex = isNaN(parseInt(itemZIndex)) ? intUlZIndex : parseInt(itemZIndex);
		
		if (intItemZIndex > intUlZIndex + 1) {
			posz = intItemZIndex;
		}
		else {
			if (cosval > 0) posz = (intUlZIndex + 1).toString();
			else posz = intUlZIndex;
		}
				
		return {"ulOrdinal":ulOrdinal, "x":posx, "y":posy, "z":posz};
	}
	
//----- 

function ecsite_CreatePrototypes()
	{
		function ecsite_coordPlaceholder_x () {}
		function ecsite_coordPlaceholder_y () {}
		function ecsite_coordPlaceholder_z () {}
		dojo.declare("ecsite.Propline", null, { //for ecsiteApplication.animateCarousel(), code originally from dojo/_base/fx.js
			_carouselProperties: null,
			constructor: function(properties, carouselProperties){
				this._properties = properties;
				this._carouselProperties = carouselProperties;
				for(var p in properties){
					var prop = properties[p];
					if(prop.start instanceof dojo.Color){
						// create a reusable temp color object to keep intermediate results
						prop.tempColor = new dojo.Color();
					}
				}
			},
			getValue: function(r){
				var ret = {};
				var liOrdinal, xPropName, yPropName, zPropName;
				for(var p in this._properties){
					var prop = this._properties[p],
						start = prop.start;
					if(p == "carouselOrdinal"){
						liOrdinal = start;
					}else if(start instanceof ecsite_coordPlaceholder_x){
						xPropName = p;
					}else if(start instanceof ecsite_coordPlaceholder_y){
						yPropName = p;
					}else if(start instanceof ecsite_coordPlaceholder_z){
						zPropName = p;
					}else if(start instanceof dojo.Color){
						ret[p] = dojo.blendColors(start, prop.end, r, prop.tempColor).toCss();
					}else if(!dojo.isArray(start)){
						ret[p] = ((prop.end - start) * r) + start + (p != "opacity" ? prop.units || "px" : 0);
					}
				}
				
				var itemCoords = this.calculateCoordinates(dojo.style(this._carouselProperties.carouselElm, "width"),
					dojo.style(this._carouselProperties.carouselElm, "height"),
					this._carouselProperties.ulOrdinal,
					dojo.style(this._carouselProperties.carouselElm, "zIndex"),
					liOrdinal,
					this._carouselProperties.carouselElm.itemCount,
					this._carouselProperties.itemHeight,
					this._carouselProperties.itemWidth,
					dojo.style(this._carouselProperties.itemElm, "zIndex"),
					this._carouselProperties.carouselElm.maxItemHeight,
					this._carouselProperties.carouselElm.maxItemWidth,
					r);
								
				ret[xPropName] = itemCoords.x.toString() + "px";
				ret[yPropName] = itemCoords.y.toString() + "px";
				ret[zPropName] = itemCoords.z.toString();
				
				return ret;
			}
		});
		dojo.extend(ecsite.Propline, ecsite_Propline_AddCalculateCoordinates);
		
		dojo.declare("ecsite.ApplicationError", null, {
			name: "ecsite.ApplicationError",
			message: null,
			number: null,
			description: null
		});
		dojo.declare("ecsite.Application", null, {
			rootLayoutWidth: 1122,
			backgroundColor: new dojo.Color("#C0C0C0"),
			bgNode: null,
			bgSurface: null,
			tracker: null,
			GOOGLE_ACCT: "UA-4310356-3",
			CONTENTSUBDIR_PATH: "content/",
			CONTENTSUBDIR_FILEEXT: ".content.html",
			// The server environment variables NUMBERSIGN_REWRITE_CONTENTSUBDIR_TOKEN and NUMBERSIGN_REWRITE_ABSOLUTE_TOKEN must be set in the Apache config files for the following code to work properly.
			// Also, Server-Side-Includes must be enabled in Apache and be processed for javascript files
			//NUMBERSIGN_REWRITE_CONTENTSUBDIR_TOKEN: "Î",
			//NUMBERSIGN_REWRITE_ABSOLUTE_TOKEN: "Î",
			NUMBERSIGN_REWRITE_CONTENTSUBDIR_TOKEN: "Î”",
			NUMBERSIGN_REWRITE_ABSOLUTE_TOKEN: "Îž",
			constructor: function(){
				this.tracker = new dojox.analytics.Urchin({
					acct: this.GOOGLE_ACCT,
					GAonLoad: function(){
						console.log("Google Analytics tracker loaded");
					}
				});

				this.process_markup();
				
				this.bgImageNode = dojo.byId("bgImage");				
				this.bgNode = dojo.byId("bgSurface");
			},
			dialog_processElements: function(dialogContentElm){
				if (dojo.isIE) {
					for(var i in css3MC.pseudoCSSRules) {					
						var affectedElements = css3MC.ut.cssQuery(i, dialogContentElm);							
						for(var j=0;j<affectedElements.length;j++) {	
							css3MC.processElement(affectedElements[j], css3MC.pseudoCSSRules[i]['column-count'], css3MC.pseudoCSSRules[i]['column-width'], css3MC.pseudoCSSRules[i]['column-gap'], css3MC.pseudoCSSRules[i]['column-rule']);
						}
					}
				}
			},
			process_markup: function(){
				dojo.query("a[xlink:show=new]").forEach(function(node, index, arr){
					dojo.attr(node, "target", "_blank");
				});
				
				var carouselNodeList = dojo.query("ul.carousel");
				if (carouselNodeList.length > 0) {
					dojo.require("dijit.Dialog");
					dojo.forEach(carouselNodeList, dojo.hitch(this, function(carouselElm, index, arr){
						carouselElm.ulOrdinal = index;
						dojo.style(carouselElm, "position", "relative");
						dojo.style(carouselElm, "zIndex", "90");
						carouselElm.dialog = new dijit.Dialog({
							title: "Executive Connection",
							style: "width: 700px; height: 500px;"
						});
						
						carouselElm.pauseCtrlNode = dojo.doc.createElement("DIV");
						carouselElm.pauseCtrlNode.pauseText = "<div style=\"font-size:.5em; zoom:1;\">" + String.fromCharCode(9616) + String.fromCharCode(9616) + "</div>";//"<span style=\"font-size:.5em;\"><span style=\"position:relative;left:.7em;\">" + String.fromCharCode(10074) + "</span><span style=\"position:relative;left:.2em;\">" + String.fromCharCode(10074) + "</span></span>";
						carouselElm.pauseCtrlNode.pauseText = String.fromCharCode(8201) + String.fromCharCode(9616) + String.fromCharCode(9616);//"<span style=\"font-size:.5em;\"><span style=\"position:relative;left:.7em;\">" + String.fromCharCode(10074) + "</span><span style=\"position:relative;left:.2em;\">" + String.fromCharCode(10074) + "</span></span>";
						carouselElm.pauseCtrlNode.playText = String.fromCharCode(8201) + String.fromCharCode(8227)//String.fromCharCode(9654);
						carouselElm.pauseCtrlNode.appendChild(dojo.doc.createTextNode(carouselElm.pauseCtrlNode.pauseText));
						dojo.style(carouselElm.pauseCtrlNode, "position", "absolute");
						dojo.style(carouselElm.pauseCtrlNode, "right", "0px");
						dojo.style(carouselElm.pauseCtrlNode, "bottom", "0px");
						dojo.style(carouselElm.pauseCtrlNode, "opacity", ".3");
						dojo.style(carouselElm.pauseCtrlNode, "cursor", "pointer");
						dojo.style(carouselElm.pauseCtrlNode, "fontSize", "2em");
						dojo.style(carouselElm.pauseCtrlNode, "direction", "rtl");
						dojo.connect(carouselElm.pauseCtrlNode, "onclick", function(evt){
							var carouselElm = null;
							dojo.query("ul.carousel").forEach(dojo.hitch(this, function(node, index, arr){
								if (dojo.isDescendant(this, node)) carouselElm = node;
							}));
							if (dojo.isObject(carouselElm.combinedAnim)){
								var animStatus = carouselElm.combinedAnim.status();
								if (animStatus == "playing") carouselElm.combinedAnim.pause();
								else if (animStatus == "paused") carouselElm.combinedAnim.play();
								else if (animStatus == "stopped") carouselElm.combinedAnim.play();
							}
						});
						carouselElm.appendChild(carouselElm.pauseCtrlNode);
											
						var liOrdinal = 0;
						var maxItemHeight = 0;
						var maxItemWidth = 0;
						carouselElm.animArray = new Array();
						carouselElm.combinedAnim = null;
						carouselElm.appRef = this;
						for (var i = 0; i < carouselElm.childNodes.length; i++){
							child = carouselElm.childNodes[i];
							if (child.nodeType == 1) {
								if (child.tagName.toUpperCase() == "LI") {
									liOrdinal++;
									var veilNode = null;
									dojo.forEach(child.childNodes, dojo.hitch(this, function(grandchild, index, arr){
										if (grandchild.nodeType == 1) {
											if (grandchild.tagName.toUpperCase() == "A") {
												if (dojo.hasClass(grandchild, "carousellink")) {
													veilNode = grandchild;
												}
											}
										}
									}));
									
									veilNode.appRef = this;
									child.appRef = this;
									dojo.style(child, "display", "block");
									dojo.style(child, "position", "absolute");
									dojo.style(veilNode, "height", dojo.style(child, "height") + "px");
									dojo.style(veilNode, "width", dojo.style(child, "width") + "px");
									dojo.style(veilNode, "opacity", .65);
									
									var vCenterNode = dojo.doc.createElement("DIV");
									dojo.forEach(veilNode.childNodes, dojo.hitch(this, function(greatgrandchild, index, arr){
											veilNode.removeChild(greatgrandchild);
											vCenterNode.appendChild(greatgrandchild);
									}));
									dojo.style(vCenterNode, "position", "absolute");
									dojo.style(vCenterNode, "top", "50%");
									dojo.style(vCenterNode, "left", "50%");
									dojo.style(vCenterNode, "textAlign", "center");
									veilNode.appendChild(vCenterNode);
									dojo.style(vCenterNode, "marginTop", -(dojo.style(vCenterNode, "height")/2) + "px");
									dojo.style(vCenterNode, "marginLeft", -(dojo.style(vCenterNode, "width")/2) + "px");
									
									child.veilNode = veilNode;
									
									dojo.connect(child.veilNode, "onclick", function(evt){
											var carouselElm = this.appRef.findCarousel(this);
											/* var carouselElm = null;
											dojo.query("ul.carousel").forEach(dojo.hitch(this, function(node, index, arr){
												if (dojo.isDescendant(this, node)) carouselElm = node;
											})); */
											carouselElm.dialog.savedAnimStatus = carouselElm.combinedAnim.status();
											carouselElm.dialog.savedCurrentHref = window.location.href;
											if (dojo.isObject(carouselElm.combinedAnim)) carouselElm.combinedAnim.pause();
											
											var currentUri = (window.location.href.indexOf("#") == -1) ? window.location.href : window.location.href.substr(0,window.location.href.indexOf("#"));
											var dialogUri = (dojo.attr(this, "href").indexOf(":") == -1) ? new dojo._Url(document.baseUri, dojo.attr(this, "href")) : dojo.attr(this, "href");
											var dialogAbsoluteUri = new ecsite.Uri(dialogUri).getAbsolute();
											var dialogAbsoluteUriObj = new ecsite.Uri(dialogAbsoluteUri);
											var dialogUriPort = (dialogAbsoluteUriObj.port == null) ? "" : dialogAbsoluteUriObj.port;
											var numbersignValue = null;
											if ((dialogAbsoluteUriObj.host == window.location.hostname) && ((dialogAbsoluteUriObj.scheme + ":") == window.location.protocol) && (dialogUriPort == window.location.port)) {
												var dialogAbsoluteUriObj = new ecsite.Uri(dialogAbsoluteUri.replace(/\/([^\/]*)\.xhtml/, "/" + this.appRef.CONTENTSUBDIR_PATH + "$1" + this.appRef.CONTENTSUBDIR_FILEEXT));
												numbersignValue = this.appRef.NUMBERSIGN_REWRITE_CONTENTSUBDIR_TOKEN + dialogAbsoluteUriObj.path;
												this.appRef.tracker.tracker._trackEvent('carousel', 'click', dialogAbsoluteUriObj.path);
											}
											else {
												numbersignValue = this.appRef.NUMBERSIGN_REWRITE_ABSOLUTE_TOKEN + dialogAbsoluteUri;
												this.appRef.tracker.tracker._trackEvent('carousel', 'click', dialogAbsoluteUri);
											}
											var newUri = currentUri + "#" + encodeURIComponent(numbersignValue);
											window.location.href = newUri;
											dojo.stopEvent(evt);
											
											carouselElm.dialog.attr("href", dialogAbsoluteUriObj.toString());
											carouselElm.dialog.appRef = carouselElm.appRef;
											carouselElm.dialog.hrefOnLoadHandle = dojo.connect(carouselElm.dialog, "onLoad", function(evt){
												var scrollDiv = dojo.doc.createElement("DIV");
												dojo.addClass(scrollDiv, "dialogbox");
												dojo.style(scrollDiv, "overflow", "auto");
												dojo.style(scrollDiv, "height", "450px");
												dojo.style(scrollDiv, "width", "665px");
												scrollDiv.innerHTML = this.attr("content");
												dojo.disconnect(this.hrefOnLoadHandle);
												this.attr("content", scrollDiv);
												this.appRef.dialog_processElements(scrollDiv);
												dojo.style(scrollDiv, "width", "100%");
											});
											carouselElm.dialog.animRef = carouselElm.combinedAnim;
											carouselElm.dialog.onHideHandle = dojo.connect(carouselElm.dialog, "hide", function(evt){
												if (this.savedAnimStatus == "playing") {
													this.animRef.play()
												}
												window.location.href = this.savedCurrentHref.indexOf("#") == -1 ? this.savedCurrentHref + "#" : this.savedCurrentHref;
											});
											
											carouselElm.dialog.show();
	
											dojo.byId("dijit_Dialog_0_underlay").dialogRef = carouselElm.dialog;
											dojo.connect(dojo.byId("dijit_Dialog_0_underlay"), "onclick", function(evt){
												this.dialogRef.hide();
											});
									});
									dojo.connect(child, "onmouseover", function(evt){
											var carouselElm = this.appRef.findCarousel(this);
											var carouselZIndex = isNaN(dojo.style(carouselElm, "zIndex")) ? 100 : dojo.style(carouselElm, "zIndex");
											this.savedZIndex = dojo.style(this, "zIndex");
											dojo.style(this, "zIndex", carouselZIndex + 2);
											dojo.style(this.veilNode, "zIndex", carouselZIndex + 3);
											dojo.style(this.veilNode, "left", "0px");
											
											dojo.stopEvent(evt);
									});
									dojo.connect(child, "onmouseout", function(evt){
											dojo.style(this.veilNode, "left", "-10000px");
											dojo.style(this, "zIndex", this.savedZIndex);
											dojo.stopEvent(evt);
									});
									
									if (dojo.style(child, "height") > maxItemHeight) maxItemHeight = dojo.style(child, "height");
									if (dojo.style(child, "width") > maxItemWidth) maxItemWidth = dojo.style(child, "width");
									this.animationObj = this.animateCarousel({ 
										node: child,
										duration : 120000, // increasing duration slows down the speed of the carousel
										repeat: 0,
										easing: dojo.fx.easing.linear,
										properties: {
											top: {
												start: new ecsite_coordPlaceholder_y()
											},
											left: {
												start: new ecsite_coordPlaceholder_x()
											},
											zIndex: {
												start: new ecsite_coordPlaceholder_z()
											},
											ulOrdinal: {
												start: carouselElm.ulOrdinal
											},
											carouselOrdinal: {
												start: liOrdinal
											}
										},
										carouselProperties: {
											itemHeight: dojo.style(child, "height"),
											itemWidth: dojo.style(child, "width"),
											itemZIndex: dojo.style(child, "zIndex"),
											carouselElm:carouselElm,
											itemElm:child
										}
									});
									carouselElm.animArray.push(this.animationObj);
								}
							}
						}
						carouselElm.itemCount = liOrdinal;
						carouselElm.maxItemHeight = maxItemHeight;
						carouselElm.maxItemWidth = maxItemWidth;
						carouselElm.combinedAnim = dojo.fx.combine(carouselElm.animArray);
						carouselElm.combinedAnim.play();
					}));
				}
			},
			findCarousel: function(itemElm){
				var retVal = null;
				dojo.query("ul.carousel").forEach(dojo.hitch(this, function(node, index, arr){
					if (dojo.isDescendant(itemElm, node)) retVal = node;
				}));
				return retVal;
			},
			animateCarousel: function(/*dojo.__AnimArgs*/ args){
									
				args.node = dojo.byId(args.node);
				if(!args.easing){ args.easing = dojo._defaultEasing; }
		
				var anim = new dojo._Animation(args);
				dojo.connect(anim, "beforeBegin", anim, function(){
					var pm = {};
					for(var p in this.properties){
						if(p == "width" || p == "height"){
							this.node.display = "block";
						}
						var prop = this.properties[p];
						prop = pm[p] = dojo.mixin({}, (dojo.isObject(prop) ? prop: { end: prop }));
		
						if(dojo.isFunction(prop.start)){
							prop.start = prop.start();
						}
						if(dojo.isFunction(prop.end)){
							prop.end = prop.end();
						}
						var isColor = (p.toLowerCase().indexOf("color") >= 0);
						function getStyle(node, p){
							// dojo.style(node, "height") can return "auto" or "" on IE; this is more reliable:
							var v = {height: node.offsetHeight, width: node.offsetWidth}[p];
							if(v !== undefined){ return v; }
							v = dojo.style(node, p);
							return (p == "opacity") ? +v : (isColor ? v : parseFloat(v));
						}
						if(!("end" in prop)){
							prop.end = getStyle(this.node, p);
						}else if(!("start" in prop)){
							prop.start = getStyle(this.node, p);
						}
		
						if(isColor){
							prop.start = new dojo.Color(prop.start);
							prop.end = new dojo.Color(prop.end);
						}/* else{
							prop.start = (p == "opacity") ? +prop.start : parseFloat(prop.start);
						} */
					}
					this.curve = new ecsite.Propline(pm, args.carouselProperties);
				});
				
				dojo.connect(anim, "onPlay", anim, function(){
					args.carouselProperties.carouselElm.pauseCtrlNode.innerHTML = args.carouselProperties.carouselElm.pauseCtrlNode.pauseText;
					dojo.style(args.carouselProperties.carouselElm.pauseCtrlNode, "fontSize", "1em");
				});
				dojo.connect(anim, "onPause", anim, function(){
					args.carouselProperties.carouselElm.pauseCtrlNode.innerHTML = args.carouselProperties.carouselElm.pauseCtrlNode.playText;
					dojo.style(args.carouselProperties.carouselElm.pauseCtrlNode, "fontSize", "2em");
				});
				dojo.connect(anim, "onStop", anim, function(){
					args.carouselProperties.carouselElm.pauseCtrlNode.innerHTML = args.carouselProperties.carouselElm.pauseCtrlNode.playText;
					dojo.style(args.carouselProperties.carouselElm.pauseCtrlNode, "fontSize", "2em");
				});
				dojo.connect(anim, "onEnd", anim, function(){
					args.carouselProperties.carouselElm.pauseCtrlNode.innerHTML = args.carouselProperties.carouselElm.pauseCtrlNode.playText;
					dojo.style(args.carouselProperties.carouselElm.pauseCtrlNode, "fontSize", "2em");
				});
				
				dojo.connect(anim, "onAnimate", dojo.hitch(dojo, "style", anim.node));
				return anim; // dojo._Animation
			}
		});
	}
  
/*

				dojo.require("dojox.data.css");
				dojo.require("dojox.data.css.rules");
				
				dojox.data.css.rules.forEach(function(rule, index, arr){
					//dojo.style(rule, "border", "solid blue 1px");
					//dojo.doc.write(rule.selectorText + "<br/>");
					if (rule.selectorText == "ul.carousel > li") {
						try {
							rule.removeProperty("display");
							//rule.setProperty("display", "block");
							dojo.style(node, "display", "block");
						}
						catch (ex) {
						}
					}
				}, false, dojo.doc.styleSheets); */
  
dojo.provide("ecsite.Uri");
dojo.declare(
	"ecsite.Uri",
	dojo._Url,
	{		
		isAbsolute:function(){
			// summary:
			//		Tells if the parsed URL is absolute (if not it's relative).
			// tests:
			//		>>> new dojox.Uri("/").isAbsolute() // Check simple isAbsolute() for false.
			//		false
			//		>>> new dojox.Uri("http://localhost").isAbsolute() // Check simple isAbsolute() for true.
			//		true
			return this.scheme!="" && this.scheme!=null && this.host!="" && this.host!=null;
		},
		
		getAbsolute:function(protocol, host, port){
			// summary:
			//		Return an absolute URL, including protocol, host, etc.
			// description:
			//		It always assumes the host, port, etc from window.location if
			//		not explicitly given.
			// tests:
			//		>>> new dojox.Uri("/").getAbsolute("http", "localhost") // Get simple absolute URL.
			//		"http://localhost/"
			//		>>> url = new dojox.Uri("/") // Test getAbsolute() using window.location.
			//		>>> p = window.location.protocol, h = window.location.hostname
			//		>>> new dojox.Uri("/").getAbsolute() == p+"//"+h+"/"
			//		true
			if (this.isAbsolute()) {
				return this.toString();
			}
			// If host+protocol are given as params we should not use windows.location.port
			// but assume that no port is meant (if missing).
			var _port = (this.scheme && this.host) ? ( this.port  || "") : window.location.port;
			var ret = (this.scheme ? (this.scheme+":") : window.location.protocol) + "//";
			ret += this.host || window.location.hostname;
			ret += _port ? ":"+_port : "";
			if (this.toString().charAt(1) == "/") {
				ret += this.toString()
			}
			else {
				var _currentPath = new ecsite.Uri(window.location.href).path;
				var _currentPathWithoutScriptName = _currentPath.substring(0, _currentPath.lastIndexOf("/") + 1);
				ret += _currentPathWithoutScriptName + this.toString()
			}
			return ret;
		}		
	}
);

