/* (c)opyright 2008 Allconnect, All Rights reserved. */

var roundedBorderTypes = {
	all:[true, true, true, true],
	upperLeft:[true, false, false, false],
	lowerLeft:[false, false, false, true],
	upperRight:[false, true, false, false],
	lowerRight:[false, false, true, false],
	left:[true, false, false, true],
	right:[false, true, true, false],
	top:[true, true, false, false],
	bottom:[false, false, true, true],
	none:[false, false, false, false]
};

function roundTopLeftCorner(ctx, x, y, width, height, radius) {
	ctx.lineTo(x + radius, y);
	ctx.quadraticCurveTo(x, y, x, y + radius);
}

function squareTopLeftCorner(ctx, x, y, width, height) {
	ctx.lineTo(x, y);
}

function roundBottomLeftCorner(ctx, x, y, width, height, radius) {
	ctx.lineTo(x, y + height - radius);
	ctx.quadraticCurveTo(x, y + height, x + radius, y + height);
}

function squareBottomLeftCorner(ctx, x, y, width, height) {
	ctx.lineTo(x, y + height);
}

function roundBottomRightCorner(ctx, x, y, width, height, radius) {
	ctx.lineTo(x + width - radius, y + height);
	ctx.quadraticCurveTo(x + width, y + height, x + width, y + height - radius);
}

function squareBottomRightCorner(ctx, x, y, width, height) {
	ctx.lineTo(x + width, y + height);
}

function roundTopRightCorner(ctx, x, y, width, height, radius) {
	ctx.lineTo(x + width, y + radius);
	ctx.quadraticCurveTo(x + width, y, x + width - radius, y);
}

function squareTopRightCorner(ctx, x, y, width, height, radius) {
	ctx.lineTo(x + width, y);
}

function doRoundedFill(ctx, x, y, width, height, radius, color, corners) {
	doRoundedBorder(ctx, x, y, width, height, radius, corners);
	ctx.fillStyle = color;
	ctx.fill();
}

function doRoundedStroke(ctx, line, x, y, width, height, radius, color, corners) {
	doRoundedBorder(ctx, x, y, width, height, radius, corners);
	ctx.lineWidth = line;
	ctx.strokeStyle = color;
	ctx.stroke();
}

function doRoundedBorder(ctx, x, y, width, height, radius, corners) {
	ctx.beginPath();
	if (corners[0]) {
		ctx.moveTo(x, y + radius);
	} else {
		ctx.moveTo(x, y);
	}
	if (corners[3]) {
		roundBottomLeftCorner(ctx, x, y, width, height, radius);
	} else {
		squareBottomLeftCorner(ctx, x, y, width, height, radius);
	}
	if (corners[2]) {
		roundBottomRightCorner(ctx, x, y, width, height, radius);
	} else {
		squareBottomRightCorner(ctx, x, y, width, height);
	}
	if (corners[1]) {
		roundTopRightCorner(ctx, x, y, width, height, radius);
	} else {
		squareTopRightCorner(ctx, x, y, width, height);
	}
	if (corners[0]) {
		roundTopLeftCorner(ctx, x, y, width, height, radius);
	} else {
		squareTopLeftCorner(ctx, x, y, width, height, radius);
	}
	ctx.closePath();
}

function doArrow(ctx, direction, x, y, w, h) {
	ctx.beginPath();
	switch (direction) {
	  case "UP":
		ctx.moveTo(x + w / 2, y + 0);
		ctx.lineTo(x + w, y + h);
		ctx.lineTo(x + 0, y + h);
		ctx.lineTo(x + w / 2, y + 0);
		break;
	  case "DOWN":
		ctx.moveTo(x + w / 2, y + h);
		ctx.lineTo(x + w, y + 0);
		ctx.lineTo(x + 0, y + 0);
		ctx.lineTo(x + w / 2, y + h);
		break;
	  case "LEFT":
		ctx.moveTo(x + w, y + 0);
		ctx.lineTo(x + 0, y + h / 2);
		ctx.lineTo(x + w, y + h);
		ctx.lineTo(x + w, y + 0);
		break;
	  case "RIGHT":
		ctx.moveTo(x + 0, y + 0);
		ctx.lineTo(x + w, y + h / 2);
		ctx.lineTo(x + 0, y + h);
		ctx.lineTo(x + 0, y + 0);
		break;
	}
	ctx.closePath();
}

function makeCanvas(id) {
    var canvas = document.createElement("canvas");
    canvas.id = id;
    return canvas;
}

function initCanvasFeatures() {
	var divs = document.getElementsByTagName('div');
	
	for(var i = 0; i < divs.length; i++) {
		var canvasName = divs[i].getAttribute('canvas');
		if(canvasName) {
			if(ie) {
				document.write('<canvas id="'+canvasName+'" fg="'+divs[i].id+'"></canvas>'); // doh!
			} else {
				document.body.appendChild(makeCanvas(canvasName));
			}
		}
		var menuName = divs[i].getAttribute('menu');
		if(menuName) {
			if(ie) {
				document.write('<canvas id="'+menuName+'" fg="'+divs[i].id+'"></canvas>'); // doh!
			} else {
				document.body.appendChild(makeCanvas(menuName));
			}
		}
		var popupName = divs[i].getAttribute('popup');
		if(popupName) {
			if(ie) {
				document.write('<canvas id="'+popupName+'" fg="'+divs[i].id+'"></canvas>'); // doh!
			} else {
				document.body.appendChild(makeCanvas(popupName));
			}
		}
	}
}

function MenuBackground(canvas) {
	
	var ctx = canvas.getContext("2d");
	var isCart = eval(canvas.fg.getAttribute("cart"));
	
	var x = 0;
	var y = 0;
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	//var access_order_h = height;
	var bg = branded_colors.brandedmodulebgcolor.background
	
	if(isCart) {
		x = width - cart_w;
		bg = branded_colors.brandedmenushoppingcartbgcolor.background;
		doRoundedFill(ctx, x, y, cart_w, height, radius, bg, roundedBorderTypes.all);
	} else {
		doRoundedFill(ctx, x, y, access_order_w, height, radius, bg, roundedBorderTypes.all);
	}
	
	if(isCart) {
		ctx.drawImage(cartimg,x+cartimg.width+5,height/2-cartimg.height/2);
	} else {
		doLock(ctx,15,13,branded_colors.brandedmenuiconcolor.foreground,branded_colors.brandedmenutickcolor.background);
	}
	
	
	if(isCart) {
		x = 0;
		doRoundedFill(ctx, x, y, width - (cart_w + cart_gutter), height, radius, branded_colors.brandedmenubgcolor.background, roundedBorderTypes.all);
	} else {
		x = access_order_w + access_order_gutter;
		doRoundedFill(ctx, x, y, width - (access_order_w + access_order_gutter), height, radius, branded_colors.brandedmenubgcolor.background, roundedBorderTypes.all);
	}
	
	
}

function doLock(ctx,x,y,fg,bg) {
	// start lock
	var offsetx = x;
	var offsety = y;
	ctx.fillStyle = fg;
	ctx.fillRect(offsetx + 1, offsety, 6, 1);
	ctx.fillRect(offsetx, offsety + 1, 2, 2);
	ctx.fillRect(offsetx + 6, offsety + 1, 2, 2);
	ctx.fillRect(offsetx, offsety + 4, 8, 5);
	ctx.fillRect(offsetx + 1, offsety + 9, 6, 1);
	ctx.fillStyle = bg;
	ctx.fillRect(offsetx + 3, offsety + 7, 2, 1);
	// end lock
}

function ACGradient(canvas) {
	
	var ctx = canvas.getContext("2d");
	var x = 0;
	var y = 0;
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	var fill = "#dddddd";
	var stroke = "#ffffff";
	
	var grad = ctx.createLinearGradient(width/2,y,width/2,90);
	grad.addColorStop(0, fill);
	grad.addColorStop(1,stroke);
	
	doRoundedFill(ctx, x, y, width, 90, radius, grad, roundedBorderTypes.none);
	
}

function getScrollBarWidth () {
	
	var inner = document.createElement('p');
	inner.style.width = "100%";
	inner.style.height = "200px";

	var outer = document.createElement('div');
	outer.style.position = 'absolute';
	outer.style.top = '0px';
	outer.style.left = '0px';
	outer.style.visibility = 'hidden';
	outer.style.width = '200px';
	outer.style.height = '150px';
	outer.style.overflow = 'hidden';
	outer.appendChild (inner);

	document.body.appendChild (outer);
	var w1 = inner.offsetWidth;
	outer.style.overflow = 'scroll';
	var w2 = inner.offsetWidth;
	if (w1 == w2) w2 = outer.clientWidth;
	document.body.removeChild (outer);
	
	return  (w1 - w2);
}

function ZipBorder(canvas) {
	var ctx = canvas.getContext("2d");
	var x = 0;
	var y = 0;
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	var fill = branded_colors.brandedzipbgcolor.background;
	var stroke = branded_colors.brandedheavybottomborder.foreground;
	var bottomWeight = (line * 4) + line;
	
	doRoundedFill(ctx, x, y, width, height, radius, branded_colors.brandedzipbgcolor.background, roundedBorderTypes.all);
	
	doRoundedFill(ctx, x, y, width, 34, radius, branded_colors.brandedmodulebgcolor.background, roundedBorderTypes.top);
	
	
	ctx.beginPath();
	
	ctx.arc(width/2,34, 14, 0, 201,false);
	
	ctx.closePath();
	ctx.fillStyle = branded_colors.brandedmodulebgcolor.background;
	ctx.fill();
	
	doArrow(ctx, "DOWN", width/2-6, 34, 12, 7);
	ctx.fillStyle = branded_colors.brandedmenuiconcolor.foreground;
	ctx.fill();
	
	
	//if(document.all) {
	//	doArrow(ctx, "RIGHT", 6, (y+(height/3)*2)-14, 7, 7);
	//} else {
	//	doArrow(ctx, "RIGHT", 6, (y+(height/3)*2)-19, 7, 7);
	//}
	
	var fullSearch = $('fullSearch');
	doArrow(ctx, "RIGHT", 6, parseInt(fullSearch.offsetTop)+(7/2), 7, 7);
	
	ctx.fillStyle = branded_colors.brandedmenubgcolor.background;
	ctx.fill();
}

function ACHeavyBottom(canvas) {
	var ctx = canvas.getContext("2d");
	var x = 0;
	var y = 0;
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	var fill = branded_colors.brandedheavybottomborder.background;
	var stroke = branded_colors.brandedheavybottomborder.foreground;
	var bottomWeight = (line * 4) + line;
	if (fill) {
		doRoundedFill(ctx, x, y, width, height, radius, stroke, roundedBorderTypes.all);
	}
	if (fill) {
		doRoundedFill(ctx, x, y, width, height - bottomWeight - line, radius, fill, roundedBorderTypes.all);
	}
	if (stroke) {
		doRoundedStroke(ctx, line, x + line, y + line, width - (line * 2), height - (line * 2) - bottomWeight, radius, stroke, roundedBorderTypes.all);
	}
}

function SplashLocationModuleContainer(canvas){
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	var fill = branded_colors.brandedexpressmodulecontainerbackground.background;
	var stroke = '#6F6F6F';
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);

	if(branded_colors.brandedlocationbarborder.background) {
		doRoundedFill(ctx, x, y, width, height, 8, fill, roundedBorderTypes.all);
	}	
	try{
		if(bkImg2){
			if(bkImg2!=null && bkImg1!=""){
				ctx.drawImage(bkImg2,((width/2)-(524/2)-15) , height-30);
			}
		}
	}catch(err){}//no image in CMS, fail gracefully
	try{
		if(bkImg1){
			if(bkImg1!=null && bkImg1!=""){
				var ileft = 30;//default value - do not change
				var itop = 0;//default value - do not change
				try{
					if(img1Top){
						if(img1Top!=null&&img1Top!=""){
							itop = parseInt(img1Top);
						}
					}
					if(img1Left){
						if(img1Left!=null&&img1Left!=""){
							ileft = parseInt(img1Left);
						}
					}
				}catch(err){}
				ctx.drawImage(bkImg1,ileft,itop);
			}
		}
	}catch(err){}//no image in CMS, fail gracefully
	

}
function ExpressLocationModule(canvas){
	var ctx2 = canvas.getContext("2d");
	var x = 0;
	var y = 0;
	
	var fill = branded_colors.brandedexpressmodulebackground.background;	
	var headerBarColor = branded_colors.brandedexpressmoduleheaderbarbackground.background;
	
	//var width = parseInt(canvas.width)-4;
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	
	if(branded_colors.brandedlocationbarborder.background) {
		doRoundedFill(ctx2, x, y, width, height, radius, fill, roundedBorderTypes.all);
	}
	doRoundedFill(ctx2, x+3, y+3, width-6, 34, radius, headerBarColor, roundedBorderTypes.all);
	
}

function ExpressTopPlanPanel(canvas){
	
	var ctx = canvas.getContext("2d");
	var x = 0;
	var y = 0;
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	var orig = "#5F5F5F";
	//var orig = "#CC0000";
	var topColor = orig;//peaked shadow effect
	var gradientOffSetColor = "";
	var r = 0, g = 0, b = 0;
	
	if(topColor.indexOf("#")==0){
		topColor = topColor.substring(1,topColor.length);
		
//		if(topColor.length==3){
//			(topColor+"")+=(topColor+"");
//		}
		r = parseInt(topColor.substring(0,2),16) - 17;
		g = parseInt(topColor.substring(2,4),16) - 17;
		b = parseInt(topColor.substring(4,6),16) - 17;	
		
		if(!isNaN(r) && r<0){
			r = Math.abs(r);
		}
		if(!isNaN(g) && g<0){			
			g = Math.abs(g);			
		}
		if(!isNaN(b) && b<0){
			b = Math.abs(b);
		}
		gradientOffSetColor = "#"+((r>255)?"FF":r.toString(16))+((g>255)?"FF":g.toString(16))+((b>255)?"FF":b.toString(16));		
	}
	
	doRoundedStroke(ctx, 2, x, y, width, height, 10, "#666", roundedBorderTypes.all);
	
	//header
	doRoundedStroke(ctx, 2, x, y, width, 28, 10, "#999", roundedBorderTypes.top);
	doRoundedFill(ctx, x+1, y+1, width-2, 15, 6, orig, roundedBorderTypes.top);
	doRoundedFill(ctx, x+1, y+14, width-2, 15, radius, gradientOffSetColor, roundedBorderTypes.none);
	
	
	//body
	doRoundedFill(ctx, x, y+29, width, height-29, radius, "#E1E1E1", roundedBorderTypes.bottom);
	
	
	doRoundedFill(ctx, x+7, y+34, 235, height-40, radius, "white", roundedBorderTypes.none);
	if(topPlanImg){
		ctx.drawImage(topPlanImg,5,0);
	}
}

function SplashHomeMiniModule(canvas){
	
	var x = 0;
	var y = 0;	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	var ctx = canvas.getContext("2d");
	var headerBKGRNDColor = branded_colors.sh_minimoduleheader.background;
	var headerHeight = 25;
	var contentBKGRNDColor = branded_colors.sh_minimodulebody.background;
	var bottomWeight = 4;
	if (headerBKGRNDColor) {
		doRoundedFill(ctx, x, y, width, headerHeight, radius, headerBKGRNDColor, roundedBorderTypes.top);
		doRoundedFill(ctx, x, y+headerHeight, width, height-headerHeight, radius, contentBKGRNDColor, roundedBorderTypes.bottom);
	}	
}

function LocationBarBorder(canvas) {
	
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	if(branded_colors.brandedlocationbarborder.background) {
		doRoundedFill(ctx, x, y, width, height, radius, branded_colors.brandedlocationbarborder.background, roundedBorderTypes.all);
	}
	
	if(branded_colors.brandedlocationbarborder.foreground) {
		doRoundedStroke(ctx, line, x, y, width, height, radius, branded_colors.brandedlocationbarborder.foreground, roundedBorderTypes.all);
	}
}

function SpecialOffersModuleHeaderBorder(canvas) {
	
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	doRoundedFill(ctx, x, y, width, height, radius, branded_colors.brandedmodulebgcolor.background, roundedBorderTypes.all);
	
	var b_w = 44;
	var b_h = 18;
	
	var numOfButtons = specialOffersLength;
	
	if(numOfButtons > 1) {
		
		var spaceBetweenButtons = 2;
		var arrowWidth = 7;
		var arrowHeight = 7;
		
		var arrowButtonWidth = 24;
		var arrowButtonHeight = 18;
		
		var startButtons = width - ((b_w * numOfButtons) + (spaceBetweenButtons * (numOfButtons-1)) + arrowButtonWidth);
		
		for(var i = 0; i < numOfButtons; i++) {
			var sx = startButtons + (b_w * i);
			if(i > 0) sx += (spaceBetweenButtons * i);
			doRoundedFill(ctx, sx, height / 2 - b_h / 2, b_w, b_h, 2, branded_colors.brandedmenutextcolor.foreground, roundedBorderTypes.all);
		}
		
		doArrow(ctx,"LEFT", startButtons - (arrowButtonWidth/2+arrowWidth/2), height/2-arrowHeight/2, arrowWidth, arrowHeight);
		ctx.fillStyle = branded_colors.brandedmenutextcolor.foreground;
		ctx.fill();
		
		doArrow(ctx,"RIGHT", width - (arrowButtonWidth) + arrowWidth, height/2-arrowHeight/2, arrowWidth, arrowHeight);
		ctx.fillStyle = branded_colors.brandedmenutextcolor.foreground;
		ctx.fill();
	}
}

function SpecialOfferGradient(canvas) {
	
	var ctx = canvas.getContext("2d");
	var x = 0;
	var y = 0;
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	var fill = branded_colors.brandedspecialoffersgradient.background;
	var stroke = branded_colors.brandedspecialoffersgradient.foreground;
	
	var grad = ctx.createLinearGradient(width/2,y,width/2,120);
	grad.addColorStop(0, fill);
	grad.addColorStop(1, stroke);
	
	doRoundedFill(ctx, x, y, width, 120, radius, grad, roundedBorderTypes.bottom);
	
	ctx.drawImage(soimg,0,0);
	
}

function ModuleHeaderBorder(canvas) {
	
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	doRoundedFill(ctx, x, y, width, height, radius, branded_colors.brandedmodulebgcolor.background, roundedBorderTypes.all);

}
function SplashModuleHeaderBorder(canvas) {
	
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	doRoundedFill(ctx, x, y, width, height, radius, branded_colors.brandedsplashmodulebgcolor.background, roundedBorderTypes.all);

}

function ModuleLeftBorder(canvas) {
	
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	doRoundedFill(ctx, x, y, width, height, radius, branded_colors.comparisonmodulebgcolor.background, roundedBorderTypes.left);

}

function ModuleRightBorder(canvas) {
	
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	doRoundedFill(ctx, x, y, width, height, radius, branded_colors.summarymodulebgcolor.background, roundedBorderTypes.right);

}

function ModuleserviceDetailBorder(canvas) {
	
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	doRoundedFill(ctx, x, y, width, height, radius, branded_colors.detailsmodulebgcolor.background, roundedBorderTypes.all);

}

function ModulethankYouBorder(canvas) {
	
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	doRoundedFill(ctx, x, y, width, height, radius, branded_colors.thanksmodulebgcolor.background, roundedBorderTypes.all);

}

function ModuleaddressNormalizeBorder(canvas) {
	
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	doRoundedFill(ctx, x, y, width, height, radius, branded_colors.normalizemodulebgcolor.background, roundedBorderTypes.all);

}

function ModuleXrossBorder(canvas) {
	
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	doRoundedFill(ctx, x, y, width, height, radius, branded_colors.xcrossmodulebgcolor.background, roundedBorderTypes.top);

}



function SubModuleBorder(canvas) {
	
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	doRoundedFill(ctx, x, y, width, height, radius, branded_colors.brandedmenubgcolor.background, roundedBorderTypes.top);
	
}

function TabRoundedTopBorder(canvas) {
	
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	doRoundedFill(ctx, x, y, width, height, radius, branded_colors.brandedtabcolorselected.background, roundedBorderTypes.upperRight);
	
}

function TabBorder(canvas) {
	var selected = eval(canvas.fg.getAttribute('selected'));
	
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	ctx.clearRect(x,y,width,height);
	
	if(!selected) {
		height--;
		doRoundedFill(ctx, x, y, width-1, height, radius, branded_colors.brandedtabcolor.background, roundedBorderTypes.top);
	} else {
		doRoundedFill(ctx, x, y, width-1, height, radius, branded_colors.brandedtabcolorselected.background, roundedBorderTypes.top);
	}
}
function SplashTabDescriptionBorder(canvas) {
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	var greyspace = width - 115;
	
	
	doRoundedFill(ctx, x, y, width, height, radius, branded_colors.brandedtabcomparecolor.background, roundedBorderTypes.top);
	
	
	doRoundedStroke(ctx, line, x, y, width, height+(radius*2), radius, branded_colors.brandedtabcolorselected.background, roundedBorderTypes.top);
	
	doRoundedFill(ctx, x, y, greyspace, height, radius, branded_colors.brandedtabcolorselected.background, roundedBorderTypes.none);
	
	var arrowWidth = 7;
	var arrowHeight = 15;
	
	doArrow(ctx,"RIGHT", greyspace, height/2-arrowHeight/2, arrowWidth, arrowHeight);
	ctx.fillStyle = branded_colors.brandedtabcolorselected.background;
	ctx.fill();
	
}
function TabDescriptionBorder(canvas) {
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	var greyspace = width - 132;
	
	doRoundedFill(ctx, x, y, width, height, radius, branded_colors.brandedtabcomparecolor.background, roundedBorderTypes.top);
	
	
	doRoundedStroke(ctx, line, x, y, width, height+(radius*2), radius, branded_colors.brandedtabcolorselected.background, roundedBorderTypes.top);
	
	doRoundedFill(ctx, x, y, greyspace, height, radius, branded_colors.brandedtabcolorselected.background, roundedBorderTypes.none);
	
	var arrowWidth = 7;
	var arrowHeight = 15;
	
	doArrow(ctx,"RIGHT", greyspace, height/2-arrowHeight/2, arrowWidth, arrowHeight);
	ctx.fillStyle = branded_colors.brandedtabcolorselected.background;
	ctx.fill();
	
}
function SplashTabBottomCapBorder(canvas) {
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	var greyspace = width - 115;
	
	doRoundedFill(ctx, x, y, width, height, radius, branded_colors.brandedtabcomparecolor.background, roundedBorderTypes.bottom);
	
	
	doRoundedStroke(ctx, line, x, y, width, height, radius, branded_colors.brandedtabcolorselected.background, roundedBorderTypes.bottom);
	
	doRoundedFill(ctx, x, y, greyspace, height, radius, branded_colors.brandedtabcolorselected.background, roundedBorderTypes.bottom);
	
	var arrowWidth = 7;
	var arrowHeight = 15;
	
	doArrow(ctx,"RIGHT", greyspace, height/2-arrowHeight/2, arrowWidth, arrowHeight);
	ctx.fillStyle = branded_colors.brandedtabcolorselected.background;
	ctx.fill();
	
}
function TabBottomCapBorder(canvas) {
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	var greyspace = width - 132;
	
	doRoundedFill(ctx, x, y, width, height, radius, branded_colors.brandedtabcomparecolor.background, roundedBorderTypes.bottom);
	
	
	doRoundedStroke(ctx, line, x, y, width, height, radius, branded_colors.brandedtabcolorselected.background, roundedBorderTypes.bottom);
	
	doRoundedFill(ctx, x, y, greyspace, height, radius, branded_colors.brandedtabcolorselected.background, roundedBorderTypes.bottom);
	
	var arrowWidth = 7;
	var arrowHeight = 15;
	
	doArrow(ctx,"RIGHT", greyspace, height/2-arrowHeight/2, arrowWidth, arrowHeight);
	ctx.fillStyle = branded_colors.brandedtabcolorselected.background;
	ctx.fill();
	
}
function SideModuleBackground(canvas){
	var ctx = canvas.getContext("2d");
	var x = 0;
	var y = 0;	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	

	var fill = branded_colors.brandedheavybottomborder.background;
	var stroke = branded_colors.brandedheavybottomborder.foreground;
	var bottomWeight = 4;
	if (fill) {
		doRoundedFill(ctx, x, y, width, height, radius, stroke, roundedBorderTypes.all);
	}
	if (fill) {
		doRoundedFill(ctx, x+1, y+1, width-2, height - bottomWeight - line, radius, fill, roundedBorderTypes.top);
	}	
	doRoundedStroke(ctx,line, x, y, width, height, 10, "#999999", roundedBorderTypes.all);	
}
function SideModuleHeader(canvas){
	var ctx = canvas.getContext("2d");
	var x = 0;
	var y = 0;	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	var fill = branded_colors.sidemoduleheader.background;
	var stroke = branded_colors.sidemoduleheader.foreground;
	var bottomWeight = 4;
	
	var histBoxRad = 8;
	
	if (fill) {
		doRoundedFill(ctx, x, y, width, height, radius, branded_colors.brandedheavybottomborder.foreground, roundedBorderTypes.all);
	}
	if (fill) {
		doRoundedFill(ctx, x+1, y+1, width-2, height - bottomWeight - line, radius, fill, roundedBorderTypes.top);
	}
	if (stroke) {
		doRoundedStroke(ctx,line, x, y, width, height, 10, "#999999", roundedBorderTypes.all);
		doRoundedFill(ctx, x, y, width, 26, radius, stroke, roundedBorderTypes.top);	
	//	doRoundedStroke(ctx,line, x, y, width, 26, 15, stroke, roundedBorderTypes.top);
	}		
}
function PromoModuleHeader(canvas){
	var ctx = canvas.getContext("2d");
	var x = 0;
	var y = 0;	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	var fill = branded_colors.promomoduleheader.background;
	var stroke = branded_colors.promomoduleheader.foreground;
	var bottomWeight = 4;
	
	var histBoxRad = 8;
	
	if (fill) {
		doRoundedFill(ctx, x, y, width, height, radius, branded_colors.brandedheavybottomborder.foreground, roundedBorderTypes.all);
	}
	if (fill) {
		doRoundedFill(ctx, x+1, y+1, width-2, height - bottomWeight - line, radius, fill, roundedBorderTypes.top);
	}
	if (stroke) {
		doRoundedStroke(ctx,line, x, y, width, height, 10, "#999999", roundedBorderTypes.all);
		doRoundedFill(ctx, x, y, width, 20, radius, stroke, roundedBorderTypes.top);	
	//	doRoundedStroke(ctx,line, x, y, width, 26, 15, stroke, roundedBorderTypes.top);
	}		
}
function acctStatBox(canvas){
	var ctx = canvas.getContext("2d");
	var x = 0;
	var y = 0;	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	var fill = branded_colors.brandedheavybottomborder.background;
	var stroke = '#DDDDDD';
	var bottomWeight = 28;
	if (fill) {
		doRoundedFill(ctx, x, y, width, height, radius, stroke, roundedBorderTypes.all);
	}
	if (fill) {
		doRoundedFill(ctx, x+4, y, width-8, height - bottomWeight - line, radius, fill, roundedBorderTypes.top);
	}
	if (stroke) {
		doRoundedStroke(ctx, line, x + line, y + line, width - (line * 2), height - (line * 2) - bottomWeight, radius, stroke, roundedBorderTypes.all);
		doRoundedFill(ctx, x, y, width, 26, 15, stroke, roundedBorderTypes.top);	
		doRoundedStroke(ctx,line, x, y, width, 26, 15, stroke, roundedBorderTypes.top);
	}		
}
function acctHistBox(canvas){
	var ctx = canvas.getContext("2d");
	var x = 0;
	var y = 0;	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	var fill = branded_colors.brandedheavybottomborder.background;
	var stroke = '#DDDDDD';
	var bottomWeight = 4;
	
	var histBoxRad = 8;
	
	if (fill) {
		doRoundedFill(ctx, x, y, width, height, histBoxRad, stroke, roundedBorderTypes.top);
	}
	if (fill) {
		doRoundedFill(ctx, x+4, y, width-8, height - bottomWeight - line, radius, fill, roundedBorderTypes.top);
	}
	if (stroke) {
		doRoundedStroke(ctx, line, x + line, y + line, width - (line * 2), height - (line * 2) , histBoxRad, stroke, roundedBorderTypes.top);
		doRoundedFill(ctx, x, y, width, 26, histBoxRad, stroke, roundedBorderTypes.top);	
	//	doRoundedStroke(ctx,line, x, y, width, 26, 15, stroke, roundedBorderTypes.top);
	}		
}

function acctMainBox(canvas){
	var ctx = canvas.getContext("2d");
	var x = 0;
	var y = 0;	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	ACHeavyBottom(canvas);	
	doRoundedFill(ctx, x, y, width, 34, 10, "#eeeeee", roundedBorderTypes.top);	
	doRoundedStroke(ctx,line, x, y, width, 34, 10, "#999999", roundedBorderTypes.top);	
}

function CorpSideMenu(canvas){
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;	
	
	var arrowWidth= 6;
	var arrowHeight= 6;
	var arrowX = 20;
	var arrowY =47;
	var arrowColor = branded_colors.brandedmenutickcolor.background;
	var activatedColor = "black";
	
	var num=0;
	
	var activatedElem = currentCorpPage-1;
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	ACHeavyBottom(canvas);
	
	doRoundedFill(ctx, x, y, width, 34, radius, branded_colors.brandedmenubgcolor.background, roundedBorderTypes.top);
	
	
//	for (num = 0; num < 9; num++) {
//		doArrow(ctx, "RIGHT", arrowX, arrowY, arrowWidth, arrowHeight);
//		
//		(num == activatedElem)?ctx.fillStyle = activatedColor:ctx.fillStyle = arrowColor;		
//		ctx.fill();
//		arrowY = arrowY + 24;		
//	}
	navElem = $('corpNavContent').childNodes;
	
	doRoundedFill(ctx, x, y, width, 34, radius, branded_colors.brandedmenubgcolor.background, roundedBorderTypes.top);
//	for (num = 0; num < navElem.length; num++) {
//		
//		var curleft = curtop = 0;
//		var divCP = navElem[num];
//		
//		do{
//			curleft += divCP.offsetLeft;
//			curtop += divCP.offsetTop;
//		}while(divCP = divCP.offsetParent);		
//		curtop -= (ie)? 100:114; //TODO: research this unknown offset		
//		doArrow(ctx, "RIGHT", arrowX, curtop, arrowWidth, arrowHeight);
//		
//		ctx.fillStyle = (num == activatedElem)? activatedColor:arrowColor;		
//		ctx.fill();
//	}
}

function ModuleProviderBorder(canvas){
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;	
	
	var num=0;
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	ACHeavyBottom(canvas);
	
	doRoundedFill(ctx, x, y, width, 34, radius, "#999999", roundedBorderTypes.top);

	
}

function CartSummaryModule(canvas){
	var ctx = canvas.getContext("2d");
	var x = 0;
	var y = 0;	
	var width = parseInt(canvas.width);
	var rightHandWidth = 100;
	
	var height = parseInt(canvas.height);
	var rightHandHeight = height - 2;
	
	var rightHandX = width-(rightHandWidth+1);
	var rightHandY = 1;

	var fill = branded_colors.brandedheavybottomborder.background;
	var stroke = branded_colors.brandedheavybottomborder.foreground;
	//var fill = "white";
	//var stroke = "#e1e1e1";
	var rightHandStroke = "#f3f3f3";
	var bottomWeight = 2;
	
	//outline
	if (fill) {
		doRoundedFill(ctx, x, y, width, height, radius+10, stroke, roundedBorderTypes.all);
	}
	//interior
	if (fill) {
		doRoundedFill(ctx, x+1, y+1, rightHandX-2, height - bottomWeight - line, radius+10, fill, roundedBorderTypes.lowerLeft);
	}	
	//top
	doRoundedFill(ctx, x, y, width, 34, radius+10, "#e1e1e1", roundedBorderTypes.top);
	//rightHand
	doRoundedFill(ctx, rightHandX, rightHandY, rightHandWidth, rightHandHeight, radius+10, rightHandStroke, roundedBorderTypes.right);
	
}

function ModuleSumRightBorder(canvas){
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;	
	
	var num=0;
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	ACHeavyBottom(canvas);
	
	doRoundedFill(ctx, x, y, width, 34, radius, branded_colors.summarymodulebgcolor.background, roundedBorderTypes.right);

	
}
function HeaderBar(canvas){
	var ctx = canvas.getContext("2d");
	var x = 0;
	var y = 0;	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	var radius = 5;	
	//branded_colors.brandedmenubgcolor.background
	doRoundedFill(ctx, x, y, width, height, radius,"#444" , roundedBorderTypes.all);	
}
function ModuleInvalidCartItemsBorder(canvas) {
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;	
	
	var num=0;
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	ACHeavyBottom(canvas);
	
	doRoundedFill(ctx, x, y, width, 34, radius, branded_colors.invalidcartitemmodulebgcolor.background, roundedBorderTypes.top);
}

function SideMenu(canvas){
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;	
	
	var arrowWidth= 6;
	var arrowHeight= 6;
	var arrowX = 20;
	var arrowY =47;
	var arrowColor = branded_colors.brandedmenutickcolor.background;
	var activatedColor = "black";
	
	var num=0;
	
	var activatedElem = currentHelpPage-1;
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	ACHeavyBottom(canvas);
	
	navElem = $('helpNavContent').childNodes;
	
	doRoundedFill(ctx, x, y, width, 34, radius, branded_colors.brandedmenubgcolor.background, roundedBorderTypes.top);
	for (num = 0; num < navElem.length; num++) {
		
		var curleft = curtop = 0;
		var divCP = navElem[num];
		
		do{
			curleft += divCP.offsetLeft;
			curtop += divCP.offsetTop;
		}while(divCP = divCP.offsetParent);		
		curtop -= (ie)? 101:113; //TODO: research this unknown offset		
		doArrow(ctx, "RIGHT", arrowX, curtop, arrowWidth, arrowHeight);
		
		ctx.fillStyle = (num == activatedElem)? activatedColor:arrowColor;		
		ctx.fill();
	}
}

function menubarTrigger(canvas, action) {
	var ctx = canvas.getContext("2d");
	var x = 0;
	var y = 0;
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	var fill = branded_colors.brandedmenuitembgcolor.background;
	
	switch(action) {
		case 'true':
			ctx.clearRect(x, y, width, height);
			doRoundedFill(ctx, x, y, width, height-9, radius, fill, roundedBorderTypes.all);
			canvas.fg.style.color = branded_colors.brandedmenubgcolor.background;
			if (canvas.fg.firstChild && canvas.fg.firstChild.style)
				canvas.fg.firstChild.style.color = branded_colors.brandedmenubgcolor.background;
			break;
		case 'false':
			ctx.clearRect(x, y, width, height);
			canvas.fg.style.color = branded_colors.brandedmenuitembgcolor.background;
			if (canvas.fg.firstChild && canvas.fg.firstChild.style)
				canvas.fg.firstChild.style.color = branded_colors.brandedmenuitembgcolor.background;
			break;
		default:
			ctx.clearRect(x, y, width, height);
			doRoundedFill(ctx, x, y, width, height, radius, fill, roundedBorderTypes.top);
			canvas.fg.style.color = branded_colors.brandedmenubgcolor.background;
			if (canvas.fg.firstChild && canvas.fg.firstChild.style)
				canvas.fg.firstChild.style.color = branded_colors.brandedmenubgcolor.background;
			break;
	}
	
	doArrow(ctx, "DOWN", 6, 10, 7, 4);
	ctx.fillStyle = branded_colors.brandedmenutickcolor.background;
	ctx.fill();

}

function menubarItem(canvas,highlighted) {
	var ctx = canvas.getContext("2d");
	var x = 0;
	var y = 0;
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	ctx.fillStyle = branded_colors.brandedmenubgcolor.background;
	ctx.fillRect(x,y,width,height);
	
	if(highlighted) {
		ctx.fillStyle = branded_colors.brandedmodulebgcolor.background; 
	} else {
		ctx.fillStyle = branded_colors.brandedmenuitembgcolor.background;
	}
	
	ctx.fillRect(x+menuLine,y,width-(menuLine*2),height-menuLine/2);
	
	menubarItemSelected(canvas,ctx,highlighted);
}

function menubarLastItem(canvas,highlighted) {
	
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	var stroke = branded_colors.brandedmenubgcolor.background;
	var fill = branded_colors.brandedmenuitembgcolor.background;
	
	if(highlighted) {
		fill = branded_colors.brandedmodulebgcolor.background;
	}
	
	doRoundedFill(ctx, x + menuLine/2, y, width - menuLine, height - menuLine, radius, fill, roundedBorderTypes.bottom);
	doRoundedStroke(ctx, menuLine, x + menuLine/2, y - menuLine*2, width - (menuLine), height + menuLine, radius, stroke, roundedBorderTypes.bottom);
	
	menubarItemSelected(canvas,ctx,highlighted);
}


function menubarItemSelected(canvas,ctx,highlighted) {

	var div = canvas.fg;
	var selected = div.getAttribute("selected");
	
	if(selected && selected == 'true') {
		
		var fill1 = branded_colors.brandedmenutickcolor.background;
		
		if(highlighted) {
			fill1 = branded_colors.brandedmenuitembgcolor.background;
		}
		
		ctx.fillStyle = fill1;
		drawCircle(ctx, parseInt(canvas.width)-12, 11, 7);
		ctx.fill();
		
		var fill2 = branded_colors.brandedmenuitembgcolor.background;
		
		if(highlighted) {
			fill2 = branded_colors.brandedmenutickcolor.background;
		}
		
		ctx.fillStyle = fill2;
		drawCheck(ctx, parseInt(canvas.width)-17.5, 7, 10, 8);
		ctx.fill();
		
	}
}

function drawCircle(ctx, x, y, r) {
	var degrees = 201;
	ctx.beginPath();
	ctx.arc(x,y,r,0,degrees,false);
	ctx.closePath();
}

function drawCheck(ctx, x, y, w, h) {
	ctx.beginPath();
	
	ctx.moveTo(x+1,y+h/2);
	ctx.lineTo(x+w/2,y+h);
	ctx.lineTo(x+w,y);
	ctx.lineTo(x+w-2,y);
	ctx.lineTo(x+w/2,y+h-3);
	ctx.lineTo(x+2,y+h/2-2);
	
	ctx.closePath();	
}

var menubar_trigger = new Object();

function addMenubarTrigger(trigger) {
	var menu_id = trigger.getAttribute("menu");
	if(!menubar_trigger[menu_id]) {
		menubar_trigger[menu_id] = trigger;
	}
}

/**
	Fly in the menu items since we have no clue as to where
	they have been placed.
*/
function doMenubarTriggerPositioning() {
	
	var tmp = new Array();
	
	for(var i in menubar_trigger) {
		if(typeof menubar_trigger[i] == 'object') {
			tmp[tmp.length] = menubar_trigger[i];
		}
	}
	
	var menubarbg = $('menubarbg');
	
	if(!menubarbg) return;
	
	var isCart = eval(menubarbg.getAttribute("cart"));
	
	var x = parseInt(menubarbg.offsetLeft);
	var y = parseInt(menubarbg.offsetTop);
	var width = parseInt(menubarbg.offsetWidth);
	var height = parseInt(menubarbg.offsetHeight);
	
	width = width - (access_order_w + access_order_gutter + menu_offset_x + parseInt(tmp[0].offsetWidth)); // the access my order or cart width
	
	var spacing = width / tmp.length;
	
	for(var i = 0; i < tmp.length; i++) {
		
		var parent = tmp[i].parentNode;
		var iwidth = parseInt(tmp[i].offsetWidth);
		
		var ox = 0;
		
		if(isCart) {
			if(i == 0) {
				ox = x + menu_offset_x;
			} else {
				ox = x+(spacing*i) + (parseInt(tmp[0].offsetWidth)/2) - parseInt(tmp[i].offsetWidth)/2;
			}
			
			if(i == 0) {
				ox = x + menu_offset_x;
			}  else {
				ox = x + (menu_offset_x + (parseInt(tmp[0].offsetWidth)/2)) + (spacing*i) - parseInt(tmp[i].offsetWidth)/2;
				ox += menu_offset_x; // hack to fix the spacing...
			}
		} else {
			if(i == 0) {
				ox = x + (access_order_w + access_order_gutter + menu_offset_x);
			}  else {
				ox = x + (access_order_w + access_order_gutter + menu_offset_x + (parseInt(tmp[0].offsetWidth)/2)) + (spacing*i) - parseInt(tmp[i].offsetWidth)/2;
				ox += menu_offset_x; // hack to fix the spacing...
			}
		}
		
		parent.style.left = ox;
		parent.style.top = y + menu_item_offset_y;
		
		doMenubarChildPlacement(parent);
		
		last_item = tmp[i];
		parent.style.visibility = 'visible';
	}
	
	
}

function findSpacing(triggers,triggerIndex) {
	
	var menubarbg = $('menubarbg');
	var width = parseInt(menubarbg.offsetWidth);
	width = width - (access_order_w + access_order_gutter + menu_offset_x);
	
	var first = triggers[0];
	var last = triggers[triggers.length-1];
	
	
	width = width - parseInt(first.offsetWidth) - parseInt(last.offsetWidth);
	
	return width / (triggers.length-3);
}

function doMenubarChildPlacement(parent) {
	for(var j = 0; j < parent.childNodes.length; j++) {
		var child = parent.childNodes[j];
		if(child.bg) {
			child.bg.style.left = parseInt(parent.offsetLeft) + parseInt(child.offsetLeft);
			child.bg.style.top = parseInt(parent.offsetTop) + parseInt(child.offsetTop);
		}
	}
}

function initCanvases( ) {
	/**
		Find the colors sheet
	*/
	if(branded_colors.pop) {
		for(var i = 0; i < document.styleSheets.length; i++) {
			
			var stylesheet = document.styleSheets[i];
			
			if(stylesheet.href != null && stylesheet.href.indexOf('branded-colors.css') != -1) {
				
				var rules = null;
				
				if(document.all) {
					rules = stylesheet.rules;
				} else {
					rules = stylesheet.cssRules;
				}
				
				for(var j = 0; j < rules.length; j++) {
					if(rules[j].selectorText) {
						
						var newRule = new Object();
						
						if(rules[j].style.background) {
							newRule.background = rules[j].style.background;
						}
						
						if(rules[j].style.backgroundColor) {
							newRule.background = rules[j].style.backgroundColor;
						}
						
						if(rules[j].style.color) {
							newRule.foreground = rules[j].style.color;
						}
						
						if(rules[j].style.borderColor) {
							newRule.borderColor = rules[j].style.borderColor;
						}
						
						branded_colors[rules[j].selectorText.substring(1).toLowerCase()] = newRule;
					}
				}
				branded_colors.pop = false;
				//break;
			}
		}
	}
	
	var divs = document.getElementsByTagName('div');
	var menuItemCount = 0;
	
	var winW = 630, winH = 460;
	
//	if (parseInt(navigator.appVersion) > 3) {
//		if (navigator.appName=="Netscape") {
//			winW = parseInt(window.innerWidth);
//			winH = parseInt(window.innerHeight);
//		}
//		if (navigator.appName.indexOf("Microsoft")!=-1) {
//			winW = parseInt(document.body.offsetWidth)-5; // IE SUX!
//			winH = parseInt(document.body.offsetHeight);
//		}		
//		winW -= getScrollBarWidth();
//	}	
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		winW = parseInt(document.body.offsetWidth)-5; // IE SUX!
		winH = parseInt(document.body.offsetHeight);
		winW -= getScrollBarWidth();
	}else{
		winW = document.viewport.getWidth();
		winH = document.viewport.getHeight();		
	}
	
	for(var i = 0; i < divs.length; i++) {
		
		var div = divs[i];
		var canvasName = div.getAttribute('canvas');
		
		
		if(canvasName) {
		
			var canvas = $(canvasName);
			
			canvas.fg = div;
			div.bg = canvas;
			
			div.style.position = 'relative';
			div.style.zIndex = 2;
			
			var type = div.getAttribute('type');
			
			/**
			 * THIS IS A POSITIONING FIX. DO NOT CHANGE THE LOGIC AS AWKWARD AS IT MAY SEEM.
			 * 
			 * ---------DO NOT EDIT!!-------------------------------------------------------
			 */
				//get correct left and top
				var curleft = curtop = 0;
				var divCP = div; 
				do{
					curleft += divCP.offsetLeft;
					curtop += divCP.offsetTop;
				}while(divCP = divCP.offsetParent);
			/**
			 * ---------END------------------------------------------------------------------
			 */
				
				
			// Special case for Allconnect Gradient!
			if(type != 'ACGradient') {
				canvas.width = parseInt(div.offsetWidth);
				//canvas.style.left = parseInt(div.offsetLeft);
				canvas.style.left = curleft;
			}else {
				canvas.width = winW;
				canvas.style.left = 0;
			}
			
			canvas.height = parseInt(div.offsetHeight);
			//canvas.style.top = parseInt(div.offsetTop);
			canvas.style.top = curtop;
			
			var func = eval(type);
			func(canvas);
			
			canvas.style.position = 'absolute';
			canvas.style.zIndex = 1;
			
			canvas.style.visibility = 'visible';
			canvas.style.display = 'block';
		}
		
		var menu = div.getAttribute('menu');
		
		if(menu) {
		
			var canvas = $(menu);
			canvas.fg = div;
			div.bg = canvas;
			div.style.color = branded_colors.brandedmenubgcolor.background;
			if (div.firstChild && div.firstChild.style)
				div.firstChild.style.color = branded_colors.brandedmenubgcolor.background;
			
			div.style.position = 'relative';
			div.style.zIndex = 9;
			
			div.parentNode.zIndex = 9;
			
			canvas.width = parseInt(div.offsetWidth);
			canvas.height = parseInt(div.offsetHeight);
			
			var func = eval(div.getAttribute('type'));
			
			canvas.style.position = 'absolute';
			canvas.style.zIndex = 3;
			
			if(div.className.indexOf('menuTrigger') == -1) {
				canvas.style.visibility = 'hidden';
				canvas.style.display = 'none';
				func(canvas);
			} else {
				addMenubarTrigger(div);
				canvas.style.visibility = 'visible';
				canvas.style.display = 'block';
				var selected = div.getAttribute('selected');
				func(canvas,selected);
			}
			
			canvas.style.left = parseInt(div.parentNode.offsetLeft) + parseInt(div.offsetLeft);
			canvas.style.top = parseInt(div.parentNode.offsetTop) + parseInt(div.offsetTop);
			
			if(div.className.indexOf('menuTrigger') > -1) {
				canvas.style.visibility = 'visible';
				canvas.style.display = 'inline';
				div.style.visibility = 'visible';
				div.style.display = 'inline';
			}
			
			if(div.parentNode.style.display == 'none') {
				div.parentNode.style.visibility = 'visible';
				div.parentNode.style.display = 'block';
			}
			
		}
		
		if(first_run) {
			
			var popup = div.getAttribute('popup');
			
			if(popup) {
			
				var canvas = $(popup);
				canvas.fg = div;
				div.bg = canvas;
				
				//div.style.position = 'relative';
				div.style.zIndex = 20;
				
				var type = div.getAttribute('type');
				
				canvas.width = parseInt(div.offsetWidth);
				canvas.style.left = parseInt(div.offsetLeft);
				
				canvas.height = parseInt(div.offsetHeight);
				canvas.style.top = parseInt(div.offsetTop);
				
				canvas.style.position = 'absolute';
				canvas.style.zIndex = 19;
				
				canvas.style.visibility = 'hidden';
				canvas.style.display = 'none';
				
				div.style.visibility = 'hidden';
				div.style.display = 'none';
				
				
				var func = eval(type);
				func(canvas);
				
			}
		}
	}
	
	doMenubarTriggerPositioning();
	first_run = false;
}

function menuItemMouse(div,highlight) {
	var canvas = div.bg;
	if(highlight) {
		div.style.color = branded_colors.brandedmenuitembgcolor.background;
		if (div.firstChild && div.firstChild.style)
			div.firstChild.style.color = branded_colors.brandedmenuitembgcolor.background;
		var func = eval(div.getAttribute('type'));
		func(canvas,true);
		showHelper(div.parentNode,false);
	} else {
		div.style.color = branded_colors.brandedmenubgcolor.background;
		if (div.firstChild && div.firstChild.style)
			div.firstChild.style.color = branded_colors.brandedmenubgcolor.background;
		var func = eval(div.getAttribute('type'));
		func(canvas,false);
	}
}

function showMenu(menuPullDown) {
	
	for(var i = 0; i < menuPullDown.childNodes.length; i++) {
		if(menuPullDown.childNodes[i].style) {
			if(menuPullDown.childNodes[i].className.indexOf('menuTrigger') != -1) {
				menubarTrigger(menuPullDown.childNodes[i].bg);
				showHelper(menuPullDown,false);
			} else {
				menuPullDown.childNodes[i].style.visibility = 'visible';
				
				/*
				
				IE
				
				if(ie) {
					//$(CART_IE_HACK).style.position = 'relative';
					//$(CART_IE_HACK).style.left = CART_IE_HACK_VALUE;
					menuPullDown.childNodes[i].style.display = 'block';
				}
				*/
				
				
				menuPullDown.childNodes[i].bg.style.visibility = 'visible';
				menuPullDown.childNodes[i].bg.style.display = 'block';
			}
		}
	}
}

function showHelper(div,hide) {
	if(hide) {
		if(div.showHideHelper) {
			window.clearTimeout(div.showHideHelper);
		}
		div.showHideHelper = window.setTimeout("doHideMenu('"+div.id+"')",menuPopoutDelay);
	} else {
		window.clearTimeout(div.showHideHelper);
		div.showHideHelper = null;
	}
}

var CART_IE_HACK_VALUE = 0;

function doHideMenu(menuPullDown) {
	if(menuPullDown) {
		menuPullDown = $(menuPullDown);
		for(var i = 0; i < menuPullDown.childNodes.length; i++) {
			if(menuPullDown.childNodes[i].style) {
				if(menuPullDown.childNodes[i].className.indexOf('menuTrigger') != -1) {
					menubarTrigger(menuPullDown.childNodes[i].bg, menuPullDown.childNodes[i].getAttribute('selected'));
				} else {
					menuPullDown.childNodes[i].style.visibility = 'hidden';
					/*
					if(ie) {
						//$(CART_IE_HACK).style.position = 'relative';
						//$(CART_IE_HACK).style.left = CART_IE_HACK_VALUE;
						
						alert(menuPullDown.id);
						
						menuPullDown.childNodes[i].style.display = 'none';
					}
					*/
					menuPullDown.childNodes[i].bg.style.visibility = 'hidden';
					menuPullDown.childNodes[i].bg.style.display = 'none';
					
				}
			}
		}
		//menuPullDown.style.height = menuPullDown.childNodes[0].offsetHeight;
	}
}


function buildMenu() {
	
	var str = '';
	
	
	for(var i = 0; i < menubar_data.length; i++) {
		if(menubar_data.length-1 == i) {
			str += generatePullDownMenubar(menubar_data[i],true);
		} else {
			str += generatePullDownMenubar(menubar_data[i],false);
		}
	}
	document.write(str);
	return str;
}

function generatePullDownMenubar(menubarItem,end) {
	
	var str = '';
	
	if(end) {
		str += '<div class="menuPullDown" id="'+menubarItem.id+'" onmouseout="showHelper(this,true)" style="text-align: right;">';
	} else {
		str += '<div class="menuPullDown" id="'+menubarItem.id+'" onmouseout="showHelper(this,true)">';
	}
	
	str += '<div menu="'+menubarItem.id+'Trigger" class="menuTrigger menuItem" type="menubarTrigger" selected="'+menubarItem.selected+'" onmouseover="showMenu(this.parentNode)" ';
	str += 'onclick="window.location = \''+menubarItem.triggerUrl+'\'">';
	str += menubarItem.title;
	str += '</div>';
	
	for(var i = 0; i < menubarItem.sub.length; i++) {
		str += '<div menu="'+(menubarItem.id+i)+'" onmouseover="menuItemMouse(this,true)" onmouseout="menuItemMouse(this,false);" ';
		str += 'onclick="window.location = \''+menubarItem.sub[i].url+'\'" ';
		
		if(i == 0) {
			str += 'class="menuItem menuItemTopMargin" ';
		} else {
			str += 'class="menuItem" ';
		}
		
		if(i >= menubarItem.sub.length-1) {
			str += 'type="menubarLastItem" ';
		} else {
			str += 'type="menubarItem" ';
		}
		
		str += 'selected="'+menubarItem.sub[i].selected+'">';
		str += menubarItem.sub[i].title;
		str += '</div>';
	}
	
	str += '</div>';
	
	return str;
}

function InWindowPopup(canvas) {
	
	var ctx = canvas.getContext("2d");
	
	var x = 0;
	var y = 0;
	
	var width = parseInt(canvas.width);
	var height = parseInt(canvas.height);
	
	var fill = branded_colors.brandedmenubgcolor.background;
	var stroke = branded_colors.brandedmenubgcolor.background;
	var white = '#ffffff';
	
	doRoundedFill(ctx, x, y, width, height, radius, white, roundedBorderTypes.all);
	doRoundedStroke(ctx, line, x, y, width, height, radius, stroke, roundedBorderTypes.all);
	doRoundedFill(ctx, x, y, width, 34, radius, fill, roundedBorderTypes.top);
}

var ie = document.all;

var branded_colors = new Object();
branded_colors.pop = true;

var menuPopoutDelay = 50;
var line = 0.5;
var menuLine = 2;
var radius = 5;

var access_order_w = 150;
var access_order_gutter = 8;

var cart_w = 160;
var cart_gutter = 3;

var menu_offset_x = 15;

var menu_item_offset_x = 45;
var menu_item_offset_y = 9;
var menu_start_x = 0;
var menu_start_y = 0;
var menu_item_spacing = 15;

var scrollbar_width = -1;

var first_run = true;
 
insertOnLoadFunction('initCanvases()');
