/***************************
 * SITE-SPECIFIC FUNCTIONS *
 ***************************/
 
 
/*********************
 * UTILITY FUNCTIONS *
 *********************/
 
function sendMail(user,domain,tld,subject,message) {
	if (!user) user = 'guest';
	if (!domain) domain = 'camille-engel';
	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,'popup',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 preload() {
	var path = '/images/';
	var images = new Array('');
	var preload = new Array('');
	var j = images.length;
	for (var i=0; i<images.length; i++) {
		preload[j] = new Image;
		preload[j++].src = path + images[i];
	}
}

function externalLinks() {
	$('a[href^="http://"]')
	.not('a[href*="camille-engel.com"]')
	.attr({
		target: "_blank", 
		title: "Opens in a new window"
	})
	.not('#pagebottom a, a:has(img), #social-networking a')
	.after(' <img src="/images/external.png" style="vertical-align:middle" />');	
}

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');
	// Append content to link
	$('a[href$=.pdf]').not('a:has(img), #nav a').after(' <img src="/images/pdf.png" />');
}

function makeRollovers(){
	$('a.rollover').each(function() {
		var img = new Image();
		var upimage = $(this).children().eq(0).attr('src');
		img.src = upimage.replace('_up','_ov');
	});
	$('a.rollover').hover(
		function(){
			var overimage = $(this).children().eq(0).attr('src').replace('_up','_ov');
			$(this).children().eq(0).attr('src',overimage);
		},
		function(){
			var upimage = $(this).children().eq(0).attr('src').replace('_ov','_up');
			$(this).children().eq(0).attr('src',upimage);
		}
	);
}

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

function init() {
	externalLinks();
	handleLinkedFiles();
	makeRollovers();
	actionLinks();
	$('.sf-menu').superfish();
	$('a[href^=javascript:sendMail]').hover(function(){window.status='Send email';},function(){window.status=''});
}
