(function(){
	ua = navigator.userAgent.toLowerCase(),	  
	check = function(r){
		return r.test(ua);
	}
	isOpera = check(/opera/),			  
	isIE = check(/msie/),
	isIE7 = isIE && check(/msie 7/),
	isIE8 =	isIE && check(/msie 8/),
	isIE6 =	isIE && !isIE7 && !isIE8,
	isChrome = check(/chrome/),
	isWebKit =check(/webkit/),
	isSafari =!isChrome && check(/safari/),
	isSafari2 =	isSafari && check(/applewebkit\/4/),
	isSafari3 = isSafari && check(/version\/3/),
	isSafari4 = isSafari && check(/version\/4/),
	isGecko = !isWebKit && check(/gecko/),
	isGecko2 = isGecko && check(/rv:1\.8/),
	isGecko3 = isGecko && check(/rv:1\.9/),
	isWindows = check(/windows|win32/),	
	isMac = check(/macintosh|mac os x/),	
	isAir = check(/adobeair/),	
	isLinux = check(/linux/),
	
	
	jQuery.extend(jQuery.browser, {
		isOpera: isOpera,
		isIE:	isIE,
		isIE6: isIE6,
		isIE7: isIE7,
		isIE8: isIE8,
		isChrome: isChrome,
		isWebKit: isWebKit,
		isSafari: isSafari,
		isSafari2: isSafari2,
		isSafari3: isSafari3,
		isSafari4: isSafari4,
		isGecko: isGecko,
		isGecko2: isGecko2,
		isGecko3: isGecko3,
		isWindows: isWindows,
		isMac: isMac,
		isAir: isAir,
		isLinux: isLinux
	});
})();
if($.browser.isIE){	
	addStyle('css/stylefix.css');
}
function addStyle(patch){
	var style = document.createElement('link');
	style.setAttribute('rel','stylesheet');
	style.setAttribute('type','text/css');
	style.setAttribute('href',patch);
	document.getElementsByTagName('head')[0].appendChild(style)	;	
}


$(document).ready(function(){
	$('.home, #banner, #enquiries').pngFix();	
	
});


function contactForm(){
	$("#contact form").validate({
		errorPlacement: function(error, element) {
			$(element).addClass('error');
		}
		,submitHandler: function() {
			$('#loading-bar').addClass("loading");
			$('#contact form').ajaxSubmit({
				dataType: 'json',
				type: 'post',
				success : function(result){
					$('#loading-bar').removeClass("loading");
					$("#contact-result").html("<p>Thanks "+result.name+", for contacting us, "+result.msg+".</p>" +
							             "<p align=\"center\">" +
              							 "<input id=\"btn-back\" type=\"button\" class=\"x-btn\" value=\"Back\"/>"+
            							 "</p>");	
					$("#contact-panel").hide();
					$("#contact-result").show();
					$("#btn-back").click(function(){
					    $("#contact-result").hide();
						$("#contact-panel").show();												  
					});					
				}										  
			});
		}
		}
		);			
}


(function($) {
	jQuery.fn.scrollGallery = function(settings){
		return this.each(function(){
			var container = $('.items', this);
			var frame = $('#gallery-ct', this);
			var self = this;
			var len = $('img', container).length;
			$(container).width(445 * (len + 1));
			$(container).append($('img:first-child', container).clone());

			var duration = len * 1000 * 3;
			var speed = (parseInt($(container).width()) + parseInt($(frame).width())) / duration;
			var direction = "rtl";

			//animator function
				var animator = function(el, time, dir) {
					dir = 'rtl';
					//which direction to scroll
					if(dir == "rtl") {
					  
					  //add direction class
						el.removeClass("ltr").addClass("rtl");
					 		
						//animate the el
						el.animate({ left:"-" + (el.width() - $('img:first-child', el).width()) + "px" }, time, "linear", function() {
												
							//reset container position
							$(this).css({ left:0, right:"" });
							
							//restart animation
							animator($(this), duration, "rtl");
									
											
						});
					} else {
					
					  //add direction class
						el.removeClass("rtl").addClass("ltr");
					
						//animate the el
						el.animate({ left:$(frame).width() + "px" }, time, "linear", function() {
												
							//reset container position
							$(this).css({ left:0 - $(container).width() });
							
							//restart animation
							animator($(this), duration, "ltr");		
						});
					}
				}

				animator($(container), duration, direction);

			$('img', container).bind("mouseover", function() {
				  
					//stop anim
					$(container).stop(true);
				});

			//restart on mouseout
			$('img', container).bind("mouseout", function(e) {

					
					//work out total travel distance
					var totalDistance = parseInt($(container).width()) + parseInt($(frame).width());
														
					//work out distance left to travel
					var distanceLeft = ($(container).hasClass("ltr")) ? totalDistance - (parseInt($(container).css("left")) + parseInt($(container).width())) : totalDistance - (parseInt($(frame).width()) - (parseInt($(container).css("left")))) ;
					
					//new duration is distance left / speed)
					var newDuration = (distanceLeft / speed) ;
				
					//restart anim
					animator($(container), newDuration, $(container).attr("class"));

				});

		});
	};		  
})(jQuery);	

function initShop() {
	$('#shop-items .item-wrap').each(function(index){
		if ((index +1) % 3 == 0) {
			$(this).addClass('item-last');			
		}											  
	});
}