var myAccordion;
var pal = [];
pal.sections = [['/about/',3], ['/therapy/',13], ['/psychology/',4], ['/legal/',3], ['/training/',1], ['/consultancy_and_supervision/',3], ['/corporate/',4], ['/associates/',4], ['/secure/',4]];
pal.genBgs = 6;

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-15030606-1']);
_gaq.push(['_trackPageview']);

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();


window.addEvent('domready', function() {
    showEmails();
	bindLightbox();
	showNav();
	detectSmallScreen();
});

function showEmails() {
    //var email_enc = ":g&ntc`;$kgojri<oh`iFvuenijiaguuieogrcu(ita(sm$8uchb&gh&ckgoj:)g8";
	var email_enc = ":g&ntc`;$kgojri<chwsotocuFvuenijiaguuieogrcu(ita(sm$8Uchb&gh&ckgoj:)g8";
        email_str = '';
        for (i = 0; i < email_enc.length; ++i) {
            email_str += String.fromCharCode(6 ^ email_enc.charCodeAt(i));
        }
    $$('span.email').each(function(item, index) {
        item.innerHTML = email_str;
    });
}

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 detectSmallScreen() {
	if ((window.location.pathname == '/') || (window.location.pathname == '/default.aspx')) {
		if (document.body.clientWidth < 1100) {
			$$('#cols .lc')[0].setStyle('margin-right', '260px');
			$$('#page')[0].grab($$('#cols .rc')[0]);
			$$('#page .rc')[0].setStyle('clear', 'both');
			$$('#page .rc')[0].setStyle('float', 'left');
			$$('#page .rc')[0].setStyle('margin-top', '15px');
			$$('#page .rc')[0].setStyle('margin-left', '290px');
			$$('#page .rc .pnl')[1].setStyle('margin-left', '23px');
			$$('#page .mc')[0].setStyle('min-height', $$('#cols .lc')[0].getStyle('height'));
			if ((navigator.userAgent.indexOf('MSIE 7') > -1) || (navigator.userAgent.indexOf('MSIE 6') > -1)) {
				h = $$('#cols .lc')[0].getStyle('height');
				h = h.substr(0, h.indexOf('px'));
				$$('#page .rc')[0].setStyle('margin-top', (h-188) + 'px');
			}
		}
	}
}

function rnd(lower, upper) {
	return Math.floor(Math.random() * upper) + 1
}

function showPanel(pc, pf, index) {
	//Hide all panels
	$$(pc + ' div').each(function(item) {
		item.setStyle('display', 'none');
	});
	//Show panel
	$$('div#' + pf + index).setStyle('display', 'block');
}

function showNav() {
	section = -1;
	if (window.location.href.indexOf('/secure/') > 0 ) {
		section = 7;
	}
	else {
		pal.sections.each(function(item, index) {
			if (window.location.href.indexOf(pal.sections[index][0]) > 0 ) {
				section = index;
			}
		});
	}
	myAccordion = new Fx.Accordion($$('.tn'), $$('.sn'), {display: section, alwaysHide: true});
	if (section == -1) {
		$$('body')[0].setStyle('background-image', 'url(/images/bgs/general/' + rnd(0, pal.genBgs) + '.jpg)');
	}
	else {
		$$('body')[0].setStyle('background-image', 'url(/images/bgs' + pal.sections[section][0] + rnd(0, pal.sections[section][1]) + '.jpg)');
	}
}
