
/* Dart utilities */
var DartUtils = (function() {
	taken = false;
	return {
		isTakeover : function() {
			return taken;
		},
		feature: function(image, clickthru, options) {
			if(window.location.pathname == "/") {
				var sw = "";
				var injectStr = "";
				onClickURL = clickthru;
				var sf = document.getElementById("specialFeature");
			
				if (typeof options == "object") {
					if(options.sameWindow == false) { sw = 'target="_blank" '; }
					if(options.noClick == true) { sw = ""; onClickURL = "#"; }
				}

				injectStr += '<a ' + sw + 'href="' + onClickURL + '">';
				injectStr += '<img src="' + image + '" />';
				injectStr += '</a>';
			
				sf.innerHTML = injectStr;
				sf.style.display = "block";
			}
		},
		takeover : function(image, clickthru, options) {
			taken = true;
			var main = document.getElementsByTagName("html")[0];
			main.style.background = 'url("'+image+'") no-repeat center top';

			if (typeof options == "object" && options.fixedBg) {
				main.style.backgroundAttachment = 'fixed';
			}

			if (typeof options == "object" && options.bgcolor) {
				main.style.backgroundColor = options.bgcolor;
			}

			if (typeof options == "object" && options.branded) {
				main.setAttribute('branded', options.branded);
			}
			//
			// Move the header in 
			//
			
			var html_logo = document.getElementById("Logo");
			html_logo.style.margin = "0 0 0 10px";

			//var html_header_search = document.getElementById("HeaderSearch");
			//html_header_search.style.margin = "15px 20px";

			//var html_account = document.getElementById("Account");
			//html_account.style.margin = "15px 10px 0 0";
			


			//
			// If there is a takeover Banner
			//
			if (typeof options == "object" && options.takeoverBanner) {
				var a = document.createElement("a");
				a.href = clickthru;
				a.target = "_blank";
				a.style.display = "block";
				a.style.height = "130px";

				document.getElementById("takeOverFun").appendChild(a);

				var html_wrapper = document.getElementById("Wrapper");
				html_wrapper.style.padding = "15px 0 0 0";
			}

			var launchWindow = function(e) {
				if(typeof e.pageX == "number" && typeof window.innerWidth == "number") {
					if(e.pageX < window.innerWidth-18) {
						window.open(clickthru);
					}
				} else {
					window.open(clickthru);
				}
			}

			var theRest = document.getElementsByTagName('html')[0].childNodes;
			var browserName=navigator.appName; 
			var crackedBrandedBox = document.getElementById('brandedBlip');

			//Microsoft attactEvent and disable propagation
			if( browserName.match(/microsoft/gi) ) {
				main.attachEvent('onclick', launchWindow);
				main.attachEvent('onmouseover', function(e){ main.style.cursor = 'pointer'});
				for(var i = 0; i < theRest.length; i++) {
					theRest[i].attachEvent('onmouseover', function(e){
						document.getElementsByTagName("body")[0].style.cursor = "default";
					});
					theRest[i].attachEvent('onclick',function(e){ 
						e.cancelBubble = true;
					});
					
				}
				//Cracked Branded Featured spot is clickable
				crackedBrandedBox.attachEvent('onclick', launchWindow);
			}
			//Every other browser, addEventListener and disable propagation
			else {
				main.addEventListener('click', launchWindow, false);
				main.addEventListener('mouseover', function(e){ main.style.cursor = 'pointer'}, false);
				for(var i = 0; i < theRest.length; i++) {
					theRest[i].addEventListener('mouseover', function(e){
						document.getElementsByTagName("body")[0].style.cursor = "default";
					}, false);
					theRest[i].addEventListener('click',function(e){ 
						e.stopPropagation(); 
						return(false); 
					} , false);
				}
				//Cracked Branded Featured spot is clickable
				crackedBrandedBox.addEventListener('click', launchWindow, false);

				
			}
			
			

		}

	};
})();
