 $(function(){



// (function(){
// 	var toggle = $('.side b');
// 	var slide = $('.side dd');
// 	var all = [];

// 	if($('.side')){

// 		$('.side dd').each(function(i){
// 			var ti = slide.index(this);
// 			all[ti] = $(this).height();
// 		}).height(30);


// 		toggle.bind('click', function(){
// 			var ti = toggle.index(this);

// 			toggle.html('show');
			
// 			if(slide.eq(ti).height()>30) {
// 				slide
// 				.eq(ti)
// 				.animate({height: 30}, {queue:false})
// 				.css({color: '#cbc1aa'});
// 			} else {
// 				slide
// 				.animate({height: 30}, {queue:false})
// 				.css({color: '#cbc1aa'})
// 				.eq(ti)
// 				.animate({height: all[ti]}, {queue:false})
// 				.css({color: '#65552c'});

// 				toggle.eq(ti).html('hide');
// 			}


// 		});
// 	}
// })();


	if($('.book-form').length){

		var shipping = {
			'6.25'	:	'1st Class (UK)',
			'6.95'	:	'Recorded (UK)',
			'8.80'	:	'Special (UK)',
			'9.65'	:	'Airmail (EU)',
			'18.80'	:	'Airmail (ROW)'
		};
		var names = [
			'Corrigans Mayfair:The Clatter Of Forks and Spoons',
			'Corrigans Mayfair:From the Waters and the Wild',
			'Corrigans Mayfair:Cookery School'
		];
		
		var bf = $('.book-form');
		var bfi = $('.book-form select[name=shipping]');
		var bfn = $('.book-form input[name=item_name]');
		
		
		//change event
		bf.children('select[name=shipping]').bind('change',function(){
			
			//get the index
			var ti = bfi.index(this)
			bfn.eq(ti).val(names[ti] + ' - ' + shipping[$(this).val()]);
			
		});
	
	}
	


	$('#slider').anythingSlider({
	expand              : true,
	buildArrows			: false,
	resizeContents      : true,
	easing              : "swing",
	startText           : "Start",   // Start button text
	stopText            : "Stop",    // Stop button text
	navigationFormatter : 
	function(index, panel)
	{ // Format navigation labels with text
		return ['Picnic Hampers', 'Gift Vouchers', 'Cookery Books'][index - 1];
	}

	});

/*
	TIPSY
*/
$("a,img,h1,h2,h3,input,span").each(function(){if($(this).attr("title").length>0){$(this).tipsy({opacity:1,html:true,gravity:"s"})}});

//FANCYBOX
$("a.oo").fancybox({
	hideOnContentClick: true,
	overlayOpacity:0.8,
	overlayColor:'#000',
	padding:10,
	autoDimensions:false,
	height:600,
	width:900
});



	/* setup navigation */
	
	$('#nav_bar a').each(function(){
		$(this).children('span').width($(this).width()+40);
	});
	
	$('#nav_bar a').hover(function(){
		$(this).animate({color:'#9A8348'},{queue:false}).children('span').animate({top:3},{queue:false});
	},function(){
		$(this).animate({color:'#ffffff'},{queue:false}).children('span').animate({top:40},{queue:false});
	});



	/* Hide content */
	
	var button = $('#show_hide_btn');
	
	button.toggle(function(){
		$('#upper_content').animate({
						duration: 2000,
						queue: false,
						marginTop: -485						
		});
		
		button.text('Show Text');
		
		
		
		},function(){
		$('#upper_content').animate({
						duration: 2000,
				queue: false,
						marginTop: 0					
		});
		
		button.text('Gallery');
		
	
	});
	
	
	
	$('#other_r').click(function(){
		if($('#expand').height()==5) {
			h=80;
			$('#other_r').html('Hide');
		} else if($('#expand').height()==80) {
			h=5;
			$('#other_r').html('Show');
		};
		$('#expand').delay(50).animate({height:h});
	});
	
	
	if($('#bg_images img').length){
		$('#bg_images').rotary();
	}
	
	
	
	/*SECONDARY SCROLL
	$('#reviews_wrapper').rotary({
		auto: {interval:10000},
		changer: 'div.review_item',
		onstage: {left:0},
		offstage: {left:-400},
		ext: {
			queue:false,
			duration:500,
			easing:'swing'
		},
		control: {
			ind: {
				element: $('#scrollerswitcher a'),
				binding: 'click',
				onclass: 'cur'
			}
		}
	});*/
	
	
	//NEWSLETTER SIGNUP
	
	$('#newsletter_return').hide();

	$('#newsletter').submit(function(){
		chkeml = $('#newsletter_email input').checkEmail();
		fname = $('#newsletter_fname input').val();
		sname = $('#newsletter_sname input').val();
		emlval = $('#newsletter_email input').val();
				
		if(chkeml)		
		{
			
			$.ajax({
				type: "GET",
				url:"plugs/baf/process.php",
				data: "emailadd=" + emlval + "&fname=" + fname + "&sname=" + sname,
				success: function(data){
					switch(data){
						case "failed":
							message="Error adding to the database";
							$('#newsletter_return').html(message).fadeIn();
							$('#newsletter_email input, #newsletter_fname input, #newsletter_sname input')
							
						break;
						case "success":
							message="<p style=\"color: #ffffff; z-index: 10; background-color: #339900;\">Thank you. Your email has been added to our newsletter database.</p>";
						
							$('#newsletter').slideUp();
							$('#newsletter_return').html(message).fadeIn();
							$('#newsletter_email input, #newsletter_fname input, #newsletter_sname input')
							.val("")
							
						break;
						case "email":
							message="Your email address is already registered";
							$('#newsletter_return').html(message).fadeIn();
							$('#newsletter_email input, #newsletter_fname input, #newsletter_sname input')
							.removeClass('loading');
							$('#newsletter_return').delay(1900).slideUp();
						break;
					}
				}
			});
		}
		else
		{
			$('#newsletter_return').html("Please supply a valid email address.").slideDown();
							
			$('#newsletter_return').delay(1900).html("Please supply a valid email address.").slideUp();
		}
		return false;
	});	

	/* INPUT CLEAR */
	
	$(window).bind("load", function(){
			//clear form inputs (add & uses rel attributes for comparison)
			$('.inputClear').focus(function(){
				if(!$(this).attr('rel')) {
					$(this).attr('rel',$(this).val()).val('');
				} else {
					if($(this).val()==$(this).attr('rel')) $(this).val('');
				}
			}).blur(function(){
			   if($(this).val()=="") $(this).val($(this).attr('rel'));
			});
});
	
});
