function initCufon() {
	Cufon.replace('#header .intro strong span', { textShadow: '#000 1px 1px, #000 1px 1px', fontFamily: 'Helvetica' });
	Cufon.replace('.intro-btn .btn', {fontFamily: 'LTAroma ExtraLight', hover: true, forceHitArea: true  });
	Cufon.replace('#sidebar .accordion .opener h3', {fontFamily: 'LTAroma ExtraLight' });
	Cufon.replace('.side-block h3', {fontFamily: 'LTAroma ExtraLight' });
	Cufon.replace('#content h2', {fontFamily: 'LTAroma ExtraLight' });
	Cufon.replace('.aside .widget h4', {fontFamily: 'LTAroma ExtraLight' });
	Cufon.replace('.aside .box .heading h4', {fontFamily: 'LTAroma ExtraLight' });
	Cufon.replace('.aside .btn-book a', {fontFamily: 'LTAroma ExtraLight' });
	Cufon.replace('#footer .block h4', {fontFamily: 'LTAroma ExtraLight' });
	Cufon.replace('.spa-content .btns .box a', { fontFamily: 'LTAroma ExtraLight' });
	Cufon.replace('.spa-content .section h3', {fontFamily: 'LTAroma ExtraLight' });
}

function clearFormFields(o)
{
	if (o.clearInputs == null) o.clearInputs = true;
	if (o.clearTextareas == null) o.clearTextareas = true;
	if (o.passwordFieldText == null) o.passwordFieldText = false;
	if (o.addClassFocus == null) o.addClassFocus = false;
	if (!o.filter) o.filter = "default";
	if(o.clearInputs) {
		var inputs = document.getElementsByTagName("input");
		for (var i = 0; i < inputs.length; i++ ) {
			if((inputs[i].type == "text" || inputs[i].type == "password") && inputs[i].className.indexOf(o.filterClass)) {
				inputs[i].valueHtml = inputs[i].value;
				inputs[i].onfocus = function ()	{
					if(this.valueHtml == this.value) this.value = "";
					if(this.fake) {
						inputsSwap(this, this.previousSibling);
						this.previousSibling.focus();
					}
					if(o.addClassFocus && !this.fake) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				inputs[i].onblur = function () {
					if(this.value == "") {
						this.value = this.valueHtml;
						if(o.passwordFieldText && this.type == "password") inputsSwap(this, this.nextSibling);
					}
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
				if(o.passwordFieldText && inputs[i].type == "password") {
					var fakeInput = document.createElement("input");
					fakeInput.type = "text";
					fakeInput.value = inputs[i].value;
					fakeInput.className = inputs[i].className;
					fakeInput.fake = true;
					inputs[i].parentNode.insertBefore(fakeInput, inputs[i].nextSibling);
					inputsSwap(inputs[i], null);
				}
			}
		}
	}
	if(o.clearTextareas) {
		var textareas = document.getElementsByTagName("textarea");
		for(var i=0; i<textareas.length; i++) {
			if(textareas[i].className.indexOf(o.filterClass)) {
				textareas[i].valueHtml = textareas[i].value;
				textareas[i].onfocus = function() {
					if(this.value == this.valueHtml) this.value = "";
					if(o.addClassFocus) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				textareas[i].onblur = function() {
					if(this.value == "") this.value = this.valueHtml;
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
			}
		}
	}
	function inputsSwap(el, el2) {
		if(el) el.style.display = "none";
		if(el2) el2.style.display = "inline";
	}
}
$(document).ready(function(){
	initCufon();
	clearFormFields({
		clearInputs: true,
		clearTextareas: true,
		passwordFieldText: true,
		addClassFocus: "focus",
		filterClass: "default"
	});
    var _parentSlide = '#sidebar .accordion .section';
    var _linkSlide = 'div.opener';
    var _slideBlock = 'div.slide';
    var _openClassS = 'ui-state-active';
    var _durationSlide = 300;
    
    $(_parentSlide).each(function(){
	if (!$(this).is('.'+_openClassS)) {
	    $(this).find(_slideBlock).css('display','none');
	}
    });
    $(_linkSlide,_parentSlide).click(function(){
	if ($(this).parents(_parentSlide).is('.'+_openClassS)) {
	    $(this).parents(_parentSlide).removeClass(_openClassS);
	    $(this).parents(_parentSlide).find(_slideBlock).slideUp(_durationSlide);
	} else {
	    $(this).parents(_parentSlide).addClass(_openClassS);
	    $(this).parents(_parentSlide).find(_slideBlock).slideDown(_durationSlide);
	}
	return false;
    });

});


function initNav()
{
	var nav = document.getElementById("navbar");
	if(nav)
	{
		var lis = nav.getElementsByTagName("li");
		for (var i=0; i<lis.length; i++)
		{
			lis[i].onmouseover = function()
			{
				this.className += " hover";
			}
			lis[i].onmouseout = function()
			{
				this.className = this.className.replace(" hover", "");
			}
		}
	}
	if(nav)
	{
		var lis2 = nav.getElementsByTagName("dd");
		for (var i=0; i<lis2.length; i++)
		{
			lis2[i].onmouseover = function()
			{
				this.className += " hover";
			}
			lis2[i].onmouseout = function()
			{
				this.className = this.className.replace(" hover", "");
			}
		}
	}
}
if (document.all && !window.opera) attachEvent("onload", initNav);

//set external links
$(document).ready(function() {
    $('a[rel = external]').attr('target', 'blank');
});
//Update header for sub menu
$(document).ready(function() {
    $('.menu-header').text($('.breadcrumbs li').eq(1).text());
});
//Hide/Display Sub Menu nested UL
$(document).ready(function() {
    if ($('.sub-menu')) {
        $('.sub-menu ul li ul').hide();
        $('.sub-menu ul li ul li.active').parent().show();
        $('.sub-menu ul li.active > ul').show();
    }
});
//Video Suites and Video links
$(document).ready(function() {
    $("a[rel = lightbox]").click(function() {
        var requiredMajorVersion = 10;
        var requiredMinorVersion = 0;
        var requiredRevision = 0;
        var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
        if (!hasReqestedVersion) {
            var content = $('<div id="flashMessage" ><p>You need to install Flash to view the video suite</p><p><a href="http://get.adobe.com/flashplayer/" >Download the Flash player now.</a></p></div>');
            $.fancybox({
                'content': content,
                'padding': 20
            });
        } else {
            var st = this.href;
            var paths = st.split("?file=");
            $.fancybox({
                'href': paths[0],
                'type': 'swf',
                'swf': {
                    'codebase': 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
                    'width': '602',
                    'height': '338',
                    'quality': 'high',
                    'pluginspage': 'http://www.macromedia.com/go/getflashplayer',
                    'align': 'middle',
                    'play': 'true',
                    'loop': 'true',
                    'scale': 'showall',
                    'wmode': 'opaque',
                    'devicefont': 'false',
                    'id': 'videoPlayer',
                    'bgcolor': '#ffffff',
                    'name': 'videoPlayer',
                    'menu': 'true',
                    'allowFullScreen': 'true',
                    'allowScriptAccess': 'sameDomain',
                    'movie': 'videoPlayer',
                    'wmode': 'transparent',
                    'allowfullscreen': 'true',
                    'FlashVars': 'settingsFile=' + paths[1]
                }
            });
        }
        return false;
    });
});
//Video/Gallery Listers
$(document).ready(function() {
    var count = 0;
    //hide gallery items
    $('.spa-content .section .gallery').hide();
    //change text of gallery item
    $('.gallery-item').text('Click here to view the gallery');
    //create image groupings and display number of images - image galleries
    $('.section').each(function() {
        count++;
        $(this).find('a.lightbox').attr('rel', 'group' + count);
        var links = $(this).find('a.lightbox').length;
        if (links > 0) {
            $(this).find('.block .description dl dd:first').text(links);
        }
    });
    //lightbox link - gallery items
    $("a.lightbox").fancybox({
        'padding': 0,
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none'
    });
});
//Add tracking to mailto:
$(document).ready(function() {
    $('a[href^=mailto:]').attr('onclick', 'pageTracker._trackPageview(\' / mailto / \'+this.href);')
});

