$(document).ready(function () {
	
	var BrowserDetect = {
		init: function () {
			this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
			this.version = this.searchVersion(navigator.userAgent)
				|| this.searchVersion(navigator.appVersion)
				|| "an unknown version";
			this.OS = this.searchString(this.dataOS) || "an unknown OS";
		},
		searchString: function (data) {
			for (var i=0;i<data.length;i++)	{
				var dataString = data[i].string;
				var dataProp = data[i].prop;
				this.versionSearchString = data[i].versionSearch || data[i].identity;
				if (dataString) {
					if (dataString.indexOf(data[i].subString) != -1)
						return data[i].identity;
				}
				else if (dataProp)
					return data[i].identity;
			}
		},
		searchVersion: function (dataString) {
			var index = dataString.indexOf(this.versionSearchString);
			if (index == -1) return;
			return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
		},
		dataBrowser: [
			{
				string: navigator.userAgent,
				subString: "Chrome",
				identity: "Chrome"
			},
			{ 	string: navigator.userAgent,
				subString: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb"
			},
			{
				string: navigator.vendor,
				subString: "Apple",
				identity: "Safari",
				versionSearch: "Version"
			},
			{
				prop: window.opera,
				identity: "Opera"
			},
			{
				string: navigator.vendor,
				subString: "iCab",
				identity: "iCab"
			},
			{
				string: navigator.vendor,
				subString: "KDE",
				identity: "Konqueror"
			},
			{
				string: navigator.userAgent,
				subString: "Firefox",
				identity: "Firefox"
			},
			{
				string: navigator.vendor,
				subString: "Camino",
				identity: "Camino"
			},
			{		// for newer Netscapes (6+)
				string: navigator.userAgent,
				subString: "Netscape",
				identity: "Netscape"
			},
			{
				string: navigator.userAgent,
				subString: "MSIE",
				identity: "Explorer",
				versionSearch: "MSIE"
			},
			{
				string: navigator.userAgent,
				subString: "Gecko",
				identity: "Mozilla",
				versionSearch: "rv"
			},
			{ 		// for older Netscapes (4-)
				string: navigator.userAgent,
				subString: "Mozilla",
				identity: "Netscape",
				versionSearch: "Mozilla"
			}
		],
		dataOS : [
			{
				string: navigator.platform,
				subString: "Win",
				identity: "Windows"
			},
			{
				string: navigator.platform,
				subString: "Mac",
				identity: "Mac"
			},
			{
				   string: navigator.userAgent,
				   subString: "iPhone",
				   identity: "iPhone/iPod"
		    },
			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]

	};
	BrowserDetect.init();
	
var theID = null;
var $panels = $('#content > div');
var $container = $('#content');

// if false, we'll float all the panels left and fix the width 
// of the container
var horizontal = false;

// float the panels left if we're going horizontal
if (horizontal) {
  $panels.css({
    'float' : 'left',
    'position' : 'relative' // IE fix to ensure overflow is hidden
  });
  
  // calculate a new width for the container (so it holds all panels)
  $container.css('height', $panels[0].offsetHeight * $panels.height);
}

// collect the scroll object, at the same time apply the hidden overflow
// to remove the default scrollbars that will appear
var $scroll = $('#content').css('overflow', 'hidden');

// apply our left + right buttons
//$scroll
//  .before('<img class="scrollButtons left" src="images/scroll_left.png" />')
//  .after('<img class="scrollButtons right" src="images/scroll_right.png" />');

// handle nav selection
function selectNav() {
  $(this)
    .parents('ul:first')
      .find('a')
        .removeClass('selected')
      .end()
    .end()
    .addClass('selected');
}



//$('#slider .navigation').find('a').click(selectNav);

// go find the navigation link that has this target and select the nav
function trigger(data) {
  var el = $('#navigation').find('a[href$="' + data.id + '"]').get(0);
theID = data.id;
//alert($.cookie('tinmencookie'));
  selectNav.call(el);
}

if(window.location.hash){
	trigger({ id: window.location.hash.substr(1)});
}else{
}
$(window).resize(function(){
	if(null==theID){
		$('#navigation a:first').click();
	}else{
		$('#navigation').find('a[href$="' + theID + '"]').click();
	}
});


// offset is used to move to *exactly* the right place, since I'm using
// padding on my example, I need to subtract the amount of padding to
// the offset.  Try removing this to get a good idea of the effect
var offset = parseInt((horizontal ? 
  $container.css('paddingTop') : 
  $container.css('paddingLeft')) 
  || 0) * -1;


var scrollOptions = {
  target: $scroll, // the element that has the overflow
  
  // can be a selector which will be relative to the target
  items: $panels,
  
  navigation: '#navigation a',
  
  // selectors are NOT relative to document, i.e. make sure they're unique
  prev: 'img.left', 
  next: 'img.right',
  
  // allow the scroll effect to run both directions
  axis: 'y',
  
  onAfter: trigger, // our final callback
  
  offset: offset,
  
  // duration of the sliding effect
  duration: 1000,
  
  // easing - can be used with the easing plugin: 
  // http://gsgd.co.uk/sandbox/jquery/easing/
  easing: 'easeOutBounce'
};

// apply serialScroll to the slider - we chose this plugin because it 
// supports// the indexed next and previous scroll along with hooking 
// in to our navigation.
$('#content').serialScroll(scrollOptions);

// now apply localScroll to hook any other arbitrary links to trigger 
// the effect
$.localScroll(scrollOptions);

// finally, if the URL has a hash, move the slider in to position, 
// setting the duration to 1 because I don't want it to scroll in the
// very first page load.  We don't always need this, but it ensures
// the positioning is absolutely spot on when the pages loads.
scrollOptions.duration = 1;
$.localScroll.hash(scrollOptions);
//var firefox   = $.browser.firefox();

	$("#navigation li").hover(function() {
		  $(this).stop().animate( { fontSize:"1.5em" }, "fast" );
		}, function() {
		 $(this).stop().animate( { fontSize:"1.0em" }, "fast" );
		});
		
		$(".linkcontainer").hover(function() {
			  $(".bw", this).stop().animate({ opacity: 0.0 }, {duration:300 });
			}, function() {
			 	 $(".bw", this).stop().animate({ opacity: 1.0 }, {duration:300 });
			});
		

			
$(".joshross").hover(function() {
	$(".joshrossimg").fadeIn("fast");
}, function() {
	$(".joshrossimg").fadeOut("fast");
});
				
$(".findthat").hover(function() {
 $(".findthatimg").fadeIn("fast");
	}, function() {
$(".findthatimg").fadeOut("fast");
});
								
$(".mornington").hover(function() {
	$(".morningtonimg").fadeIn("fast");
}, function() {
	$(".morningtonimg").fadeOut("fast");
});		
								
$(".tinmen").hover(function() {
	$(".tinmenimg").fadeIn("fast");
}, function() {
	$(".tinmenimg").fadeOut("fast");
});		

if(BrowserDetect.browser=="Firefox"){
	$(".linkcontainer a").css("height","63px");
	}
	
	$("#ajax-contact-form").submit(function(){

	var str = $(this).serialize();

	   $.ajax({
	   type: "POST",
	   url: "contact.php",
	   data: str,
	   success: function(msg){

	$("#note").ajaxComplete(function(event, request, settings){

	if(msg == 'OK') // Message Sent? Show the 'Thank You' message and hide the form
	{
	result = '<div class="notification_ok">Ta fer t\'email.</div>';
	$("#fields").hide();
	}
	else
	{
	result = msg;
	}

	$(this).html(result);

	});

	}

	 });

	return false;

	});
				

});