$(document).ready( function() {



	//Exists by selector. Ex.: if ($.exists('.test')) {...}
	jQuery.exists = function(selector) {return ($(selector).length > 0);}

	// Adding delay(mtime) function to jquery. Ex.: $('.test').delay(500).hide();
	//$.fn.delay = function(duration) {$(this).animate({ dummy: 1 }, duration);return this;};
	$.fn.delay = function(time, callback){
		jQuery.fx.step.delay = function(){};
		return this.animate({delay:1}, time, callback);
	}

	// Clients Scroll Box
if ($.exists('.spinbox')){
	$.getScript("/js/jquery.scrollTo.js", function(){
		var spinWidth = 177;
			if ($.exists('.spinclients')) spinWidth = 200;
		var spinPos = 0;
		var spinSpeed = 800;
		var spinStop = 1;
		var spinEls = $('.spinbox td').size();
		var spinTotal = spinEls * spinWidth;
		var spinPosEnd = spinTotal - spinWidth;
		var spinAutoSpeed = 3000;
			if (spinEls < 3) spinAutoSpeed = 7000;

		if ($.exists('.spingetimages')){
			var spinRel = $('.spinbox td a');
			spinRel[0].innerHTML = '<img src="'+ spinRel[0].getAttribute('rel') +'" alt="'+ spinRel[0].getAttribute('title') +'" />';
		}

		$('.spinbox table').css('width',spinTotal+'px');
		if (spinEls > 1) {
			$('.larrow, .rarrow').hover(function(){$(this).addClass('glow');},function(){$(this).removeClass('glow');});
			$('.larrow, .rarrow').mouseup(function(){$(this).removeClass('opac');}).mousedown(function(){$(this).addClass('opac');});
			$('.spinbox td, .spin span').hover(function(){spinStop=0;},function(){spinStop=1;});
			$('.larrow').click(function(){spinleft()});
			$('.rarrow').click(function(){spinright()});
		}
		spinleft = function () {
			if (spinPos >= spinWidth && spinPos > 0) {
				spinPos += - spinWidth;
				spinSpeed = 800;
			}else{
				spinPos = spinPosEnd;
				if (spinEls > 2) spinSpeed = 0;
			}
			spin();
		}
		spinright = function () {
			if (spinPos <= spinPosEnd) {
				if (spinPos == spinPosEnd) {
					spinPos = 0;
					if (spinEls > 2) spinSpeed = 0;
				}else{
					spinPos += spinWidth;
					spinSpeed = 800;
				}
			}
			spin();
		}
		spin = function() {
			if ($.exists('.spingetimages')){
				var sCur = (spinPos/spinWidth);
				spinRel[sCur].innerHTML = '<img src="'+ spinRel[sCur].getAttribute('rel') +'" alt="'+ spinRel[sCur].getAttribute('title') +'" />';
				if (spinRel[sCur+1]) {
					new Image().src = spinRel[sCur+1].getAttribute('rel'); //preloading next image
				}
			}
			
			$('.spinbox').scrollTo(spinPos, spinSpeed);
		}
		autoSpin = function () {
			if (spinStop){spinright();}
			setTimeout(autoSpin,spinAutoSpeed);
		}
		setTimeout(autoSpin,spinAutoSpeed);
	});
}


	//Colorise footer icons
	$('.footer .awards img').hover(function(){$(this).attr('src',this.src.replace('.png','-color.png'));},function(){$(this).attr('src',this.src.replace('-color.png','.png'));});


	if (!$('#tMenu').is(':empty')) {
		$.getScript("/js/jquery.tooltip.js", function(){
			$(".header .logo, #tMenu").ezpz_tooltip({
				contentPosition: 'belowStatic',
				stayOnContent: true,
				contentId: 'tMenu',
				offset: 0
			});
		});
	}

	if ($.exists("a[rel='zoom']")){
		$.getScript("/js/jquery.lightbox.js", function(){
			$("a[rel='zoom']").lightBox();
		});
	}


});

