(function ($) {


		//================== make the homepage carousel
	function homePageGallery() {
		// setup vars
		var imgCount = 0, base = $('.page-home div.view-current-build-view'), wrap = base.find('.views-row'), currentI = 0, imgWrap = $(wrap[0]).find('.home-gallery'), imgs = wrap.find('img'), temp = '<div class="gallery-slider" style="position:relative; height:100%; overflow:hidden; min-width:1669px;"></div>';
		var texts = wrap.find('.gallery-text').hide(), textElem = '<div class="replacement-text" style="position:absolute; top:10px; left:15px; z-index:3; width:32%;">lal</div>', leftArrow = base.find('.gallery-left-arrow'), rightArrow = base.find('.gallery-right-arrow');
		//setup wraps
		wrap.css({'position' : 'absolute', 'left' : ($(wrap[0]).width() + 40) + 'px', 'width': $(wrap[0]).width() + 'px'});
		$(wrap[0]).css({'left' : 'auto'});
		imgWrap.append(temp);
		temp = null;
		imgWrap = imgWrap.find('.gallery-slider');
		$(imgs).each(function () {
			if($(this).width() && $(this).width() > 0){
				$(imgWrap).width($(imgWrap).width() + $(this).width()).append(this);
				imgCount ++;
			}else{
				$(this).load( function () {
					$(imgWrap).width($(imgWrap).width() + $(this).width()).append(this);
					imgCount ++;
					init();
				} );
			}
		});
		
		init();
		
		function init(){
			if(imgCount == imgs.length) { // delay the init until all images are loaded for browsers that pre-process js
				imgs = $(imgWrap).find('img');
				//move it one in so that we always have at least one image on either side
				$(imgWrap).css({'left' : '-' + $(imgs[0]).width() + 'px'});
				$(imgWrap).prepend($(imgs[$(imgs).length - 1]));//put the end element on the front to show the first element first
				imgs = $(imgWrap).find('img');
				//get text elems and hide
				
				base.append(textElem);
				textElem = base.find('div.replacement-text');
				$(textElem).html($(texts[currentI]).html());
				//=== events
				
				$(leftArrow).click(function(e) {
					if(currentI+1 == wrap.length) { currentI = -1; }
					currentI ++;
					prepareForImageSlide($(imgs[0]), 'left');
					slideImg($(imgs[currentI]), 'left');
				});
				$(rightArrow).click(function(e) {
					if(currentI-1 == -1) { currentI = wrap.length; }
					currentI --;
					prepareForImageSlide($(imgs[$(imgs).length-1]), 'right');
					slideImg($(imgs[currentI]), 'right');
				});
			}
		}
		
		//=== functions
		function changeText() {
			$(textElem).fadeOut(100, function () {
				$(textElem).html($(texts[currentI]).html()).fadeIn(500);
			});
		}
		function prepareForImageSlide(img,side) {
			if(side == 'right'){
				$(imgWrap).prepend(img).css({'left': parseInt($(imgWrap).css('left')) - $(img).width()+'px'});
			}else{
				$(imgWrap).append(img).css({'left': parseInt($(imgWrap).css('left')) + $(img).width()+'px'});
			}
			imgs = $(imgWrap).find('img');
		}
		function slideImg(img,side) {
			var iw = $(img).width();
			if(side == 'right'){
				$(imgWrap).stop(true, true).animate({'left': (parseInt($(imgWrap).css('left')) + $(img).width()) + 'px'}, 800,'swing', function(){
					changeText();
				});
			}else{
				$(imgWrap).stop(true, true).animate({'left': (parseInt($(imgWrap).css('left')) - $(img).width()) + 'px'}, 800, 'swing', function(){
					changeText();
				});
			}
		}
		
	}// end homepage slider
	
	
	
	function formLableOverlay(){
		var textfields = $('form input[type="text"]');
		var textareas = $('form textarea');
		//== loop through and overlay label
		textfields.each(function(){
			var tf = $(this).siblings("label");
			var txt = tf.text();
			if(this.value == 'Your name' || this.value == 'Telephone...' || this.value == 'Enter your email' || this.value.indexOf ('Email') !=-1){
				this.value = txt;
			}
			tf.css({'display':'none'});
			$(this).focusin(function(){
				if(this.value == txt){
					this.value = '';
				}
			}).focusout(function(){
				if(this.value == ''){
					this.value = txt;
				}
			});
		});
		//== now the same for the textareas
		textareas.each(function(){
			var tf = $(this).parent().siblings("label");
			var txt = tf.text();
			txt = txt+'...';
			if(this.value == 'Your enquiry' || this.value == 'Your enquiry...'){
				this.value = txt;
			}
			tf.css({'display':'none'});
			$(this).focusin(function(){
				if(this.value == txt){
					this.value = '';
				}
			}).focusout(function(){
				if(this.value == ''){
					this.value = txt;
				}
			});
		});
	}//formLableOverlay
	
	//======================= init
	Drupal.behaviors.setUpTabs = {
    	attach: function(context, settings) {

			//js function calls
			if($('div.home-gallery','#content').length > 1){
				homePageGallery();
			}
			//== call form label overlay
			if($('form.webform-client-form', '#content').length){
				formLableOverlay();
			}
			
			//== Add os and browser classes for specific styles
			if(navigator.appVersion.indexOf("Mac")!=-1){
				$('body').addClass('Mac');
			}else if(navigator.platform.indexOf("Linux")!=-1){
				$('body').addClass('Linux');
			}else{
				$('body').addClass('PC');
			}
			
			var ua = $.browser;
			if (ua.safari) {
				$('body').addClass('safari-browser');
			}
			if (ua.webkit) {
				$('body').addClass('webkit-browser');
			}
			if (ua.msie) {
				$('body').addClass('msie-browser v'+ua.version.slice(0,1));
			}
			if (ua.opera) {
				$('body').addClass('opera-browser');
			}
			if (ua.mozilla) {
				$('body').addClass('mozilla-browser');
			}
			
			//account for ie7 not doing :before
			if($('.v7 .gallery-wrapper li.first a').length){
				$('.v7 .gallery-wrapper li.first a').prepend('More images');
			}

		}
	};

})(jQuery);;
// $Id: jquery.cookie.js,v 1.1 2009/07/01 12:16:48 dries Exp $

/**
 * Cookie plugin 1.0
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie=function(b,j,m){if(typeof j!="undefined"){m=m||{};if(j===null){j="";m.expires=-1}var e="";if(m.expires&&(typeof m.expires=="number"||m.expires.toUTCString)){var f;if(typeof m.expires=="number"){f=new Date();f.setTime(f.getTime()+(m.expires*24*60*60*1000))}else{f=m.expires}e="; expires="+f.toUTCString()}var l=m.path?"; path="+(m.path):"";var g=m.domain?"; domain="+(m.domain):"";var a=m.secure?"; secure":"";document.cookie=[b,"=",encodeURIComponent(j),e,l,g,a].join("")}else{var d=null;if(document.cookie&&document.cookie!=""){var k=document.cookie.split(";");for(var h=0;h<k.length;h++){var c=jQuery.trim(k[h]);if(c.substring(0,b.length+1)==(b+"=")){d=decodeURIComponent(c.substring(b.length+1));break}}}return d}};
;

