// Sitewide scripts using jquery

// activate google analitics with jquery.google-analytics.js plugin
// edit the Google Tracking number
//$.trackPage('UA-4066939-1', {status_code: 404});


$(document).ready(function() { 

// initialise Header Rotating Images using InnerFade
	$("#header_fade").innerfade({
		containerheight: "168px", //uncomment to fix a height
		speed: 2000,
		timeout: 5000,
		type: "random"
	});
// initialise home page upper Rotating Images using InnerFade
	$("#home_upper").innerfade({
	  containerheight: "342px", 
		speed: 3000,
		timeout: 5000,
		type: "sequence"
	});

// initialise home page lower Rotating Images using InnerFade
	$("#home_fade").innerfade({
		//containerheight: "311px", //uncomment to fix a height
		speed: 2000,
		timeout: 5000,
		type: "random"
	});

//tabs using idTabs plugin
	$("#main ul").idTabs();

// Add target="_blank" to external links
	$("a").filter(function() {
		return this.hostname && this.hostname !== location.hostname;
	}).attr("target", "_blank");

//remove the outline of a link when clicked
	$("a").click(function() {
		this.blur();
	});
	

//colorbox photo gallery
	$('.gallery a').colorbox();
	$(document).bind('cbox_open', function(){
        $('embed, object, select').css({ 'visibility' : 'hidden' });
	});
	$(document).bind('cbox_closed', function(){
        $('embed, object, select').css({ 'visibility' : 'visible' });
	});
	
	// Homepage ask a therapist
	$('.btn_ask a').colorbox({
		speed: 400,
		width: "500px",
		height: "330px",
		href: "/ask_therapist.php"
	});
	
  //validate form
	var validate_form = function() {
		$('#ask-therapist').validate({
			rules: {
				name: {
					required: true,
					minlength: 2
				},
				email: {
					required: true,
					email: true
				}
			}, 
			messages: {
				name: "<br>Please enter your name",
				email: "<br>Please enter a valid email address"
			}
		});
	};
	
	//bind the form validation
	validate_form();
	$(document).bind('cbox_complete', function(){
		$('.btn_ask a').unbind('validate');
		validate_form();
	});
	
	
/*
//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.)lodipt\.com\//i, '');
				$.trackEvent("Download", "Click - " + extension, filePath);
			});
		}
	});
*/

// end $(document).ready();
});

//cufon text replacement
Cufon.replace(".programs_text h1");

