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(){
						   
	$('.pgewrapper').hide();
	$('.pgemask').css({opacity: 0.8});
		
	$('#book').click(function(){
		$('.pgewrapper').show();
		$('.pgecontainer').pgeConCen();	
	});
						   
	$(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 = 648;
	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=="#ZW1sYms="){
				$('.current').children('.pagecontent')
				.load("media/content/emlbook/index.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(){
		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: 9
			}).children('a.section_name').animate({
				width: 9
			}).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: 115
			}).children('a.section_name').animate({
				width: 115
			}).css({backgroundPosition: "0px -300px"});
			
			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().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);
				});
			}
}

function pageload_callback(button){
	var ajaxhook = button.parent().parent().parent().parent().children('.pagecontent').children('.ajax_content');
	
	
	
	
	/***/
	
	
	if ($('.intlink').length>0){
        
		$('.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;
        });
    }
	
	
	
	
		//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(){
			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{
					return true; 
				 }
			}
			else{$('.cFrmReturn').text("Please ensure you have filled in the mandatory fields marked with * correctly")}
			return false;
		});
	}
	
	/***/
	


	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
					dura = 500;
					moveMax = "-435px";
					movelmax = "-210px";
					movelmin = 20;
					moveMin = 20;
					
					var tvisable = true;
						$('a.showhide').click(function() {
							if(tvisable == true) {
								//show text	
								$(this).parent('.icontent').animate({
									
									top: moveMax,
									left: movelmax
									
								},{duration: dura, queue: false});
								$(this).html('show text');
								//$(this).parent().parent().parent().children(".imgcontrol").fadeOut();
								
								tvisable = false;
						
							} else {
								//hide text	
								$(this).parent('.icontent').animate({
																
									top: moveMin,
									left: movelmin
									
								},{duration: dura, queue: false});
								$(this).html('hide text');
								//$(this).parent().parent().parent().children(".imgcontrol").fadeIn();
								
								tvisable = true;
					
							}
							return false;
						});
					
					
				}//end if a.showhide
				
				if (ajaxhook.children('.images').length > 0) {
					ajaxhook.children('.images').cycle();
				}//end if #images
	}

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);

/***/