// Sitewide scripts using jquery
// place this at the bottom of other script includes to activate jquery plugins

// cufon styling for text
	Cufon.replace('h1', {
		color: '-linear-gradient(#053EAF, #030961)'
	});
	Cufon.replace('h2');
	Cufon.replace('h3');
	Cufon.replace('h4');
	Cufon.replace('h5');

// activate google analitics with jquery.google-analytics.js plugin
// edit the Google Tracking number
//$.trackPage('UA-xxxxxxx-x');

//these scripts will fire after html has loaded
$(document).ready(function() { 
													 
// activate png transparency fix
	$(document).pngFix(); //uncomment to create png transparencies in IE6
	

// initialise Header Rotating Images using InnerFade
	$("#home_photos").innerfade({
		containerheight: "319px", //uncomment to fix a height
		speed: 3500,
		timeout: 5000,
		type: "sequence"
	});
	
// Function to hide email addresses
	$("span.mailme").each(function() {
		var spt = "#" + $(this).attr("id");
		var at = / where /; //replaces with @
		var dot = / all /g; //replaces with .
		var addr = $(spt).text().replace(at, "@").replace(dot, ".");
		$(spt).after('<a href="mailto:' + addr + '" title="Send an email">' + addr + '</a>')
		.hover(function() {window.status = "Send a letter!";}, function() {window.status = "";});
		$(spt).remove();
	});

// Add external link icon to text hyperlinks
	$("a:not(:has(img))").filter(function() {
		return this.hostname && this.hostname !== location.hostname;
	}).addClass("external_link").attr("target", "_blank");
	
// Add an rss link icon to text hyperlinks
	$("a[href^='http://feeds']:not(:has(img))").addClass("feed_link").attr("target", "_blank");

//Horizontal Scroll
	$(".sponsors").hscroll();

//colorbox photo gallery
//	$('.gallery a').colorbox();
//	$().bind('cbox_open', function(){
//        $('embed, object, select').css({ 'visibility' : 'hidden' });
//	});
//	$().bind('cbox_closed', function(){
//        $('embed, object, select').css({ 'visibility' : 'visible' });
//	});
	
/*
// Google Analytics for custom events
	$("a.custom_event").click(function() {
		var title = $(this).attr("title");
		$.trackEvent("category", "action", title); //edit parameters (optional 4th param - "value" int)
	});
*/

//track mailto and downloads with Google Analytics
	$('a').each(function() { //loop though each anchor element
		var href = $(this).attr('href');
		var filetypes = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3)$/i;
		
		//check for links starting with mailto:
		if (href.match(/^mailto\:/i)){
			$(this).click(function() {
				var mailLink = href.replace(/^mailto\:/i, '');
				$.trackEvent("Email", "Click", mailLink);
			});
		}
		//check for links with file extension that match the filetypes regular expression:
		else if (href.match(filetypes)){
			$(this).click(function() {
				var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
				var filePath = href.replace(/^https?\:\/\/(www.)mydomain\.com\//i, '');
				$.trackEvent("Download", "Click - " + extension, filePath);
			});
		}
	});
	
// iSelect Popup
	$('#iselect_design').hover(function() {
		$(this).find('#iselect_promo:hidden').fadeIn(500);
	}, function() {
		$(this).find('#iselect_promo:visible').fadeOut(500);
	});
	
//end $(document).ready();

}); 