﻿$(document).ready(function() {
	//Cufon.replace('h1', { fontFamily: 'Zurich Cn BT' });
	//Cufon.replace('h2', { fontFamily: 'Zurich Cn BT' });
	//Cufon.replace('.cfnt', { hover: true, fontFamily: 'Zurich Cn BT' });
	//Cufon.replace('.tel', { fontFamily: 'Zurich Cn BT' });
	$.externallinks();
	$('.bannerbx ul').innerfade({
		animationtype: 'fade',
		speed: 2000,
		timeout: 10000,
		type: 'sequence',
		containerheight: '246px'
	});
	/*$(".fncbx").fancybox({
		'titleShow': false,
		'width': '605px',
		'height': '550px',
		'transitionIn': 'elastic',
		'transitionOut': 'elastic',
		'opacity': '0.9',
		'autoScale': false
	});
	$("a.fncbx").each(function(){ 
		this.href = this.href + "&external=1";
	});*/

	/*$("a.videofancybox,a.lightbox").fancybox({
		'hideOnContentClick': false,
		/*'zoomSpeedIn': 500,
		'zoomSpeedOut': 500,
		'width': '605px',
		'height': '550px',
		/*'frameWidth': '425',
		'frameHeight': '344',
		'overlayOpacity': '0.9',
		'autoScale': false
	});*/
	$("a.videofancybox,a.lightbox").fancybox({
		'hideOnContentClick': false,
		/*'zoomSpeedIn': 500,
		'zoomSpeedOut': 500,
		'width': '425px',
		'height': '344px',*/
		'frameWidth': '425',
		'frameHeight': '304',
		'overlayOpacity': 0.9
	});
	$('input[title!=""]').hint();
	$('a[href^="http://www.youtube.com/"]').flash({
		height: 425,
		width: 344,
		allowFullScreen: true,
		wmode: "transparent"
	},
	{ version: 8 },
	function(htmlOptions) {
		$this = $(this);
		htmlOptions.src = $this.attr('href');
		htmlOptions.width = 425;
		htmlOptions.height = 344;
		$this.before($.fn.flash.transform(htmlOptions));
		$this.replaceWith("");
	});
	
	$.googletracklinks("UA-12925736-1", window.location.href.substr(0, window.location.href.indexOf("/",7)));
});

function showvideo() {
	$.fancybox({
		'padding'		: 0,
		'href'			: 'http://www.youtube.com/v/6OB5YAACq0A&amp;hl=en_GB&amp;fs=1&amp;autoplay=1',
		'title'   		: 'Mise en Place TV Advert',
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'content': '<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/6OB5YAACq0A&amp;hl=en_GB&amp;fs=1&amp;autoplay=1" /><param name="wmode" value="transparent" /><param name="allowfullscreen" value="true" /><param name="type" value="application/x-shockwave-flash" /><param name="pluginspage" value="http://www.adobe.com/go/getflashplayer" /><embed width="425" height="344" wmode="transparent" allowfullscreen="true" type="application/x-shockwave-flash" src="http://www.youtube.com/v/6OB5YAACq0A&amp;hl=en_GB&amp;fs=1&amp;autoplay=1" pluginspage="http://www.adobe.com/go/getflashplayer" flashvars=""></embed></object>'
	});
}

$.externallinks = function() {
	$('a[href^="http://"]').attr({
		target: "_blank",
		title: function(arr) {
			if ($(this).attr("title").length > 0) {
				$(this).attr("title", $(this).attr("title") + " (opens in a new window)");
			}
			else {
				$(this).attr("title", "opens in a new window");
			}
		}
	});
}

$.googletracklinks = function(_uacct,base) {
	// The slashes are to ensure the period is in the url, the $ is to make sure it is the end of the url, the i is to make it case insensitive.
	filetypes = /\.doc$|\.xls$|\.exe$|\.zip$|\.pdf$|\.mp3$|\.psd$/i;
	$("a[href]").each(function() {
		// Track mailto links
		if ($(this).attr("href").match(/^mailto\:/i)) {
			var url = "/mailto/" + $(this).attr("href").replace(/^mailto\:/i, "")
			$(this).click(function() {
				pageTracker._trackPageview(url);
				pageTracker._trackEvent('Email Contact', $(this).attr("href").replace(/^mailto\:/i, "").replace(/\;/g, ""));
			})
			//$(this).attr("title", $(this).attr("title") + " | " + url + " | " + _uacct);
			$(this).attr("title", $(this).attr("title") + " >");
		}
		// Track external links
		else if (location.host != this.host.replace(/\:80$/i, "")) {
			var url = "/outgoing/" + $(this).attr("href").replace(/^http\:\/\/(www\.)*/i, "")
			$(this).click(function() {
				pageTracker._trackPageview(url);
				pageTracker._trackEvent('Outgoing link', $(this).attr("href").replace(/^http\:\/\/(www\.)*/i, ""));
			})
			//$(this).attr("title", $(this).attr("title") + " | " + url + " | " + _uacct);
			$(this).attr("title", $(this).attr("title") + " >>"); // + $(this).attr("href").replace(/^http\:\/\/(www\.)*/i, ""));
		}
		// Track downloads (links with a given extension)
		else if ($(this).attr("href").match(filetypes)) {
			// The URL needs to be changed for each site this is applied to.
			var url_prefix = String(document.location).replace(/^(https?:\/\/[^:\/]+).*$/, "$1").replace(/^((site)?file:\/\/.+\/)[^\/]+$/, "$1").replace(/(\\.)/g, "\\$1");
			var url = '/downloads/' + $(this).attr("rel") + '/' + $(this).attr("title").replace(/ /g, "_");
			$(this).click(function() {
				pageTracker._trackPageview(url);
				pageTracker._trackEvent('Download', $(this).attr("rel") + ' - ' + $(this).attr("title").replace(/ >>>>>> (opens in a new window)/g, ""));
			})
			$(this).attr("title", $(this).attr("title") + " >>>");
		}
		else if ($(this).attr("href").match(/vacancy\/\?/i)) {
			// The URL needs to be changed for each site this is applied to.
			//alert("test");
			var url = $(this).attr("href").replace(base,"");
			$(this).click(function() {
				var pageTracker = _gat._getTracker(_uacct);
				pageTracker._trackPageview(url);
			})
			$(this).attr("title", $(this).attr("title") + "view vacancy details");
			$(this).attr("rel",  url);
		}
	});
}

