/* Author: Carl Walsh

*/
/*var shadowpos = 70;
shadows(shadowpos);
function shadows(shadowpos){

	shadowpos = shadowpos + 100;
	$('#inner-header').animate({'backgroundPosition': shadowpos+'% bottom'},
	{duration: 10000, easing: 'linear', complete: function(){
		shadows(shadowpos);
	}});

}*/

if($('#popup').length > 0){
	$('#popup').modal({
  		keyboard: true,
  		show: true,
  		backdrop: true
	});
}

$('#main-nav a').hover(function(){
	
});

eviivo_height = $('.eviivo_searchbox').height();
$('#eviivo-toggle').click(function(){
	current_height =  $('.eviivo_searchbox').height();
	change_to_height = (current_height == eviivo_height) ? 0 : eviivo_height;
	$('.eviivo_searchbox').animate({'height': change_to_height});
	return false;
});

$('.offers_list li p a').click(function(){
	
	if($(this).hasClass('gotlink')){
		return true;
	} else {
		return false;	
	}
});

$('.offers_list .the-pdf-link').each(function(){
	$('.offers_list li p a').attr('href', $(this).attr('href')).addClass('gotlink');
});

$(window).bind('load', function(){

	
	$('.gallery-icon a').fancybox();

});

	$('#image-feature').mobilyslider({
    content: '.sliderContent', // class for slides container
    children: 'img', // selector for children elements
    transition: 'fade', // transition: horizontal, vertical, fade
    animationSpeed: 300, // slide transition speed (miliseconds)
    autoplay: true, 
    autoplaySpeed: 5000, // time between transitions (miliseconds)
    pauseOnHover: false, // stop animation while hovering
    bullets: true, // generate pagination (true/false, class: sliderBullets)
    arrows: true, // generate next and previous arrow (true/false, class: sliderArrows)
    arrowsHide: true, // show arrows only on hover
    prev: 'prev', // class name for previous button
    next: 'next', // class name for next button
    animationStart: function(){}, // call the function on start transition
    animationComplete: function(){} // call the function when transition completed
});



	timer = setTimeout('changeImage();', 5000);
	var image = 1;
	
	
	function changeImage(){
		image++;
		
		 $("#placer").ImageSwitch({  
			 Type: "FadeIn", // Type of effect to run the function  
			 NewImage: blogurl+"img/features/place"+image+".jpg", //The new image will be loaded in  
			 EffectOriginal: false,  
			 Speed: 750, //Speed of the effect  
			 StartLeft: 50, //The position the effect start compare to original position could be (-)  
			 StartTop: 0,  
			 StartOpacity: 0, //Which start opacity it would be  
			 EndLeft: -50, //The position the effect end compare to the original position could be (-)  
			 EndTop: 0,  
			 EndOpacity: 0, //Which start opacity it would be  
			 Direction: "LeftRight", //Which Way the image will be sroll  
			 Door1: "", //The image for the door 1  
			 Door2: "" //The image for the door 2  
		});  
		 timer = setTimeout('changeImage();', 5000);
		 
		 if(image == 3){
			image = 0;
		}
	}



    $(function(){
		
		if(thepub == 'the_clifton'){
			tw_us = 'Thecliftonhotel';
		}
		
		if(thepub == 'barley_mow'){
			tw_us = 'BarleyMowPub';
		}
		
		if(thepub == 'crown_and_anchor'){
			tw_us = '_CrownAndAnchor';
		}
		
		if(thepub == 'pakenham_arms'){
			tw_us = 'pakenhamarms';
		}
		
		if(thepub == 'the_mitre'){
			tw_us = 'mitrehotel';
		}
		
		if(thepub == 'tea_clipper'){
			tw_us = 'TheTeaClipper';
		}
		
		if(thepub == 'the_botanist'){
			tw_us = '_TheBotanistKew';
		}
		
		if(thepub == 'white_swan'){
			tw_us = '_TheWhiteSwan';
		}
		
        $(".tweet").tweet({
        avatar_size: 32,
        count: 3,
        username: tw_us,
        template: "{text}",
		loading_text: "Loading Tweets &#9786; ",
		callback_function: function(){
			
			var s={change:$('.tweet_list li'),duration:10000},i=1,l=s.change.length-1;
			console.log(s.change.length-1);
			s.change.fadeOut().eq(0).fadeIn();
			setTimeout(function(){
				s.change.fadeOut().eq(i).fadeIn();
				console.log(i);
				i=(i<l) ? ++i : 0;
				setTimeout(arguments.callee, s.duration);
			}, s.duration);
		}
        });
    
    	if($('.offers_list li').length > 1){
    		(function(){
			var s={change:$('.offers_list li'),duration:10000},i=1,l=s.change.length-1;
			console.log(s.change.length-1);
			s.change.fadeOut().eq(0).fadeIn();
			setTimeout(function(){
				s.change.fadeOut().eq(i).fadeIn();
				console.log(i);
				i=(i<l) ? ++i : 0;
				setTimeout(arguments.callee, s.duration);
			}, s.duration);
		})();
    	}
		
		
	});
	
	//INPUT CLEAR
	
		//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'));
		});
	
	// CHKEML
	
	(function($){$.fn.checkEmail=function(){var b;this.each(function(){var c=$(this).val();b=c.indexOf("@")==-1||c.lastIndexOf(".")==-1?false:true});return b}})(jQuery);

	
	//BAF
	
	$('#sign_up_return').hide();

	$('#baf-form').submit(function(){
		chkeml = $('#sign_up_email').checkEmail();
		fname = $('#sign_up_fname').val();
		sname = $('#sign_up_sname').val();
		emlval = $('#sign_up_email').val();
				
		if(chkeml)		
		{
			
			$.ajax({
				type: "GET",
				url:tehurl+"/inc/process.php",
				data: "emailadd=" + emlval + "&fname=" + fname + "&sname=" + sname + "&place=" + thepub,
				success: function(data){
					switch(data){
						case "failed":
							message="<small>Error adding to the database</small>";
							$('#sign_up_return').html(message).fadeIn();
							$('#sign_up, #sign_up_fname, #sign_up_sname')
							
						break;
						case "success":
							message="<p class=\"lineheight-small\"><small>Thank you. Your email has been added to our database.</small></p>";
						
							
							$('#sign_up_return').html(message).fadeIn();
							$('#sign_up').not('#join')
							.val("")
							
						break;
						case "email":
							message="Your email address is already registered";
							$('#sign_up_return').html(message).fadeIn();
							$('#sign_up_email, #sign_up_fname, #sign_up_sname')
							
							$('#sign_up_return').delay(1900).slideUp();
						break;
					}
				}
			});
		}
		else
		{
			$('#sign_up_return').html("<small>Please supply a valid email address.</small>").slideDown();
							
			$('#sign_up_return').delay(1900).html("<small>Please supply a valid email address.</small>").slideUp();
		}
		return false;
	
	});//END BAF
























	$('#xmas_sign_up_return').hide();

	$('#xmas-baf-form').submit(function(){
		
		//console.log("Yellow Cryons");

		chkeml = $('#xmas_sign_up_email').checkEmail();
		fname = $('#xmas_sign_up_fname').val();
		sname = $('#xmas_sign_up_sname').val();
		emlval = $('#xmas_sign_up_email').val();
				
		if(chkeml)		
		{
			//console.log("Yellow Cryons2");
			
			$.ajax({
				type: "GET",
				url:tehurl+"/inc/process.php",
				data: "emailadd=" + emlval + "&fname=" + fname + "&sname=" + sname + "&place=" + thepub,
				success: function(data){
					switch(data){
						case "failed":
							message="<small>Error adding to the database</small>";
							$('#xmas_sign_up_return').html(message).fadeIn();
							$('#xmas_sign_up, #xmas_sign_up_fname, #xmas_sign_up_sname')
							
						break;
						case "success":
							message="<p class=\"lineheight-small\"><small>Thank you. Your email has been added to our database.</small></p>";
						
							
							$('#xmas_sign_up_return').html(message).fadeIn();
							$('#xmas_sign_up').not('#join')
							.val("")
							
						break;
						case "email":
							message="Your email address is already registered";
							$('#xmas_sign_up_return').html(message).fadeIn();
							$('#xmas_sign_up_email, #xmas_sign_up_fname, #xmas_sign_up_sname')
							
							$('#xmas_sign_up_return').delay(1900).slideUp();
						break;
					}
				}
			});
		}
		else
		{
			$('#xmas_sign_up_return').html("<small>Please supply a valid email address.</small>").slideDown();
							
			$('#xmas_sign_up_return').delay(1900).html("<small>Please supply a valid email address.</small>").slideUp();
		}

		//console.log("Yellow Cryons3");
		return false;
	
	});//END BAF













