
(function () { eval(JELLY.local); // START Closure


/*------------------------------------------------------------------------- Search Text Input ---*/
var inputReplace = function (element, defaultText) {
	if (!element) return;
	var firstPass = true;
	element.onfocus = function () {
		if (this.value === defaultText) {
			this.value = '';
		}	
	};
	element.onblur = function () {
		if (/^\s*$/.test(this.value) || this.value === defaultText || firstPass) {
			this.value = defaultText;
			firstPass = false;
		} 
	};
	element.onblur();
};

var siteSearch = Q('#header-site-search input[type=text]');
if (siteSearch) { 
	inputReplace(siteSearch[0], siteSearch[0].parentNode.getElementsByTagName('span')[0].innerHTML.trim());
}

/*------------------------------------------------------------------------- Dropdown nav ---*/
var dropDowns = Q('#nav-1 li');
if (browser.ie6 && dropDowns) {
	var ie6_navEventHandler = function (e) {
		var div = this.getElementsByTagName('div');	
		if (div[0]) {
			if (e.type === 'mouseover') { 
				div[0].style.display = 'block';
				this.style.zIndex = 100;
			} else {
				div[0].style.display =
				this.style.zIndex = '';
			}
		}
	};
	dropDowns.each(function (item) {
		addEvent(item, 'mouseenter', ie6_navEventHandler);
		addEvent(item, 'mouseleave', ie6_navEventHandler);
	});
}

/*------------------------------------------------------------------------- Flash Text ---*/
var createFlashHtml = function (text, opts) {
	opts = opts || {};
	var template = '<textformat leading="{leading}"><p align="{align}"><font color="{color}" ' + 
		'size="{size}">{text}</font></p></textformat>';		
	return template.
		replace(/{text}/, text).
		replace(/{leading}/, opts.leading || '-1').
		replace(/{align}/, opts.align || 'left').
		replace(/{color}/, opts.color || '').
		replace(/{size}/, opts.size || '');
};

var flashReplacement = function () {
	var titles = Q('#content .flash-text');
	for (var i = 0; i < titles.length; i++) {
		var title = titles[i],
			height = title.offsetHeight,
			html = title.innerHTML.trim(),
//			color = ('rgb(' + getStyle(title, 'color', false) + ')').cssRgbToHex(),
			color = str.parseColour(getStyle(title, 'color', false), 'hex'),
			align = getStyle(title, 'text-align', false) === 'right' ? 'right' : 'left',
			width = '100%',
			htmlString;
		title.style.padding = '0';
		title.style.height = height + 'px';
		title.style.visibility = 'hidden';
		
		
		if (/p/i.test(title.nodeName) && hasClass(title, 'cta')) {
			html = createFlashHtml(html, {
				color: color,
				align: align,
				size: 16
			});			
		} else if (/h(1|2)/i.test(title.nodeName)) {
			html = createFlashHtml(html, {
				color: color,
				align: align,
				size: 20
			});	
		} else if (/h3/i.test(title.nodeName)) {
			html = createFlashHtml(html, {
				color: color,
				align: align,
				size: 16
			});	
		} else {
			html = createFlashHtml(html, {
				color: color,
				align: align,
				size: 14
			});	
		}
		title.innerHTML = 
			createFlashObject({ 
				path: '/_assets/swf/flash-text.swf',
				width: width,
				height: height,
				fallback: title.innerHTML,
				params: {
					wmode: 'transparent'
				},
				vars: {
					HTML: html,
					hoverColour: 'yes'
				}
			});
			
		// Seems to fix MSIE if you add a delay - perhaps there is latency in object instanciation
		(function () {
			var i = title;
			setTimeout(function () {i.style.visibility = ''}, 20);
		})()
	}
};

flashReplacement(); 


})(); // END Closure

