$(document).ready(function() {
   // do stuff when DOM is ready
   	$('#lyrmenu').fadeTo(1,0.9);
   	$('#lyrmenus').fadeTo(1,0.9);
   	$('#lyrcompany').fadeTo(1,0.9);
   	  $('#lyrwhoweare').fadeTo(1,0.9);
   	$('#lyrdr').fadeTo(1,0.9);
   	$('#lyrlocation').fadeTo(1,0.9);
   	$('#lyrph').fadeTo(1,0.9);
   	$('#lyrcakes').fadeTo(1,0.9);
         $('#lyrcatering').fadeTo(1,0.9);
   	$('#lyrart').fadeTo(1,0.9);
   	$('#lyres').fadeTo(1,0.9);
   	$('#lyrnewmenu5').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);
});
var currTxt='';

function introTemp(){
	counter(0);
	preload();
	var pg=getQuerystring("pg","");
	if(pg!=""){
		chgView(pg,null,false);
	}
	setTimeout("$('#lyrIntro').fadeOut();$('#lyrMain').fadeIn();showLeftBar('menu');slideShow('home');",3000);
}
function counter(c){
	$('#spCounter').html(c);
	c+=1;
	if(c<100){
		setTimeout("counter("+c+");",30);
	}
}
function preload(){
	MM_preloadImages('images/gallery/front1.jpg','images/gallery/front2.jpg');
}
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('location')!=-1){
		$('img[id^="slide"]').click(function() {
			window.open('http://maps.google.com/maps?q=Boulangerie+Bon+Matin,+178+Tollington+Park,+London+N4+3AJ,+United+Kingdom&hl=en&ll=51.572189,-0.110421&spn=0.013923,0.054932&sll=51.475499,-0.171425&sspn=0.006976,0.01929&vpsrc=6&hq=Boulangerie+Bon+Matin,+178+Tollington+Park,&hnear=London+N4+3AJ,+United+Kingdom&t=m&z=15&iwloc=A');
		});
	} 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 flashMessage(lyr, opacStart, opacEnd){
	if(!lyr){return;}
	opacity(lyr,opacStart,opacEnd,900,'flashMessage(\''+lyr+'\','+opacEnd+','+opacStart+')',100);
}
function opacity(id, opacStart, opacEnd, millisec, onend, onendtime, to) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

	//determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            toHide=setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            toShow=setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
	if(onend!='') {
		onendtime+=(timer*speed);
		toDo=setTimeout(onend, onendtime);
	}
}
function changeOpac(opacity, id) { 
	//change the opacity for different browsers 
    var object = document.getElementById(id).style; 
	object.visibility='visible';
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
	if(opacity>0){object.display='';}else{object.display='none';}
}

