var currTxt='';

$(document).ready(function() {
   // do stuff when DOM is ready
   	$('#lyrmenu').fadeTo(1,0.9);
   	$('#lyrmenus').fadeTo(1,0.9);
   	$('#lyrthebar').fadeTo(1,0.9);
   	$('#lyrdr').fadeTo(1,0.9);
   	$('#lyrcontact').fadeTo(1,0.9);
   	$('#lyrph').fadeTo(1,0.9);
   	$('#lyrres').fadeTo(1,0.9);
   	$('#lyres').fadeTo(1,0.9);
   	$('#lyrnp').fadeTo(1,0.9);
   	$('.text-bkg').fadeTo(1,0.9);
   	$('.shortcut-box').fadeTo(1,0.9);
	$('#lyrfooter').animate({height:'-=29',top:'+=29'},20);
	$('#tblfooter').fadeOut(2);
	
	showLink();
});

function showLink(){
		//link
	$.ajax({ 
	  url: "scripts/link.php",
	  context: document.body,
	  success: function(data){
		var win,arr=data.split('|');
		if (arr[2]==1){win='_blank';}else{win='_self';}
		$("#tdLink").html('<p class="header_lg"><a href="'+arr[1]+'" target="'+win+'" class="header_link_red_lg">'+arr[0]+'</a></p>');
	  }
	});
}
function introTemp(page){
	counter(0);
	preload();
	var pg=getQuerystring("pg","");
	if(pg!=""){
		chgView(pg,null,false);
	}
	setTimeout("$('#lyrIntro').fadeOut();$('#lyrMain').fadeIn();showLeftBar('menu');slideShow('home');",3000);

	if(page=='home'){ 
		//link
		$.ajax({ 
		  url: "scripts/link.php",
		  context: document.body,
		  success: function(data){
			  var arr=data.split('|');
			$("#tdLink").html('<p class="header_lg"><a href="'+arr[1]+'" target="_blank" class="header_link">'+arr[0]+'</a></p>');
		  }
		});
		
		//dining menus
		$.ajax({
		  url: "scripts/dining-menus.php",
		  context: document.body,
		  success: function(data){
			$("#lyrdiningmenus").html(data);
		  }
		});
		
		//bar menus
		$.ajax({
		  url: "scripts/bar-menus.php",
		  context: document.body,
		  success: function(data){
			$("#lyrbarmenus").html(data);
		  }
		});
	}
}
function counter(c){
	$('#spCounter').html(c);
	c+=1;
	if(c<100){
		setTimeout("counter("+c+");",30);
	}
}
function preload(){
	MM_preloadImages('images/gallery/portrait.jpg','images/gallery/branches.jpg');
}

function showPg(pg,left){
	hideLeftBar(left);
	endSlideShow();
	$('#lyrMain').fadeOut(1000);
	setTimeout('window.open(\''+pg+'\',\'_self\')',600);
}
function showHome(newSec,txt){ 
	if(currSec==''&&newSec==''){return;}
	if(!newSec){newSec='';}
	hideSec(currSec);
	endSlideShow();
	setTimeout('window.open(\'home.html?pg='+newSec+'&txt='+txt+'\',\'_self\')',600);
}
function enterHome(){
	var sec=getQuerystring("pg","");
	var txt=getQuerystring("txt","false");
	if(sec==''){
		$('#lyrMain').fadeIn(300);showLeftBar('menu');slideShow('home');
	} else {
		$('#lyrMain').fadeIn(100);
		expandSec(sec,txt);
	}
}
function showLeftBar(sec){
	$('#lyr'+sec).show().animate({width:'+=200'},400);
	$('#tbl'+sec).show();
}
function hideLeftBar(sec){
	$('#lyr'+sec).animate({width:'-=200'},600);
	$('#tbl'+sec).fadeOut();
}
function showText(sec){
	$('#lyr'+sec+'txt').fadeIn();
	$('#tbl'+sec+'txt').show();
	currTxt=sec;
/*	$('.scroll-pane').jScrollPane(
		{
			verticalDragMinHeight: 20,
			verticalDragMaxHeight: 20,
			horizontalDragMinWidth: 20,
			horizontalDragMaxWidth: 20
		}
	);*/
}
function hideText(sec){
	$('#lyr'+sec+'txt').fadeOut();
	$('#tbl'+sec+'txt').fadeOut();
	currTxt='';
}
function showFooter(){
	$('#lyrfooter').show().animate({height:'+=29',top:'-=29'},200);
	$('#tblfooter').show();
}
function hideFooter(){
	$('#tblfooter').fadeOut(400);
	$('#lyrfooter').animate({height:'-=29',top:'+=29'},200).fadeOut(200);
}
function getQuerystring(key, default_)
{
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}
var currSec='';
function showSec(sec,showText){
	//clean up prev sec if nec
	if(currSec!=''){ 
		if(currTxt!=''){hideText(currTxt);}
		hideLeftBar(currSec);
		hideFooter();
		currSec='';
	}else{
		hideLeftBar('menu');
	}
	setTimeout("expandSec('"+sec+"',"+showText+");",900);
}
function expandSec(sec,txt){
	if(txt){showText(sec);} 
	if(sec.indexOf('contact')!=-1){
		$('img[id^="slide"]').click(function() {
			window.open('http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=The+Thomas+Cubitt,+44+Elizabeth+Street,+London&aq=0&sll=51.493754,-0.150813&sspn=0.007481,0.015857&g=44+Elizabeth+Street,+london&ie=UTF8&hq=The+Thomas+Cubitt,&hnear=44+Elizabeth+St,+London+SW1W+9PA,+United+Kingdom&z=16" target="_blank" class="content-bld-lnk');
		});
	} else { 
		$('img[id^="slide"]').unbind('click');
	}
	slideShow(sec);
	showLeftBar(sec);
	showFooter();
	currSec=sec;
}
function hideSec(sec){
	if(currSec==''){return;}
	if(currTxt!=''){hideText(sec);}
	hideLeftBar(sec);
	hideFooter();
	$('img[id^="slide"]').unbind('click');
	currSec='';
	setTimeout("expandLeftMenu();",900);
}
function expandLeftMenu(){
	showLeftBar('menu');
	slideShow('home');
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) {x.src=x.oSrc;}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function is_valid_url(url)
{
     return url.match(/^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/);
}
function getFormattedDate(d){
	if(!d){d = new Date();}
	
	var date=d.getFullYear()+'-';
	date+=right('00'+(d.getMonth()+1),2)+'-'
	date+=right('00'+d.getUTCDate(),2);

	return date;
}
function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

