/***************************
 * SITE-SPECIFIC FUNCTIONS *
 ***************************/
 function launchVideo(swf) {
	var querystring = '';
	if (swf) {
		querystring	= '?swf=' + swf;
	}
	openWindow('/video_player/' + querystring,'width=380,height=380');
}

function launchVideos(file) {
	var querystring = '';
	if (file) {
		querystring	= '?file=' + file;
	}
	openWindow('/videos/' + querystring,'width=830,height=400');
}
 
/*********************
 * UTILITY FUNCTIONS *
 *********************/
 
function sendMail(user,domain,tld,subject,message) {
	if (!user) user = 'info';
	if (!domain) domain = 'newlifedigitalmedia';
	if (!tld) tld = 'com';
	locationstring = 'mailto:' + user + '@' + domain + '.' + tld;
	if (subject) locationstring += '?subject=' + encodeURIComponent(subject);
	if (message) locationstring += '&body=' + encodeURIComponent(message);
	window.location = locationstring;
}

function openWindow(url,features) {
	var newWin = window.open(url,'new-window',features);
	newWin.focus();
}

function closeWindow() {
	if (window.opener) {
		self.close();	
	}
}

function printPage() {
	if (window.print != null) {
		window.print();
	}
	else {
		alert("To print this page, please select Print from your browser's File menu.");
	}
}

function makeExternalLinks(){
    $('a, area').filter(function(){
        return this.hostname && this.hostname != location.hostname;
    })
	 .attr({
		target: "_blank", 
		title: "Opens in a new window"
	})
	.not(':has(img)')
	.addClass('external-link');
}

function handleLinkedFiles() {
	// Open linked files in a new window
	$('a').filter(function() {
        return (/(pdf$)|(doc$)|(ppt$)|(pps$)/i).test( $(this).attr('href'));
	}).attr('target','_blank');
	// Assign a class to link
	$('a[href$=.pdf]').not('a:has(img)').addClass('pdf-link');
	$('a[href^=javascript:printPage]').addClass('printer-link');
}

function makeRollovers(){
	$('a.rollover').each(function() { // preload over states
		var img = new Image();
		var upimage = $(this).find('img').attr('src');
		img.src = upimage.replace('_up','_ov');
	});
	$('a.rollover').hover(
		function(){
			var overimage = $(this).find('img').attr('src').replace('_up','_ov');
			$(this).find('img').attr('src',overimage);
		},
		function(){
			var upimage = $(this).find('img').attr('src').replace('_ov','_up');
			$(this).find('img').attr('src',upimage);
		}
	);
}

function makeActionLinks() {
	$('a.action').append(' &#187;');
}

function init() {
	makeExternalLinks();
	handleLinkedFiles();
	makeRollovers();
	makeActionLinks();
	$('a:has(img)').css('border','0');
}
