$(document).ready(function() {
	// **************************************************** //
	// Autofocus on Search page
	// **************************************************** //
	$('.content #search .keysearch:first').focus();
	
	// **************************************************** //
	// Validate contact form page
	// **************************************************** //
	$('#question #submit').click(function() {
		theName = $('.form #name').val();
		thePhone = $('.form #phone').val();
		theMessage = $('.form #message').val();
		if (theName.length > 1 && thePhone.length > 1 && theMessage.length > 1) {
			return true;
		}
		else {
			alert ("Please complete the compulsory fields and submit again.");
			return false;
		}
	});
	
	// **************************************************** //
	// Enable and activate the banner slides
	// **************************************************** //
	$(".slidetabs").tabs(".tier1 .images > div", {

		// enable "cross-fading" effect
		effect: 'fade',
		fadeOutSpeed: "slow",

		// start from the beginning after the last tab
		rotate: true

	// use the slideshow plugin. It accepts its own configuration
	}).slideshow({autoplay: true, interval: 10000, clickable: false});
	
	// **************************************************** //
	// Lightbox for Jquery (Gallery page)
	// **************************************************** //
	//$('.gallery a').lightBox({fixedNavigation:true});
	$('.gallery a').lightBox({
		overlayBgColor: '#000',
		overlayOpacity: 0.6,
		imageLoading: '../images/lightbox-ico-loading.gif',
		imageBtnClose: '../images/lightbox-btn-close.gif',
		imageBtnPrev: '../images/lightbox-btn-prev.gif',
		imageBtnNext: '../images/lightbox-btn-next.gif',
		containerResizeSpeed: 350,
		txtImage: 'Image',
		txtOf: 'of'
	   });
});

// **************************************************** //
// Skype detection
// **************************************************** //
jQuery.extend({
	skype : function(failureFunction) {
		var $ = jQuery;

		if ($.browser.safari || $.browser.opera) {
			return true;
		} else if ($.browser.msie) {
			try {
				if (new ActiveXObject("Skype.Detection")) return true;
			} catch(e) { }
		} else {
			if (typeof(navigator.mimeTypes["application/x-skype"]) == "object") {
				return true;
			}
		}
		$('a[href^="skype:"]').click(function() {
			failureFunction();
			return false;
		});
		return false;
	}
});

$(function() {
	$.skype(function() {
		// this function gets called if they don't have skype.
		alert("Sorry, but you do not appear to have Skype installed. We will now open a new window where you can download it.");
		skypeUrl = "http://www.skype.com/intl/en-us/get-skype/";
		window.open(skypeUrl);
		return false;
	});
});

