// globals
var VideoWidth, VideoHeight; // persistent so we know the last-used size for chained videos



function makeHRef(user,display,domain,style) {

	// We use this script to create mailto tags that can't be detected by spambots
	// Pass in the mail 'user' account and get a full link back:
	// makeHRef('user'); produces: <a href="mailto:user@domain.xxx">user@domain.xxx</a>
	// Display: changes the display value between the 'a' tags
	// Domain: sets a different domain (default = lucion.com)
	// Style: sets a class for the tag

	var a = '\x40'; // @
	var m = '\x6d'; m=m+'\x61'; m=m+'\x69'; m=m+'\x6c'; m=m+'\x74'; m=m+'\x6f'; m=m+'\x3a'; // m a i l t o :
	if (!domain) domain = 'lucion' + '\x2e' + '\x63' + '\x6f' + '\x6d'; // . c o m;
	if (!display) display = user + a + domain;
	if (!style) {
		style = '';
	} else {
		style = 'class="' + style + '" ';
	}
	document.write('<a ' + style + 'href="' + m + user + a + domain + '">' + display + '</a>');
}
// Deprecated; keep for now in case of old pages; try to remove by 1/2011
function makeHRefCust(a,z) {
	makeHRef(a,z);
	// a = username, z = display value
	// makeHrefCust(user,display) produces: <a href="mailto:user@domain.xxx">display</a>
}
function makeHRefClass(a,y,z) {
	makeHRef(a,z,'',y);
	// a = username, y = class, z = display value
	// makeHrefCust(user,display) produces: <a href="mailto:user@domain.xxx">display</a>
}
function makeHRefEx(a,b,c) {
	// For other domains, produces: <a href="mailto:a@b.c">a@b.c</a>
	makeHRef(a,'',b+'.'+c);
}



function clarify(a) {
	// For reverting from an obfuscated string to a clear string
	var str = a.join("");
	document.write(str);
}



function pageWidth() {
	return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}
function pageHeight() {
	return  window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}
function posLeft() {
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}
function posTop() {
	return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}
function posRight() {
	return posLeft() + pageWidth();
}
function posBottom() {
	return posTop() + pageHeight();
}



function playVideo(caller) {

	// switch the href to our swf reference
	htm = caller.href;
	caller.href = caller.href.replace('.htm','_skin.swf');

	// get a screen size
	getVideoSize(800,600,60);

	// open the Highslide object
	result = hs.htmlExpand(caller, {
			objectType: 'swf', width: VideoWidth,
			objectWidth: VideoWidth, objectHeight: VideoHeight,
			preserveContent: false, wrapperClassName: 'no-footer titlebar',
			allowSizeReduction: false, maincontentText: '',
			headingEval: 'this.a.title' } );

	// fail-safe to the html page, not the swf; result == true if hs failed
	if (result == true) {
		caller.href = htm;
	}

	return result;
}
function chainVideo(id) {

	// look for a current container element in the highslide popup
	var success = false;
	var obj = null;
	for (var i=0; i<1000; i++) {
		if (document.getElementById('hs-flash-id-' + i)) {
			success = true;
			break;
		}
	}

	// embed
	if (success) {
		swfobject.embedSWF('videos/' + id + '_skin.swf', 'hs-flash-id-' + i, VideoWidth, VideoHeight, '7', 'videos/expressInstall.swf', '', {menu:'false', bgcolor:'#ffffff', quality:'high'});
		return;
	}

	// failsafe: open alternate page
	var re = /\/videos\//;
	if (re.test(location.href)) {
		window.location = id + '.htm'; // if there's already an alternate page open, reuse it
	} else {
		window.open('videos/' + id + '.htm', '','toolbar=no,directories=no,');
	}
}
function callMovie(s) {
	chainVideo(s);
}
function getVideoSize(w,h,buffer) {

	// Give videos the biggest size possible up to the requested dimensions
	// buffer is to account for extra width/height required by the container

	if (pageWidth() < w + buffer) {
		w = pageWidth() - buffer;
		if (w < 400) w = 400;	// sane minimum size
		h = w * 0.75;
	}
	if (pageHeight() < h + buffer) {
		h = pageHeight() - buffer;
		if (h < 300) h = 300;	// sane minimum size
		w = h * 1.333;
	}
	VideoWidth = Math.round(w);
	VideoHeight = Math.round(h);
}
function isIE6() {
	return /msie|MSIE 6/.test(navigator.userAgent);
}


function showFeature(caller) {

	// open the Highslide object
	result = hs.htmlExpand(caller, {
		objectType: 'ajax',
		preserveContent: false,
		wrapperClassName: 'no-footer titlebar lucion-ajax'
	} );

	return result;
}


function toggleToBlock(id) {

	// hide them all
	var blocks, i;
	blocks = document.getElementsByTagName('div');
	for (i in blocks) {
		if(/toggle/.test(blocks[i].className)) {
			blocks[i].style.display = 'none';
		}
	}

	// show the requested block
	document.getElementById(id).style.display = 'block';

	return false;
}


function useTemplate(id) {
	tpl = document.getElementById(id);
	document.write( tpl.innerHTML );
}
