function myInit() {

	// all links with rel=external to open in new window
	/*$('A[rel="external"]').each( function() {
		$(this).attr('target',"_blank");
		});*/
	//
	$("a[href^='http:']").not("[href*='jamiesfarm.org.uk']").attr('target','_blank');
	
	$('#navigation > li:has(ul) > a').click( function() {											  
		return false;
		}); 
	
	
	$("#navigation > li").hover( function () {		
		$("#navigation > li").removeClass('hover');
		$(this).addClass('hover');
		},function () {
		$(this).removeClass('hover');
		}
		);
	/*
	$("#navigation > li > ul").hover( function () {		
		},function () {
		$(this).parent().removeClass('hover');
		}
	);	
	*/
	
	
	
	$('#galleryScrollLeft').click( function() {
		galleryScrollLeft();
		return false;
		});
	
	$('#galleryScrollRight').click( function() {
		galleryScrollRight();
		return false;
		});
	
	$('.thumbnail').click( function() {
		imageId = this.id;
		imageId = imageId.replace('thumb_','');
		loadImage(imageId);
		return false;
		});
	
	$('#imageLarge').click( function() {
		loadImage(nextId);
		return false;
		});
	
	$("#commentForm").submit(function() {		
		$('#commentForm').attr('method','post');		
		});
	
	$("#commentForm").validate({
		 ignoreTitle:true,
		 rules: {
			name:{required: true},
			email:{required: true,email: true},
			comment:{required: true}			
			}
		});

	$('#slideshow').show().innerfade({ 
		speed: 600, 
		timeout: 4000, 
		type: 'sequence', 
		containerheight: '193px'
		});
	
	
	
	$('#faq h3 a').click( function() {			
		$('#content div#faq div.faq').hide();
		$('#faq .on').removeClass('on');
								
		var theId = this.id;
		theDiv = theId.replace("q","a");		
		$('#'+theDiv).show();
		$(this).parent().addClass('on');
			
		return false;
		});
	
	$("#content div#faq div.faq").hide();
	
	
	$('#slideshow').show().innerfade({ 
		speed: 600, 
		timeout: 4000, 
		type: 'sequence', 
		containerheight: '193px'
		});
	}

function loadImage(imageId) {
	
	if (!imageId) {
		return;
		}
		
	$('#imageLarge').fadeOut(200, function () {		
		$.ajax({
			type: "POST",
			url: "/loadImage.php",
			data: "imageId="+imageId,
			success: function(returned){	
				myData = returned.split("~");					
				$('#imageLarge').html(myData[0]);
				nextId = myData[1];
				$('#imageLarge').fadeIn(200, function () {				
					// scroll thumbnail into view
					//scrollThumbnails(myData[1]);
					
					});				
				}
			});			
		});	
	}

function galleryScrollLeft() {		
	if (scrollToInt > 0) {
		scrollToInt = parseInt(scrollToInt) - parseInt(scrollIncrement);
		scrollThumbnails(scrollToInt);
		}
	}
function galleryScrollRight() {	
	if (scrollToInt < (maxWidth-paneWidth)) {
		scrollToInt = parseInt(scrollToInt) + parseInt(scrollIncrement);
		scrollThumbnails(scrollToInt);
		} 
	}

function scrollToImage(imageId) {
	
	containerOffset = $('#thumbnails').offset();	
	thumbOffset = $('#thumb_'+imageId).offset();	
	scrollPixel = thumbOffset.left - containerOffset.left;	
	scrollThumbnails(scrollPixel)
	
	}
	
function scrollThumbnails(scrollPixel) {	
	
	if (scrollPixel < 0) {
		scrollPixel = 0;
		}
		
	$('#thumbnails').scrollTo(  scrollPixel, { axis:'x', duration:1000 } );	
	scrollToInt = parseInt(scrollPixel);	
	if (scrollPixel >= (maxWidth-paneWidth)) {
		$('#galleryScrollRight').addClass('disabled');
		}
	if (scrollPixel > 0) {
		//$('#scrollUp').fadeIn('normal');
		$('#galleryScrollLeft').removeClass('disabled');
		}
	if (scrollPixel < (maxWidth-paneWidth)) {
		//$('#scrollDown').fadeIn('normal');
		$('#galleryScrollRight').removeClass('disabled');
		}
	if (scrollPixel == 0) {
		//$('#scrollUp').fadeOut('normal');
		$('#galleryScrollLeft').addClass('disabled');
		}
	}