$(document).ready(function(){
	var windowWidth = 0;
	var	imageWidth = 0;
	var	imageHeight = 0;
	var	imageRatio = 0;
	var docHeight = 0;
	var contentHeight = 0;
	var direction = 0;
	var totalSize = 0;
	var oldMenu = 0;
	var menuId = 0;
	var timer = 0;
	var showPC = false;
	var bookingVisible = false;
	var nowHeight = 0;
	var curBgLink = 0;


	$('#menu-outer > div').each(function(){
		if($(this).height()>nowHeight){
			nowHeight = $(this).height();
		}
	});
	$('#menu-outer > div, #menu-outer').height(nowHeight);

	
	var whiteBarHeight = $('#white-bar').height();
	var headerHeight = $('#header').height();
	var bookingFormHeight = $('#booking-form-container').height();
	var postcardWidth = $('#postcard-column').width();
	var postcardHeight = $('#send-postcard').height();
	var menuHeight = $('.wide-menu').height();
	var menuOffset = 0;
	var	contentShown = true;
	var menuTabName;

	if ($.browser.msie && $.browser.version.substr(0,1)<=7) {
		//$('#navigation > li > a').css('margin-left','-16px');
	}

	$(window).bind('resize',resizeBigImage);
	$(window).bind('load',resizeBigImage);

	$('#booking-form-container').hide();
	$('.wide-menu, .thin-menu, #send-postcard').css({
		'width':'0'
	}).hide();

	if($('#footer-quotes').size() > 0) {
		$('#footer-quotes p:not(":first")').hide();
		setInterval(changeQuote,3000);
	}

	function changeQuote() {
		if($('#footer-quotes p:visible').next('p').size()>0) {
			$('#footer-quotes p:visible').fadeOut();
			$('#footer-quotes p:visible').next().fadeIn();
		} else {
			$('#footer-quotes p:visible').fadeOut();
			$('#footer-quotes p:first').fadeIn();
		}
	}


	$('.top-level > a').click(function(){
		timer = setInterval(checkHeaderHeight,40);

		if($(this).parent().children('ul').is(':visible')) {
			$(this).parent().children('ul').slideUp(function(){
				clearInterval(timer);
			});
			$(this).parent().removeClass('on');
			if($(this).parent().is('.down-arrow')){
				$('.down-arrow').addClass('up-arrow').removeClass('down-arrow');
			}
		} else {
			//$('#navigation > li .on').removeClass('on');
			if($(this).parent().parent('#navigation').size() > 0) {
				$('#navigation > li  ul:visible').slideUp();
				$('.down-arrow').addClass('up-arrow').removeClass('down-arrow');
				//$('.on').removeClass('on');
			} else if($(this).parent().parent().parent().parent('#navigation').size() > 0) {
				$('#navigation > li ul ul:visible').slideUp();
			}


			$(this).parent().children('ul').slideDown(function(){
				clearInterval(timer);
			});
			$('.on').removeClass('on');

			if($(this).parent().is('.up-arrow')){
				$(this).parent().addClass('down-arrow').removeClass('up-arrow');
				$(this).parent().addClass('on');
			} else {
				$(this).parents('#explore-nav,#cuisine-nav,#accomodation-nav').addClass('on');
			}
			if($('.on .curpage').size() > 0){
				$('.curpage').parents('ul').slideDown();
			}
		}
		return false;
	})
	
	
	$('#navigation').mouseleave(function(){
		overNav=0;
		setTimeout(closeNav,500);
	}).mouseenter(function(){
		overNav=1;
	})

	function closeNav() {
		if(overNav==0) {
			$('.on').removeClass('on').children('ul').slideUp();
		}
	}

	/*
	//show nav on hover - looked awful so turned off

	$('#accomodation-nav> a,#cuisine-nav> a,#explore-nav> a').mouseenter(function(){
		timer = setInterval(checkHeaderHeight,40);

		if($(this).parent().children('ul').is(':visible')) {
			$(this).parent().children('ul').slideUp(function(){
				clearInterval(timer);
			});
			$(this).parent().removeClass('on');
			if($(this).parent().is('.down-arrow')){
				$('.down-arrow').addClass('up-arrow').removeClass('down-arrow');
			}
		} else {
			$('#navigation > li .on').removeClass('on');
			if($(this).parent().parent('#navigation').size() > 0) {
				$('#navigation > li  ul:visible').slideUp();
				$('.down-arrow').addClass('up-arrow').removeClass('down-arrow');
				$('.on').removeClass('on');
			} else if($(this).parent().parent().parent().parent('#navigation').size() > 0) {
				$('#navigation > li ul ul:visible').slideUp();
			}

			$(this).parent().children('ul').slideDown(function(){
				clearInterval(timer);
			});

			if($(this).parent().is('.up-arrow')){
				$(this).parent().addClass('down-arrow').removeClass('up-arrow');
				$(this).parent().addClass('on');
			} else {
				$(this).parent().addClass('on');
			}
		}
		return false;

	})	
	*/

	if($('.curpage').size()>0) {
		$('.curpage').parent().children('ul').show();
		$('.curpage').parents().show();
		if($('.curpage').parents('.explore').size()==0){
			if($('.curpage').parents('.cuisine').size()>0){
				$('.curpage').parents('.cuisine').addClass('on');
			} else {
				$('.curpage').parents('.top-level').addClass('on');
			}
		} else {
			$('.explore .curpage').parent().parent().parent().addClass('on');
		}
	}	


	$('.menu-nav li').bind('click', showMenuSection);
	$('#news-reviews-left li').bind('click', showNewsSection);


	$('a.menu-btn,a.ocean-way').bind('click', showMenu);
	$('a.send-postcard').bind('click', showPostcard);
	
	$('#send-postcard a.back-btn-blk').click(function(){
		$('a.send-postcard').trigger('click');
		return false;
	});
	
	$('a.show-full-image').toggle(function(){
		if($('.wide-menu, .thin-menu').is(':visible')) {
			$('.wide-menu, .thin-menu').animate({'width':0},function(){	
				hideContent();
				oldMenu = 0;
			})
		} else {
			hideContent();
		}
	}, function(){
		if($('.wide-menu, .thin-menu').is(':visible')) {
			$('.wide-menu, .thin-menu').animate({'width':0},function(){	
				showContent();
				oldMenu = 0;
			})
		} else {
			showContent();
		}
	});
	
	$('a.booking-enquiries,a.book-a-table,a.sales-enquiries, a.owners-enquiries').toggle(function(){
		if($('.wide-menu, .thin-menu, #send-postcard').is(':visible')) {
			$('.wide-menu, .thin-menu, #send-postcard').animate({'width':0},function(){	
				showBookingForm();
				
			})
		} else {
			showBookingForm();

		}
	}, function(){
		if($('.wide-menu, .thin-menu, #send-postcard').is(':visible')) {
			$('.wide-menu, .thin-menu, #send-postcard').animate({'width':0},function(){	
				hideBookingForm();
			})
		} else {
			hideBookingForm();
		}
	});
	
	$('#booking-form-container a.back-btn-blk').click(function(){
		$('a.booking-enquiries,a.book-a-table, a.sales-enquiries').trigger('click');
		return false;
	});

	$('.wide-menu:not("#policy-menu") .close-menu').click(function(){
		$('#'+$(this).parent().attr('id').replace('-menu','')).trigger('click');
		return false;
	})

	
	$('a.right-gallery-arrow').click(function(){
		direction = '+';
		moveThumbs();
		return false
	});
	
	$('a.left-gallery-arrow').click(function(){
		direction = '-';
		moveThumbs();
		return false
	});


	if($('#navigation > .up-arrow.on').size()>0){
		$('.up-arrow').removeClass('up-arrow').addClass('down-arrow');
	};
	
	if($('#thumbs').size() > 0 && typeof(cmsActive)=='undefined') {
		$('#thumbs a:first').addClass('selected');
		$('#thumbs a').click(function(){
			var imageSrcLink = $(this).attr('href');
			var imageClicked = $(this).children('img');
			$('.thecurimg').removeClass('thecurimg');
			$('#thumbs a.selected').removeClass('selected')
			$(this).addClass('thecurimg selected');
			
			$('#full-width-image').addClass('loading');
			
			$('#full-width-image img').fadeOut(function(){
				$('#full-width-image img').attr('src',imageSrcLink).load(function(){
					$('#full-width-image img').fadeIn(function(){
						$('#full-width-image').removeClass('loading');
					});
				})
			})
			if($('#thumbs-scroller-container').size()>0) {
				$('#left-postcard-column img').attr('src',imageSrcLink.replace('large','postcard-previews'));
				$('#pc-image-hidden-input').attr('value',imageSrcLink.replace('large','postcards'))
			}
			
			//$(this).attr('href');
			return false;
		});

	if($('#thumbs a').size() > 1 && galleryPage < 1) {
		galleryInterval = setInterval(function(){
			if($('#thumbs a.selected').next('a').size()>0){
				$('#thumbs a.selected').removeClass('selected').next('a').addClass('selected');	
			} else {
				$('#thumbs a.selected').removeClass('selected');
				$('#thumbs a:first').addClass('selected');
			}
			$('#thumbs a.selected').trigger('click');
		},12000)
	}
		
		
	};
	$('a.send-postcard').click(function(e){
		e.preventDefault();
//		clearInterval(galleryInterval);						  
 	 });

	if($('#thumbs-scroller-container').size()>0){
		initialiseGallery()
	}


	// Image auto rotation stuff
/*	$.doPreload = function() {
		var pic = new Image(1920,800);
		pic.src = $('#thumbs').children('a').eq(theNextImage).attr('href');
	}

	$.nextImage = function() {
		if (showStopped == 0) {
			var href = $('#thumbs').children('a').eq(theNextImage).attr('href');

			$('#big-image-2').attr('src', href).load(function() {
				$('#big-image').fadeOut(3000);
				$('#big-image-2').fadeIn(3000, function() {
					$('#big-image').attr('src', $('#big-image-2').attr('src'));
					$('#big-image-2').hide();
					$('#big-image').show();
				});
			});

			theNextImage++;

			if (theNextImage >= $('#thumbs').children('a').length)
				theNextImage = 0;

			$.doPreload();
		}
	}
	$('#thumbs a').click(function() {
		showStopped = 1;
		$('#big-image-2').hide();
	});

	var theNextImage = 1;
	var showStopped = 0;
	
	$('#big-image-2').hide();
    setInterval("$.nextImage()", 18000);
	setTimeout('$.doPreload()', 1); // Bit of a hack - seems to break if not called with a timeout
	// End image auto rotation stuff
*/
	
	function resizeBigImage() {
		windowWidth = $(window).width();
		windowHeight = $(window).height();
		imageWidth = $('#full-width-image img').width();
		imageHeight = $('#full-width-image img').height();
		contentHeight = $('#white-bar').height();
		footerHeight = $('#footer').height();
		imageRatio = imageHeight / imageWidth; 

		if(windowWidth>960) {
			$('#full-width-image img').css({
				width:(windowHeight - footerHeight) / imageRatio,
				height:windowHeight - footerHeight
			})
			imageWidth = $('#full-width-image img').width();
			imageHeight = $('#full-width-image img').height();
			
			if(imageWidth<windowWidth && $('#white-bar').size()<1) {
				if(parseInt(windowWidth * imageRatio) - ($('#title').height() + $('#black-bar').height()) < postcardHeight) {
					$('#full-width-image img').css({
						width: (postcardHeight  + $('#black-bar').height()) / imageRatio,
						height:postcardHeight + $('#title').height() + $('#black-bar').height()
					})
				} else {
					$('#full-width-image img').css({
						width:windowWidth,
						height:windowWidth * imageRatio
					})
//			alert('');	
				}
			} else if ($('#white-bar').size()>0) {
				var contentHeightInc = ($('#navigation').height()) + $('#title').height() + $('#black-bar').height() + whiteBarHeight;
				if(contentHeightInc / imageRatio < windowWidth ) {
					if(contentHeightInc < menuHeight + contentHeight + $('#black-bar').height() + $('#title').height() && (menuHeight + contentHeight + $('#black-bar').height() + $('#title').height()) / imageRatio > windowWidth) {
						$('#full-width-image img').css({
							width:(menuHeight + contentHeight + $('#black-bar').height() + $('#title').height()) / imageRatio,
							height:menuHeight + contentHeight + $('#black-bar').height() + $('#title').height()
						})
					} else {
						$('#full-width-image img').css({
							width:windowWidth,
							height:windowWidth * imageRatio
						})
					}
				} else {
					if(contentHeightInc < menuHeight + contentHeight + $('#black-bar').height() + $('#title').height()) {
						$('#full-width-image img').css({
							width:(menuHeight + contentHeight + $('#black-bar').height() + $('#title').height()) / imageRatio,
							height:menuHeight + contentHeight + $('#black-bar').height() + $('#title').height()
						})
					} else {
						$('#full-width-image img').css({
							width:contentHeightInc / imageRatio,
							height:contentHeightInc
						})
					}
				}

				if($('#full-width-image img').height() > 800) {
					$('#full-width-image img').css({
						width:800 / imageRatio,
						height:800
					})
				}
			} else if($('#send-postcard').size()>0) {
				imageWidth = $('#full-width-image img').width();
				imageHeight = $('#full-width-image img').height();
				if(imageHeight - ($('#title').height() + $('#black-bar').height()) < postcardHeight) {
					$('#full-width-image img').css({
						width: (postcardHeight  + $('#black-bar').height()) / imageRatio,
						height:postcardHeight + $('#title').height() + $('#black-bar').height()
					})
				}
			} 

			if($('.wide-menu').size()>0) {
				imageWidth = $('#full-width-image img').width();
				imageHeight = $('#full-width-image img').height();
				if(imageHeight - $('#black-bar').height() - $('#white-bar').height() < menuHeight) {
					$('#full-width-image img').css({
						width:(menuHeight + $('#black-bar').height() +$('#white-bar').height()) / imageRatio,
						height:menuHeight + $('#black-bar').height() +$('#white-bar').height()
					})
				}
			}
		}
		imageWidth = $('#full-width-image img').width();
		imageHeight = $('#full-width-image img').height();
		
		$('#full-width-image').height($('#full-width-image img').height());
		repositionImage();
		repositionContent();
	}
	
	function repositionImage() {
		windowWidth = $(window).width();
		imageWidth = $('#full-width-image img').width();
		
		$('#full-width-image img').css({
			marginLeft:-((imageWidth - windowWidth) / 2)
		});
	}
	
	function repositionContent() {
		docHeight = $(window).height();
		contentHeight = $('#white-bar').height() + $('#footer').height();
		imageHeight = $('#full-width-image img').height();
		if(docHeight > contentHeight + imageHeight && varPage == "home") {
			$('#header').height(imageHeight - $('#black-bar').height());
		} else if ($('#white-bar:visible').size()>0) {
			//height fix so accomodation pages are same height
			if(varPage == 'heavenly-beach-houses' || varPage == 'big-beach-house' || varPage == 'premium-suites' || varPage == 'classic-rock-suites' || varPage == 'contemporary-beach-rooms' || varPage == 'garden-cottages') {
				$('#header').height($('#navigation').height() + 14);
			 } else {
				$('#header').height(imageHeight - $('#black-bar').height() - $('#title').height() - $('#content-holder').height() + $('#footer').height())
			 }	
		} else {	
			$('#header').height(imageHeight - $('#black-bar').height() - $('#title').height())	
		}

		if($('#header').height() < $('#navigation').height() + 14) {
			$('#header').height($('#navigation').height() + 14);
		}

		if($('.wide-menu:visible, .thin-menu:visible').size() >0) {
			menuHeight = $('#black-bar').offset();
			$('.wide-menu:visible, .thin-menu:visible').width((windowWidth / 2) + $('#' + menuId + '-menu table').width() - (960/2));

		}
	}
	
	function initialiseGallery() {
		$('#thumbs img').css({'float':'left','marginRight':'5px'})
		$('#thumbs img').each(function(){
			totalSize =	$(this).width() + parseInt($(this).css('marginRight').replace('px','')) + totalSize;
		});
		$('#thumbs-wrapper, #thumbs').css({
			'position':'absolute',
			'top':0,
			'left':0,
			'width': totalSize
		});

		$('#thumbs a').click(function() {
			$('#photo-caption h2').html($(this).children('img').attr('alt'));
		});
	}

	$.thumbAdded = function() {
		totalSize=0;
		initialiseGallery();
		$('#thumbs-wrapper').animate({'left': -($('#thumbs').width() - $('#thumbs-scroller').width())})
	}

	function moveThumbs() {
		var thumbsPosition = $('#thumbs-wrapper').position();
		if(direction=='+' && thumbsPosition.left > -($('#thumbs-wrapper').width() - $('#thumbs-scroller').width()) && $('#thumbs-wrapper:animated').size()<1) {
			$('#thumbs-wrapper').animate({'left': '-=' + $('#thumbs-scroller').width()})
		}
		else if(direction=='-' && thumbsPosition.left < 0 && $('#thumbs-wrapper:animated').size()<1) {
			$('#thumbs-wrapper').animate({'left': '+=' + $('#thumbs-scroller').width()})
		}
	}

	function showContent() {	
		contentShown = true;
		$('#header').stop().animate({
			'height':headerHeight
		},1000)
		$('#white-bar').slideDown(1000);
		$('a.show-full-image').html('Show Full Image');
		$('a.show-full-image').css('backgroundImage','url(/images/bg/grey-down-arrow.gif)');
		return false;
	}

	function hideContent() {	
		contentShown = false;
		headerHeight = $('#header').height();
		$('#header').stop().animate({
			'height':$('#full-width-image img').height() - $('#title').height() - $('#black-bar').height()
		},1000)
		
		$('#white-bar').slideUp(1000);
		$('a.show-full-image').html('Show Content');
		$('a.show-full-image').css('backgroundImage','url(/images/bg/grey-up-arrow.gif)');
		return false;
	}
	
	function showBookingForm() {
		
		//get height of hidden booking div
		$("#booking-form-container").css({'visibility':'hidden','display':'block'});
		bookingHeight = $("#booking-form-container").height();
		$("#booking-form-container").css({'visibility':'visible','display':'none'});
		$('#booking-form-container .container').height(bookingHeight);

		if($('#white-bar').is(':visible')) {
			hideContent();
			bookingVisible = true;
		}
		$('#booking-form-container').slideDown(1000);
		if($('#full-width-image img').height() - bookingFormHeight - $('#black-bar').height() - $('#title').height() < $('#navigation').height()) {
			$('#header').stop().animate({
				'height':$('#navigation').height()
			}, 1000);		
		}	else {
			$('#header').stop().animate({
				'height':$('#full-width-image img').height() - bookingFormHeight - $('#black-bar').height() - $('#title').height()
			}, 1000);		
		}


		return false;
	}
	
	function hideBookingForm() {
		$('#booking-form-container').slideUp(1000);
		if(showPC==true) {
				showPc=false;
			$('#header').stop().animate({
				'height':$('#full-width-image img').height() - $('#black-bar').height() - $('#title').height() - whiteBarHeight
			}, 1000, function(){
				showPostcard();
			});
		} else {
			if(contentShown == false) {
				$('#header').stop().animate({
					'height':$('#full-width-image img').height() - $('#black-bar').height() - $('#title').height()
				}, 1000);
			} else {
				$('#header').stop().animate({
					'height':$('#full-width-image img').height() - $('#black-bar').height() - $('#title').height() - whiteBarHeight
				}, 1000);
			}
		}
		if(bookingVisible==true) {
			showContent();
			bookingVisible = false;
		}
		return false;
	}

	function showMenu() {
		menuId = $(this).attr('id');
		menuOffset = $('#black-bar').offset();
		
		if(menuId != oldMenu) {
			$('.wide-menu, .thin-menu').animate({'width':0},function(){
				$('.wide-menu, .thin-menu').hide();
			});	
			if(menuOffset.top> menuHeight){
				$('#' + menuId + '-menu').height(menuOffset.top);
			} else {
				$('#' + menuId + '-menu').height(menuHeight -13);				
			}
		
			$('#' + menuId + '-menu').animate({
				'width':(windowWidth / 2) + $('#menu-outer').width()  - (960/2)
			});
			oldMenu = menuId;
		} else {
			$('.wide-menu, .thin-menu').animate({'width':0},function(){
				$('.wide-menu, .thin-menu').hide();
			})
			oldMenu = 0;
		}
		
		
		return false;
	}

	$('#policy-menu .close-menu').click(function(){
		$('.policy-menu a').trigger('click')
	})

	$('.policy-menu a').click(function() {
		menuId = 'policy';
		menuOffset = $('#black-bar').offset();
		
		if(menuId != oldMenu) {
			$('.wide-menu, .thin-menu').animate({'width':0},function(){
				$('.wide-menu, .thin-menu').hide();
			});	
			if(menuOffset.top> menuHeight){
				$('#' + menuId + '-menu').height(menuOffset.top);
			} else {
				$('#' + menuId + '-menu').height(menuHeight -13);				
			}
		
			$('#' + menuId + '-menu').animate({
				'width':(windowWidth / 2) + $('#menu-outer').width()  - (960/2)
			});
			oldMenu = menuId;
		} else {
			$('.wide-menu, .thin-menu').animate({'width':0},function(){
				$('.wide-menu, .thin-menu').hide();
			})
			oldMenu = 0;
		}
		
		
		return false;
	})
	
	$('.menu-btn').click(function() {
			$('.wide-menu #menu-outer .menu-tab').css('right','-3000px');	
			$('.wide-menu #menu-outer .menu-description').css('right','0px');	
			$('.menu-nav ul li').removeClass('selected');	
			
	  });

	
	function showMenuSection() {
		menuTabName = $(this).attr('id');
		
		$('.menu-tab').animate({'right':-3000})
		
		$('.menu-nav ul li').removeClass('selected');	
		$(this).addClass('selected');
	
		$('.'+ menuTabName).animate({'right':0})		
	}
	
	function showNewsSection() {
		sectionTabName = $(this).attr('id');
		
		$('.news-year-tab').animate({'right':-2000})
		
		$('#news-reviews-left ul li').removeClass('selected');	
		$(this).addClass('selected');
	
		$('ul.'+ sectionTabName).animate({'right':0})
		newsHeight();

		
		
	}
	
	function newsHeight() {
		//set height on news-reviews-right
		var numberOfArticles = $('#news-reviews-right ul.' + sectionTabName + ' li').size()
		var sizeOfArticle = $('#news-reviews-right li').height()

		var marginOfArticle = parseInt($('#news-reviews-right li').css('margin-bottom').replace('px',''));
		var articleHeight = sizeOfArticle + marginOfArticle;
		
		if (numberOfArticles < 6) {
			var entireHeight = 30 + (articleHeight);
		} else {
			var entireHeight = 30  + (articleHeight) * ((numberOfArticles / 6) + 1);

		}

		$('#news-reviews-right').height(entireHeight);

	}
	
	
	
	
	$.newsHeightOnLoad = function() {
		sectionTabName = $('#news-reviews-left ul li').first().attr('id');

		//set height on news-reviews-right
		var numberOfArticles = $('#news-reviews-right ul.' + sectionTabName + ' li').size()
		var sizeOfArticle = $('#news-reviews-right li').height()
		var marginOfArticle = parseInt($('#news-reviews-right li').css('margin-bottom').replace('px',''));
		
		var articleHeight = sizeOfArticle + marginOfArticle;

		//30  is to include margin-top and bottom of main div
		if (numberOfArticles < 6) {
			var entireHeight = 30 + (articleHeight);
		} else {
			var entireHeight = 30  + (articleHeight) * ((numberOfArticles / 6) + 1);
		}
		$('#news-reviews-right').height(entireHeight);

	}
	
	function showPostcard() {
		if($('#booking-form-container').is(":visible")){
			showPC = true;
			hideBookingForm();
		} else {
			
			menuOffset = $('#black-bar').offset();
			if($('#send-postcard').is(':not(":visible")')) {
				$('#send-postcard').height(menuOffset.top);
			
				$('#send-postcard').animate({
					'width':(windowWidth / 2) + postcardWidth - (960/2)
				});
				oldMenu = menuId;
			} else {
				$('#send-postcard').animate({'width':0},function(){
					$('#send-postcard').hide();
				})
				oldMenu = 0;
			}
			bookingVisible = false;
		}
	
		return false;
	}
	
	function checkHeaderHeight() {
		headerHeight = $('#header').height();
		navHeight = $('#navigation').height() + 14;
		if(headerHeight < navHeight) {
			$('#header').css('height',navHeight)
		}
	}

	if((varPage=='gallery-accommodation' || varPage=='gallery-food' || varPage == 'gallery-parties-events' || varPage == 'gallery-experience' || varPage == 'gallery-wellbeing') && $('#thumbs a').size()>1 ) {
		$('.next-arrow').click(function(){
			if($('.thecurimg').next().size()>0){
				curBgLink = $('.thecurimg').removeClass('thecurimg').next().addClass('thecurimg').attr('href');
			} else {
				$('.thecurimg').removeClass('thecurimg');
				curBgLink = $('#thumbs a:first').addClass('thecurimg').attr('href');
			}
			$('#full-width-image img').fadeOut(function(){
				$('#full-width-image img').attr('src',curBgLink).load(function(){
					$('#full-width-image img').fadeIn(function(){
						$('#full-width-image').removeClass('loading');
					});
				})
			})
			return false;
		})
		$('.previous-arrow').click(function(){
			if($('.thecurimg').prev().size()>0){
				curBgLink = $('.thecurimg').removeClass('thecurimg').prev().addClass('thecurimg').attr('href');
			} else {
				$('.thecurimg').removeClass('thecurimg');
				curBgLink = $('#thumbs a:last').addClass('thecurimg').attr('href');
			}
			$('#full-width-image img').fadeOut(function(){
				$('#full-width-image img').attr('src',curBgLink).load(function(){
					$('#full-width-image img').fadeIn(function(){
						$('#full-width-image').removeClass('loading');
					});
				})
			})
			return false;
		})
	}
	
	//home page ticker
	$('.horizontal_scroller').SetScroller({	
		velocity: 	 70,
		direction: 	 'horizontal',
		startfrom: 	 'right',
		loop:		 'infinite',
		movetype: 	 'linear',
		onmouseover: 'play',
		onmouseout:  'play',
		onstartup: 	 'play',
		cursor: 	 'pointer'
	});

	$('#hear-how').change(function() {
		if ($(this).val() == 'Other') {
			$('#hear-other').show();
		}
		else {
			$('#hear-other').hide();
		}
	});
	
	//Virtual Guestbook
	var guestHeight = $('#guestbook-comments').height();
	var guestComments = $('#guestbook-comments');
	
	$(guestComments).css({'height' : '385px'});
	$(guestComments).after('<a href="#" id="reveal-comments">Show More</a>');
	
	$('#reveal-comments').addClass('active');
	$('#reveal-comments').click(function(e) {
		e.preventDefault();
		
		if ($(this).hasClass('active')) {
			$(guestComments).animate({'height': guestHeight + 'px'});
			$('#reveal-comments').removeClass('active');
			$(this).text('Show Less');
		} else {
			$(guestComments).animate({'height': '385px'});
			$('#reveal-comments').addClass('active');
			$(this).text('Show More');
		}
		
	});
	
	

});

//remove class on from navigation on mouseleave
function removeClassOn(idName){
 setTimeout(function(){
		$('#'+idName).removeClass('on');
  },600);
};

//remove down arrrow delay
function removeDownArrow(){
  setTimeout(function(){
	$('.down-arrow').addClass('up-arrow').removeClass('down-arrow');
  },600);
};
