var navs = [['/highstreet/','sh'],['/outoftown/','so'],['/golf/','sg']];
var t1;
doSifr();

window.addEvent('domready', function() {
	showEmails();
	bindNavs();
	showNav();
	bindLightbox();
});

function fixIE7Images() {
	$$('td#m img').each(function(item) {
		if(item.getStyle('display') == 'inline') {item.setStyle('display', 'inline'); item.setStyle('float', 'left'); item.setStyle('vertical-align', 'middle')}
	});
}

function bindLightbox() {
	$$('a > img').each(function(item, index) {
		var a = item.getParent('a');
		if (a != null) {
			var href = item.getParent('a').getProperty('href');
			img = a.getChildren('img');
			if (img != null) {
				if (img.getProperty('alt') != null) {
					a.setProperty('title', img.getProperty('alt'));
				}
			}
			if (href.substr(href.length - 4) == '.jpg') {
				a.slimbox();
			}
		}
	});
}

function bindNavs() {
	$$('div.subnav').each(function(item, index) {
		item.addEvents({'mouseover': function() {
			window.clearTimeout(t1);
			this.setStyle('display', 'block');
		},
		'mouseout': function() {
			t1 = window.setTimeout(function() {
				hideNavs();
				showNav()
				}, 1000);
		}});
	});
	$$('a.tn').each(function(item, index) {
		item.addEvents({'mouseover': function() {
			window.clearTimeout(t1);
			hideNavs();
			$('s' + this.getProperty('id')).setStyle('display', 'block');
		},
		'mouseout': function() {
			t1 = window.setTimeout(function() {
				hideNavs();
				showNav()
				}, 1000);
		}});
	});
}

function hideNavs() {
	$$('div.subnav').each(function(item, index) {
		item.setStyle('display', 'none');
	});
}

function showNav() {
	result = false;
	navs.each(function(item, index) {
		if (window.location.href.indexOf(navs[index][0]) > 0 ) {
			$(navs[index][1]).setStyle('display', 'block');
			result = true;
		}
	});
	return result;
}

function doSifr() {
	var CenturyGothic = {
	  src: '/sifr/CenturyGothic.swf'
	};
	sIFR.activate(CenturyGothic);
	sIFR.replace(CenturyGothic, {selector: 'div#head h4', wmode: 'transparent', tuneHeight: -4, css: '.sIFR-root {text-align: right; color: #ffffff;}'});
}

function showEmails() {
	$$('span.email').each(function(item, index) {
		var email_enc = ":g&ntc`;$kgojri<oh`iFkojjctdtiqh(ei(sm$8oh`iFkojjctdtiqh(ei(sm:)g8";
		email_str = '';
		for(i=0;i<email_enc.length;++i)
		{
			email_str += String.fromCharCode(6^email_enc.charCodeAt(i));
		}
		item.innerHTML = email_str;
	});
}


