var c_min=0;	
var c_max=600;	//max width
var c_lft=0;	
var m_lft=360; //subject width
var news_size = "";
		
var selecteasing="easeInOutQuad";
var animspeed=800;

$(document).ready(function(){
	
	//SCROLLABLE
	$(".scrollable").scrollable();	


	/* TIPSY */
	
	$("a,img,h1,h2,h3,input,span").each(function(){if($(this).attr("title").length>0){$(this).tipsy({opacity:1,html:true,gravity:"s"})}});

	
	$('.pgewrapper').hide();
	$('.pgemask').css({opacity: 0.8});

	/*$('#becomeafriend').fancybox({
		overlayOpacity:0.8,
		overlayColor:'#000',
		padding:0,
		autoDimensions:false,
		height:181,
		width:305,
		scrolling: 'no',
		onComplete: function(){
			
			$('#baf').submit(function(){
				
				email=$('#baf_email').val();
				name=$('#baf_name').val();
				restaurant='pear-tree';
				
				$('#baf_email, #baf_name').val('');
												
				$.ajax({
					type: "get",
					url: 'plugs/baf/process.php',
					data: 'email=' + email + '&name=' + name + '&restaurant=' + restaurant,
					success: function(html){
						if(html=='success'){
							$('#baf_return').html('Thank you, your e-mail has been added.');
						} else {
							$('#baf_return').html('There was an issue with your email address.');
						}
					}
				});	
				
				return false;
			});*/
			
			
/*
	CHKEML
*/

(function(a){a.fn.checkEmail=function(){var b;this.each(function(){var c=a(this).val();b=c.indexOf("@")==-1||c.lastIndexOf(".")==-1?false:true});return b}})(jQuery);




	
	
	//NEWSLETTER SIGNUP
	
	$('#baf_return').hide();

	$('#baf').submit(function(){
		chkeml = $('#baf_eml').checkEmail();
		fname = $('#fname').val();
		sname = $('#sname').val();
		emlval = $('#baf_eml').val();
				
		if(chkeml)		
		{
			
			$.ajax({
				type: "GET",
				url:"/plugs/baf/process.php",
				data: "email=" + emlval + "&name=" + fname + " " + sname,
				success: function(data){
					switch(data){
						case "failed":
							message="Error adding to the database";
							$('#baf_return').html(message).fadeIn();
							$('#fname, #sname, #baf_eml')
							
						break;
						case "success":
							message="<p style=\"color: #ffffff; z-index: 10;\">Thank you.</p>";
						
							$('#baf_return').html(message).fadeIn();
							$('#fname, #sname, #baf_eml')
							.val("")
							
						break;
						case "email":
							message="Your email address is already registered";
							$('#baf_return').html(message).fadeIn();
							$('#fname, #sname, #baf_eml')
							.removeClass('loading');
							$('#baf_return').delay(1900).slideUp();
						break;
					}
				}
			});
		}
		else
		{
			$('#baf_return').html("Please supply a valid email address.").slideDown();
							
			$('#baf_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'));
			});
});
			
			
			//ROTARY
			
			$('#offers_items').rotary({
			auto: {interval:7000},
			changer: 'div',
			onstage: {left:0},
			offstage: {left:-280},
			ext: {
				queue:false,
				duration:500,
				easing:'swing'
			},
			control: {
				ind: {
					element: $('#offers_cont li a'),
					binding: 'click',
					onclass: 'cur'
				}
			}
	});
			
			
			/* OFFERS */
			
			
			///////////////////////
			
			
						   
	

	$('#book-temp').fancybox();
	$('#book-table').fancybox();
	$('#book-room').fancybox();					   
	
	function lightb(ind){
		$('.pgecontainer>div').hide().eq(ind).show();							
									
		$('.pgewrapper').show();
		$('.pgecontainer').pgeConCen();	
	}
						   
	$('.pgewrapper').hide();
	$('.pgemask').css({opacity: 0.8});

	$('#becomeafriend').click(function(){lightb(0);});
	$('#book-table').click(function(){lightb(1);});
	$('#book-room').click(function(){lightb(2);});
	
				   
	$(window).bind("resize",function(){
		$('.pgecontainer').pgeConCen();					   
	});
	
	$('.pgemask').click(function(){
		$('.pgewrapper').hide();				
	});	
					  
$('#join').submit(function(){
	joinemail = $('#joinemail').val(); 
	
	if(CheckEmail(joinemail))
	{
		$.post("media/php/baf/baf2.php",{email: joinemail}, function(data){
			$('#baf_return').text(data).css({color: "#fff"});
			$('#joinemail').val("");
		});	
	}
	else
	{
		$('#baf_return').html("Please enter a valid email address.")
		.css({color: "#fff"});	
	}
	return false;
	});


	
	
	//variables
	var contain = $('#sections');
	var section = contain.children();
	var nav = section.children('.nav');
	var nav_ul = nav.children('ul');
	var section_name = $('a.section_name');
	var section_name = $('a.section_name');
	var pagecontent = $('.pagecontent');
	
	var s_maxwidth = 929;
	var s_minwidth = 30;



	//startup	
	nav_ul.fadeOut();
	//pagecontent.hide();
	expand(section.eq(0));
	
	
	//hash
    checkhash = hashTohref();
    if (!checkhash) {
        expand(section.eq(0));
    } else {
        ref = $('div.nav ul li a').filter(function(){
            return $(this).attr('href') == checkhash;
        });
        if(ref.length==0){	
            expand(section.eq(0));
            
            if(window.location.hash=="#paypal-success"){
            	$('.current').children('.pagecontent')
            	.load("media/content/lifestyle/paypal-success.htm" + " .ajax_content", function(){});
            }
            
            if(window.location.hash=="#paypal-cancel"){
            	$('.current').children('.pagecontent')
            	.load("media/content/lifestyle/paypal-cancel.htm" + " .ajax_content", function(){});
            }
			
			if(window.location.hash=="#ZW1sYms="){
				$('.current').children('.pagecontent')
				.load("media/content/emlbook/index.htm" + " .ajax_content", function(){});
			}

			if(window.location.hash=="#competition"){
				$('.current').children('.pagecontent')
				.load("media/content/lifestyle/competition-wmb.htm" + " .ajax_content", function(){});
			}
			
			if(window.location.hash=="#christmas"){
				$('.current').children('.pagecontent')
				.load("media/content/restaurants/christmas.htm" + " .ajax_content", function(){});
			}
			
			if(window.location.hash=="#winterhideaways"){
				$('.current').children('.pagecontent')
				.load("media/content/restaurants/winterhideaways.htm" + " .ajax_content", function(){});
			}
			
			if(window.location.hash=="#openingtimes"){
				$('.current').children('.pagecontent')
				.load("media/content/restaurants/openingtimes.htm" + " .ajax_content", function(){
					if($('div.faq').length>0){
						$('div.faq').accordion();
					}
				});
			}
			
			if(window.location.hash=="#offers"){
				$('.current').children('.pagecontent')
				.load("media/content/restaurants/offers.htm" + " .ajax_content", function(){
					if($('div.faq').length>0){
						$('div.faq').accordion();
					}
				});
			}
			
			if(window.location.hash=="#newyears"){
				$('.current').children('.pagecontent')
				.load("media/content/restaurants/newyears.htm" + " .ajax_content", function(){});
			}
			
        } else {
            expand(ref.parent().parent().parent().parent());
			ref.parent().parent().parent().parent().children('.pagecontent')
				.load(checkhash + " .ajax_content", function(){
					//callback
					pageload_callback(ref);
				});
        }
		
    }
	
	
	
	//events
	section_name.click(function(){
		

		   ti=section_name.index(this);
		   $('.welcome div').animate({opacity: 0}, 700).eq(ti).animate({opacity: 100}, 700);

		
		expand($(this).parent().parent());
		
		return false;
	});
	
	$('input#joinemail').example(function() {
	   return $(this).attr('title');
 	});

	
	
	//expand section elements
	function expand(element){
		if(!element.hasClass('current')){
			
			//out
			$('.current')
			.animate({
				width: s_minwidth
			},{queue: false});
			$('.current').children().children('ul').fadeOut();
			
			
			$('.current').children('.nav').animate({
				width: 12
			}).children('a.section_name').animate({
				width: 15
			}).css({backgroundPosition: "top right"});
			
			$('.current').children('.pagecontent').hide();
			$('.current').removeClass('current');
			

			
			//in
			element.children('.pagecontent').show();
			
			element
			.animate({
				width: s_maxwidth	 
			},{queue: false})
			.addClass('current');
			
			element.children('.nav').animate({
				width: 120
			}).children('a.section_name').animate({
				width: 120
			}).css({backgroundPosition: "-40px 0"});
			
			if(element.children().children('ul').children('li').length<2){ 
				element.children().children('ul').hide();
			} else {
				element.children().children('ul').fadeIn();
			}
			

			pageload(element.children('.nav').children('.section_name'));
			
		}
	}
	
nav.children().not('#rest_small').children().children().click(function(){	
	pageload($(this));
	return false;	
});


});

function loadcontent(element) {
		element.fadeOut();
		element.bind("load", function(){
			element.fadeIn();			  
		});
	}

function pageload(button){
	
	$('.pagecontent').html('');
		
			if (button.hasClass("section_name")) {
				//setup variables
				var loadurl = button.parent().children('ul').children().children('a').eq(0).attr('href');
					
				//load the content
				//loadcontent(button.parent().parent().children('.pagecontent'));
				button.parent().parent().children('.pagecontent')
				.load(loadurl + " .ajax_content", function(){
				
				//callback
					pageload_callback(button.parent().children('ul').children().children('a').eq(0));
				});
				
			} else {
			
				//setup variables
				var loadurl = button.attr('href');
					
				//load the content
				//loadcontent(button.parent().parent().parent().parent().children('.pagecontent'));
				button.parent().parent().parent().parent().children('.pagecontent')
				.load(loadurl + " .ajax_content", function(){
				
				//callback
					pageload_callback(button);
				});
			}
}


/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);
/* ==========================================================
 * MobilySlider
 * date: 20.1.2010
 * author: Marcin Dziewulski
 * last update: 02.02.2011
 * web: http://www.mobily.pl or http://playground.mobily.pl
 * email: hello@mobily.pl
 * Free to use under the MIT license.
 * ========================================================== */
(function($){$.fn.mobilyslider=function(options){var defaults={content:".sliderContent",children:"div",transition:"horizontal",animationSpeed:300,autoplay:false,autoplaySpeed:3000,pauseOnHover:false,bullets:true,arrows:true,arrowsHide:true,prev:"prev",next:"next",animationStart:function(){},animationComplete:function(){}};var sets=$.extend({},defaults,options);return this.each(function(){var $t=$(this),item=$t.children(sets.content).children(sets.children),l=item.length-1,w=item.width(),h=item.height(),step=0,play,bullets,arrows,z,active,bullet;var slider={init:function(){slider.data();if(sets.bullets){slider.bullets.create()}if(sets.arrows){slider.arrows.create()}if(sets.autoplay){slider.autoplay()}slider.triggers()},data:function(){item.each(function(i){$(this).css("z-index",-(i-l))});if(sets.transition=="fade"){item.hide().eq(0).show()}},zindex:{prev:function(){step==l?item.eq(0).css("z-index",l+3):item.css("z-index",l+1);item.eq(step).css("z-index",l+4).next(item).css("z-index",l+2)},next:function(){item.css("z-index",l+1).eq(step).css("z-index",l+3).prev(item).css("z-index",l+2)},bullets:function(){item.css("z-index",l+1).eq(active).css("z-index",l+2);item.eq(step).css("z-index",l+3)},trigger:function(){if(z==1){slider.zindex.next()}else{if(z==-1){slider.zindex.prev()}else{if(z==0){slider.zindex.bullets()}}}}},slide:{left:function(sign){sets.animationStart.call(this);item.eq(step).animate({left:sign+"="+w},sets.animationSpeed,function(){slider.zindex.trigger()}).animate({left:0},sets.animationSpeed+200,function(){sets.animationComplete.call(this)})},top:function(sign){sets.animationStart.call(this);item.eq(step).animate({top:sign+"="+h},sets.animationSpeed,function(){slider.zindex.trigger()}).animate({top:0},sets.animationSpeed+200,function(){sets.animationComplete.call(this)})},fade:function(){sets.animationStart.call(this);item.fadeOut(sets.animationSpeed).eq(step).fadeIn(sets.animationSpeed,function(){sets.animationComplete.call(this)})}},animation:{previous:function(){step==0?step=l:step--;z=-1;switch(sets.transition){case"horizontal":slider.slide.left("-");break;case"vertical":slider.slide.top("+");break;case"fade":slider.slide.fade();break}},next:function(){step==l?step=0:step++;z=1;switch(sets.transition){case"horizontal":slider.slide.left("+");break;case"vertical":slider.slide.top("-");break;case"fade":slider.slide.fade();break}}},autoplay:function(){play=setInterval(function(){slider.animation.next();if(sets.bullets){setTimeout(function(){slider.bullets.update()},sets.animationSpeed+300)}},sets.autoplaySpeed)},pause:function(){clearInterval(play)},bullets:{create:function(){$t.append($("<div />").addClass("sliderBullets"));bullets=$t.find(".sliderBullets");for(i=0;i<=l;i++){bullets.append($("<a />").attr({href:"#",rel:i}).text(i))}},trigger:function(){bullet=bullets.find("a");bullet.eq(0).addClass("active");bullet.click(function(){var b=$(this),rel=b.attr("rel");active=bullet.filter(".active").attr("rel");step=rel;sign=rel>active?"+":"-";z=0;if(!b.hasClass("active")){switch(sets.transition){case"horizontal":slider.slide.left(sign);break;case"vertical":slider.slide.top(sign);break;case"fade":slider.slide.fade();break}}bullet.removeClass("active");b.addClass("active");return false})},update:function(){bullet.removeClass("active").eq(step).addClass("active")}},arrows:{create:function(){$t.append($("<div />").addClass("sliderArrows"));arrows=$t.find(".sliderArrows");arrows.append($("<a />").attr("href","#").addClass(sets.prev).text("Previous"));arrows.append($("<a />").attr("href","#").addClass(sets.next).text("Next"))},trigger:function(){arrows.find("."+sets.prev).click(function(){slider.animation.previous();if(sets.bullets){slider.bullets.update()}return false});arrows.find("."+sets.next).click(function(){slider.animation.next();if(sets.bullets){slider.bullets.update()}return false});if(sets.arrowsHide){arrows.hide();$t.hover(function(){arrows.show()},function(){arrows.hide()})}}},triggers:function(){if(sets.arrows){slider.arrows.trigger()}if(sets.bullets){slider.bullets.trigger()}if(sets.pauseOnHover){$t.hover(function(){slider.pause()},function(){slider.autoplay()})}}};slider.init()})}}(jQuery));



/***********************************************************************************************************************************************************************************************************************************/
/***********************************************************************************************************************************************************************************************************************************/
/***********************************************************************************************************************************************************************************************************************************/

function pageload_callback(button){
	
	/* ACCORDION */
	if($('div.faq').length>0){
		$('div.faq').accordion();
	}
	
	
	var ajaxhook = button.parent().parent().parent().parent().children('.pagecontent').children('.ajax_content');
	
	
	/** afganistan gallery */
	
	if($('.sliderContainer').length) {
	
		$('.slider').mobilyslider({
			content: '.sliderContent',
			children: 'img',
			transition: 'fade',
			animationSpeed: 500,
			autoplay: true,
			autoplaySpeed: 5000,
			pauseOnHover: false,
			bullets: false,
			arrows: true,
			arrowsHide: true,
			prev: 'prev',
			next: 'next'
		}).css('display','none').eq(0).css('display','block')
		
		$('.slideSwitch a').live('click',function(){
			ti=$('.slideSwitch a').index(this);
			$('.slider').hide().eq(ti).show();
			return false;
		});
		
	}
	
	/** eo afganistan gallery */
	
	
	
	//RESTAURANT GRID
	
	/*$('.command').bind('click', function(){
	$(this).parent('.res').children('a').trigger('click');
});*/
	
	
	if($('#res-grid').length){
		
		// $('.res-item').each(function(){
		// 			
		// 			magiclink = $(this).children('a').attr('href');
		// 			app = '<a href="'+magiclink+'" class="command">';
		// 				if($(this).hasClass('commingsoon')){
		// 					app = app + 'Website Comming Soon';	
		// 				} else {
		// 					app = app + 'Click to launch Website';
		// 				}
		// 			app = app + '</a>';
		// 			
		// 			$(this).append(app)
		// 		});
		
		$('.command').hide();
		
		$('.res-item').not('.normal').hoverIntent(function(){
			$(this).children('.command').show();	
			imag = $(this).children('a').children('img').attr('rel');
			$(this).children('a').children('img').attr("src","media/layout/res/"+imag+"-large.jpg");
			$(this).children('a').css({'z-index': 10}).children('img').animate({
				'width': 300,
				'height': 300,
				'top': -75,
				'left': -75
			},250,function(){
				//$(this).parent().parent().children('.command').show();	
			});
		}, function(){
			$(this).children('a').css('z-index', 0).children('img').animate({
				'width': 158,
				'height': 158,
				'top': 0,
				'left': 0
			},100,function(){
				imag = $(this).attr('rel');
				$(this).attr("src","media/layout/res/"+imag+"-small.jpg");
			});
			$(this).children('.command').hide();
		});
	}
	
	//private dining
	
	if($('.pd_link').length){
		
		$('.pd_link').bind('click',function(){
			var loadurl = "media/content/forms/privatedining.php?restaurant_id=" + $(this).attr('rel');
			
			if($(this).attr('rel')=="normal") {
				$(this).parent().parent().parent().parent().children('.pagecontent')
				.load(loadurl + " .ajax_content", function(){
					
					//callback
					pageload_callback(button);
				});
			} else {
				$(this).parent().parent().parent().parent().parent().parent().parent().parent().children('.pagecontent')
				.load(loadurl + " .ajax_content", function(){
					
					//callback
					pageload_callback(button);
				});
			}
            return false;							
		});
	}
	
	if($('.lightBox').length>0){
        $('.lightBox').fancybox();
    }
	
	
	$('#afghan span').stop().animate({'opacity':0});
	$('#afghan > a').hover(function(){
		$('#afghan span').stop().animate({'opacity':1});
	},function(){
			$('#afghan span').stop().animate({'opacity':0});
	});
	
	if($('#wmbicompetitionform').length){
		

		$('#wmbicompetitionform').submit(function(){

			var answer = $('#wmbicompetitionform input[type=radio]:checked').val();
			var name = $('#name').val();
			var email = $('#email').val();

			if(answer=='yes') answer=1; else answer=0;

			$.ajax({
				type: 'POST',
				url: 'media/php/main_competition/process.php',
				data:'answer=' + answer + '&name=' + name + '&email=' + email,
				success: function(html){
					$('.cFrmReturn').text(html);
				}
			});
			return false;
		});
	}
	
	$('.scrollabalej').scrollbar();
	
	/*if($('#show-gallery').length){
		$('#show-gallery').fancybox();
	}*/
	
	
	$("#show-gallery").click(function() {
                $.fancybox([
                        'media/pictures/booksign-1.jpg',
                        'media/pictures/booksign-2.jpg',
						'media/pictures/booksign-3.jpg',
						'media/pictures/booksign-4.jpg',
						'media/pictures/booksign-5.jpg',
						'media/pictures/booksign-6.jpg',
						'media/pictures/booksign-7.jpg',
						'media/pictures/booksign-8.jpg',
						'media/pictures/booksign-9.jpg',
						'media/pictures/booksign-10.jpg',
						'media/pictures/booksign-11.jpg',
						'media/pictures/booksign-12.jpg',
						'media/pictures/booksign-13.jpg',
						'media/pictures/booksign-14.jpg',
						'media/pictures/booksign-15.jpg',
						'media/pictures/booksign-16.jpg',
						'media/pictures/booksign-17.jpg',
						'media/pictures/booksign-18.jpg',
						'media/pictures/booksign-19.jpg',
						'media/pictures/booksign-20.jpg',
						'media/pictures/booksign-21.jpg',
						'media/pictures/booksign-22.jpg',
						'media/pictures/booksign-23.jpg',
						'media/pictures/booksign-24.jpg',
						'media/pictures/booksign-25.jpg',
						'media/pictures/booksign-26.jpg',
						'media/pictures/booksign-27.jpg',
						'media/pictures/booksign-28.jpg',
						'media/pictures/booksign-29.jpg',
						'media/pictures/booksign-30.jpg',
						'media/pictures/booksign-31.jpg',
						'media/pictures/booksign-32.jpg',
						'media/pictures/booksign-33.jpg',
						'media/pictures/booksign-34.jpg',
						'media/pictures/booksign-35.jpg',
						'media/pictures/booksign-36.jpg',
						'media/pictures/booksign-37.jpg',
						'media/pictures/booksign-38.jpg',
						'media/pictures/booksign-39.jpg',
						'media/pictures/booksign-40.jpg',
						'media/pictures/booksign-41.jpg',
						'media/pictures/booksign-42.jpg',
						'media/pictures/booksign-43.jpg',
						'media/pictures/booksign-44.jpg',
						'media/pictures/booksign-45.jpg',
						
                ], {
                        'transitionIn'          : 'none',
                        'transitionOut'         : 'none',
                        'type'              	: 'image',
                        'changeFade'        	: 0,
						'width'					: 650,
						'height'				: 500
                });
        }); 
	
	
	
	
	if($('#offer1').length){
		$('#offer1').submit(function(){
				
				email=$('#offer1_email').val();
				
				restaurant='chequers-inn';
				
				$('#offer1_email').val('');
												
				$.ajax({
					type: "get",
					url: 'plugs/baf/offers_process.php',
					data: 'email=' + email + '&restaurant=' + restaurant,
					success: function(html){
						if(html=='success'){
							$('#offer_return1').html('Thank you, your e-mail voucher has been sent.');
						} else {
							$('#offer_return1').html('There was an issue with your email address');
						}
					}
				});	
				
				return false;
			});
	}
	
	
	
	if ($('.intlink').length>0){
        
		$('.intlink').click(function(){
            var loadurl = $(this).attr('href');
			var thos = this;
            //load the content
            //loadcontent(button.parent().parent().parent().parent().children('.pagecontent'));
            $('.current').children('.pagecontent')
            .load(loadurl + " .ajax_content", function(){
				
                //callback
                pageload_callback(button);
            });
			
            return false;
        });
    }
	
	
	/* video */
	
	
	/*IE DETECTION*/
	var ie=function(){for(var a=3,b=document.createElement("div"),c=b.getElementsByTagName("i");b.innerHTML="<!--[if gt IE "+ ++a+"]><i></i><![endif]--\>",c[0];);return a>4?a:void 0}();
	
	
	vsettings = {
		elem: $('#show-video'),
		container: $('#video1'),
		video_dir: 'media/video/',
		flash_dir: 'media/flash/',
		video_name: 'MPW Chequers',
		site_root: 'http://www.wheelerschequers.com/',
		width: 768,
		height: 432
	};
	
	
	if(vsettings.elem.length){
		
		if(ie<8){
			//Internet Explorer 6/7 Href FAILS!
			vsettings.elem.attr('href', "#" + vsettings.elem.attr('href').split('#')[1]);
		}
		
			vsettings.elem.fancybox({
            overlayOpacity:0.8,
            overlayColor:'#000',
            padding:0,
            autoDimensions:false,
            height:vsettings.height,
            width:vsettings.width,
			scrolling: 'no',
			onComplete: function(){			
				vsettings.container.html("<video controls width=" + vsettings.width + " height="+ vsettings.height +" preload autoplay>\
					<source src=\"" + vsettings.video_dir + vsettings.video_name + ".mp4\" type=\"video/mp4\">\
					<source src=\"" + vsettings.video_dir + vsettings.video_name + ".ogg.php\" type=\"video/ogg\">\
				</video>");
				
				if(ie<9) {
					vsettings.container.empty().flashembed({
						src: vsettings.flash_dir + 'flv-player.swf',
						width: 768,
						height: 432,
						wmode: 'transparent'
					},{
						flv: vsettings.site_root + vsettings.video_dir + vsettings.video_name + '.mp4',
						configxml: vsettings.flash_dir + 'config.xml'
					});
					
					
				}
				
			}
		});
	}
	
	
	/* end Video */
	
	/* BAF FANCYBOX */
	/*if($('#becomeafriend').length){
		$('#becomeafriend').fancyZoom();
	}*/

	$('.pgecontainer #baf').live('submit',function(){
		
		$('#baf input[type="submit"]').css({display:'none'});
		
		expVals="";
		$('#baf input[type="text"]').each(function(){expVals=expVals+$(this).val()+"{spl}";});		
		$.ajax({ 
		type: "POST", 
		url: "media/php/baf/voucher.php", 
		data: "func=voucherSubmit&vals="+expVals, 
		success: function(data){
			$('#baf #feedback').html(data);
			$('#baf input[type="submit"]').css({display:'block'});
		}
		});
		return false;
	});
	
	/***/
	
	

	
	
	
	
		//contact forms
		

	if($('.cFrm').length>0){
	
		
		$('.cFrm p').formValidate();
		
		//reset form
		$('.cFrm p').children('input[type="reset"]').click(function(){$(this).parent().frmReset();});
		
		$('.cFrm').submit(function(){
		
			r=false;
			thsObj=$(this).children('p');
			pCount=thsObj.size();
			valSize=0;
			cVals="";
			
			//validate form
			if($('.privatediningform').length>0){
				pCount=0;
				$(this).each(function(){
					thsObj=$(this).children('p');								 
					pCount=pCount+thsObj.size();
					thsObj.each(function(){if($(this).frmSubmit()){valSize++;cVals=cVals+$(this).returnFrmVals();}});
					
				});
			}
			else{thsObj.each(function(){if($(this).frmSubmit()){valSize++;cVals=cVals+$(this).returnFrmVals();}});}
			
			
			//is form valid
			if(valSize==pCount){
				$('.cFrmReturn').text("Processing your request...");
				
				//form names
				if($('.privatediningform').length>0){fncName="1",postAjax=true;}
				else if($('.recruitmentform').length>0){fncName="2",postAjax=false;}
				else if($('.contactMarco').length>0){fncName="3",postAjax=false;}
				else if($('.competitionform').length>0){fncName="4",postAjax=true;}
				else if($('.competitionform2').length>0){fncName="5",postAjax=true;}
				

				if($('.pdResSel').length){
					restaurant_id=$('.pdResSel').val();
					restaurant=restaurants_arr[$('.pdResSel').val()];
					dd=1;
				} else {
					restaurant=$('#restaurant_name').val();
					restaurant_id=$('#restaurant_id').val();
					dd=0;
				}
				
				//submit form vals
				if(postAjax){
					 $.ajax({ 
					   type: "POST", 
					   url: "media/php/process.php", 
					   data: "func=cFrmReq&frmIndx="+fncName+"&frmVals="+cVals+"&restaurant_id=" + restaurant_id + "&restaurant_name=" + restaurant + "&dd=" + dd, 
					   success: function(data){
						   if(data=="success"){$('.cFrmReturn').text("Thank you for your enquiry.");}
						   else{$('.cFrmReturn').text("There was an issue with your enquiry");}
						   $('.cFrm textarea, .cFrm input[type="text"]').val("");
					   } 
					 });
				 } else {
					r=true; 		
				 }	
			}
			else{
			$('.cFrmReturn').text("Please ensure you have filled in the mandatory fields marked with * correctly")
				r=false;
			}
			
			return r;
			
		});
	}
	
	/***/
	



	if($('.mar').length>0) {
		$('.mar').click(function(){
			$('.pgewrapper').show();
			$('.pgecontainer').pgeConCen();	
		});
	}
	
	if($('a.hkback').length>0){
		$('a.hkback').click(function(){
				var loadurl = $(this).attr('href');
					
				//load the content
				//loadcontent(button.parent().parent().parent().parent().children('.pagecontent'));
				$(this).parent().parent().parent().parent().children('.pagecontent')
				.load(loadurl + " .ajax_content", function(){
				
				//callback
					pageload_callback(button);
				});
				return false;
		});
	}

if($('a.summary').length>0){
		$('a.summary').click(function(){
				var loadurl = $(this).attr('href');
					
				//load the content
				//loadcontent(button.parent().parent().parent().parent().children('.pagecontent'));
				$(this).parent().parent().parent().parent().parent().parent().parent().children('.pagecontent')
				.load(loadurl + " .ajax_content", function(){
				
				//callback
					pageload_callback(button);
				});
				return false;
		});
	}
	if($('#video').length > 0){	
		var flashpath = "media/video/" + $('#video').attr('rel');
		flashembed("video", {src: flashpath, wmode: 'transparent'});
	}
	
	if ($('#hk_switch').length>0){
				$('#hk_switch').click(function(){
				var loadurl = $('#hk_switch').attr('href');
					
				//load the content
				//loadcontent(button.parent().parent().parent().parent().children('.pagecontent'));
				$('#hk_switch').parent().parent().parent().children('.pagecontent')
				.load(loadurl + " .ajax_content", function(){
				
				//callback
					pageload_callback(button);
				});
				return false;
		});
	}
	
	if($('#hk_news').length > 0){
			
		news_size = $('#innercon').children('div').size();
		m_lft = $('#innercon div').width();
		c_max = m_lft * news_size;
		//alert(c_max);
		
		//animate arrows
		$('#arrowright').click(function(){
			$('#innercon').IcRight(selecteasing, animspeed);		
			return false;	
		});
		
		$('#arrowleft').click(function(){
			$('#innercon').IcLeft(selecteasing, animspeed);		
			return false;
		});
		

	}
	
	if($('#hk_cs').length > 0){
			
		cs_size = $('#innercon').children('div').size();
		m_lft = $('#innercon div').width();
		c_max = m_lft * cs_size - $('#hk_cs').width() + 100;
		
		//animate arrows
		$('#arrowright').click(function(){
			$('#innercon').IcRight(selecteasing, animspeed);		
			return false;	
		});
		
		$('#arrowleft').click(function(){
			$('#innercon').IcLeft(selecteasing, animspeed);		
			return false;
		});
		

	}
	
	/* REVIEWS PAGE FUNCTIONS */
	if($('.revLst').length>0){
		
		$('.revC').css({top:500,display:'block'}).eq(0).css({top:0});
		$('.revMask').animate({opacity:.8},{duration:0,queue:false});
		revSel=0;
		
		$('.revLst').css({zIndex:60}).children('li').children('a').click(function(){
			thsId=$('.revLst li a').index(this);
			secCount=$('.revC').size()-1;
			if(revSel!=thsId){
				aniIn=thsId
				$('.revC').each(function(){
					if($(this).css('top')=="0px"){
						thsIndx=$('.revC').index(this);
						aniO=thsIndx;
					}
				});
				revSel=thsId;
				$('.revC').eq(aniIn).css({zIndex:5}).animate({top:0},{duration:500,queue:false});
				$('.revC').eq(aniO).css({zIndex:0}).animate({top:-500},500,function(){$(this).css({top:500})});

			}
		});
		
	}
	
	if(ajaxhook.children('.icontent').children('a.showhide').length > 0){
					//img controls
					
					ics = {
						offstage: {
							top: 0,
							left: 0,
							height: 80,
							width: 807
						},
						onstage: {
							top: 0,
							left: 0,
							height: 450,
							width: 807
						},
						ext: {
							queue: false,
							duration: 500,
							easing: 'swing'
						}
					};
					
					cs = {
						offstage: {
							height: 36
						},
						onstage: {
							height: 394
						}
					}
					

						$('a.showhide').toggle(function() {


								$(this).parent('.icontent').animate({
									top: ics.onstage.top,
									left: ics.onstage.left,
									height: ics.onstage.height,
									width: ics.onstage.width
								},{queue: ics.ext.queue,duration: ics.ext.duration,easing: ics.ext.easing})
								.end()
								.siblings('.icontent_position')
								.animate({height: cs.onstage.height });
								
								$(this).html('hide text');
								
								if($('ul#book_select ').length > 0){
									$('ul#book_select ').show();
									$('#booksh2').css('opacity', '1');
								}
	
							}, function(){
							
								$(this).parent('.icontent').animate({								
									top: ics.offstage.top,
									left: ics.offstage.left,
									height: ics.offstage.height,
									width: ics.offstage.width								
								},{queue: ics.ext.queue,duration: ics.ext.duration,easing: ics.ext.easing})
								.end()
								.siblings('.icontent_position')
								.animate({height: cs.offstage.height });
								
								$(this).html('show text');
								
								if($('ul#book_select ').length > 0){
									$('ul#book_select ').hide();
									$('#booksh2').css('opacity', '1');
								}

							return false;
						});
					
					
				}//end if a.showhide
				
				if (ajaxhook.children('.images').length > 0) {
					ajaxhook.children('.images').cycle();
				}//end if #images
				
				
				    //Partners Slide
    if($('.pSliderC').length>0){
        
        glbWi=0;
        $('.partnersLi li').each(function(){glbWi=glbWi+$(this).width();});
        $('.partnersLi').css({width:glbWi});
		
        $().formatPartnersLst();
		
        $('.parLftAr').click(function(){
            lstCount=$('.partnersLi li').size()-1;

            lstClassNme=$('.partnersLi li').eq(lstCount).attr('class');
            httpAddr=$('.partnersLi li').eq(lstCount).children('a').attr('href');

            $('.partnersLi li').eq(lstCount).remove();
            $('.partnersLi').prepend('<li class="'+lstClassNme+'"><a href="'+httpAddr+'" class="intlink">test</a></li>');
			IntLnk();
			$().formatPartnersLst();
			
            return false;							
        });
		
        $('.parRteAr').click(function(){
            fstClassNme=$('.partnersLi li').eq(0).attr('class');
            httpAddr=$('.partnersLi li').eq(0).children('a').attr('href');

            $('.partnersLi li').eq(0).remove();
            $('.partnersLi').append('<li class="'+fstClassNme+'"><a href="'+httpAddr+'" class="intlink">test</a></li>')
			.css({left:0});
			IntLnk();
            $().formatPartnersLst();

            return false;							
        });
    }
			//$('a.showhide').trigger('click');	
	
	}
	
/***********************************************************************************************************************************************************************************************************************************/
/***********************************************************************************************************************************************************************************************************************************/
/***********************************************************************************************************************************************************************************************************************************/

function CheckEmail(inputemail) {
	AtPos = inputemail.indexOf("@");
	StopPos = inputemail.lastIndexOf(".");

	if (AtPos == -1 || StopPos == -1)
	{
		return false;
	}
	else
	{
		return true;	
	}

}

$.fn.pgeConCen = function(){
		Pheight=$(window).height()/2;
		Thisheight=$(this).height()/2;
		Cheight=Pheight-Thisheight;
		$(this).animate({
			"top":Cheight+"px"			
		},{ duration: 200, queue: false });
};
function hashTohref(){
    hash = window.location.hash;
		
    if (hash) {
        hash=hash.substr(1);
        hash=hash.split(",");
		
        if (!hash[1]){
            hrefend=hash[0]+".htm";
        } else {
            hrefend=hash[0]+"/"+hash[1]+".htm";
        }
        var href="media/content/" + hrefend;
        return href;
    } else {
        return false;
    }
}

/***/

//jquery extended
(function($){
    $.fn.extend({
        formatPartnersLst:function(){
            centObj=Math.round($('.partnersLi li').size()/2-1);
            pSlideCHalf=$('.pSliderC').width()/2;
            
            $('.partnersLi li').animate({opacity:0},0,function(){
                $(this).css({display:'block'});
                $(this).animate({opacity:.5},{duration:0,queue:false});
                $('.partnersLi li').eq(centObj).animate({opacity:1},{duration:500,queue:false});
            });

            iC=0;
            icWid=0;
            while(iC<=centObj-1){icWid=icWid+$('.partnersLi li').eq(iC).width();iC++;}
            $('.partnersLi').css({left:((-icWid+pSlideCHalf)-($('.partnersLi li').eq(centObj).width()/2))});
            //$('.partnersLi').animate({left:((-icWid+pSlideCHalf)-($('.partnersLi li').eq(centObj).width()/2))},{duration:300,queue:false});
        },
		returnFrmVals:function(){
			thsElm=$(this);
			expVal="";
			thsElm.children('input[type="text"]').each(function(){expVal=expVal+$(this).val()+"{spl}";});
			thsElm.children('textarea').each(function(){expVal=expVal+$(this).val()+"{spl}";});
			thsElm.children('select').each(function(){expVal=expVal+$(this).val()+"{spl}";});
			
			thsElm.children('input[type="checkbox"]').each(function(){
				thsChVl=$(this).val();
				if($(this).is(":checked")){exChVl=1;}else{exChVl=0;}
				expVal=expVal+exChVl+"{spl}";
			});
			
			thsElm.children('input[type="radio"]:checked').each(function(){
				thsRaVl=$(this).val();
				expVal=expVal+thsRaVl+"{spl}";
			});
			
			
			return expVal;
		}
    });
})(jQuery);

//javascript functions

function IntLnk(){
			$('.intlink').click(function(){
				var loadurl = $(this).attr('href');
						
				//load the content
				//loadcontent(button.parent().parent().parent().parent().children('.pagecontent'));
				$('.current').children('.pagecontent')
				.load(loadurl + " .ajax_content", function(){
					
					//callback
					pageload_callback(button);
				});
				return false;
			});
}

/***/
