// Interface for breakwater



 //functions to do things


function showheight(){
  alert( document.getElementById("m-eat-content").scrollTop  );
}

function scrollTo(val){
  document.getElementById("m-eat-content").scrollTop = val;
}

function scrollToGal(val){
  document.getElementById("sa").scrollTop = val;
}


function showAbout(){

      if(document.getElementById("about-text").style.display == 'none'){
           $('#about-text').slideDown('slow');
      } else {
         $('#about-text').slideUp('slow');
      }

}


function openCart(prodhref){	
   var productId = prodhref.href + '?destination=cart';
   window.open(productId,'bwshop','width=800,height=700,scrollbars=yes');
}




///basic crossfade
function basicCrossfade(myContent, speed, wrap1, wrap2){

       $(wrap2).fadeOut(speed,
        function(){
            $(wrap1).html(myContent);
            $(wrap2).fadeIn(speed);
          })
}



//new slidedown (go from none to display)
function newSlidedown(myContent, slidespeed, wrap1){

   $(wrap1).html(myContent);
   $(wrap1).slideDown(slidespeed);
}








//leave the gallery
function leaveGallery(myContent, lasttab, relAttr, speed, slidespeed, wrap1, wrap2){
//alert('here');
  if(relAttr == 'm-eat' | relAttr == 'm-drink' | relAttr == 'm-breakfast') {
  //entering a menu

          $('#gallery').fadeOut(slidespeed,


          function(){document.getElementById('tablewrap').className = 'menu'; $(wrap1).html(myContent).fadeIn(slidespeed);

          });
          /*

         $(wrap1).slideUp(slidespeed, function(){

            $(wrap1).html(myContent);

            //document.getElementById('contentmain').style.width = 'auto';
            $(wrap1).slideDown(slidespeed);

             });
*/
  } else {
  //not entering a menu

        $('#gallery').fadeOut(slidespeed,


          function(){ $(wrap1).html(myContent).fadeIn(slidespeed);

          });


  }





}


//enter the gallery

function enterGallery(myContent, lasttab, relAttr, speed, slidespeed, wrap1, wrap2){

   if(lasttab == 'm-eat' | lasttab == 'm-drink' | lasttab == 'm-breakfast'){
   //leaving menu

    $(wrap1).slideUp(slidespeed, function(){

              $(wrap1).html('<div class="txt-inner">&nbsp;</div>');

              document.getElementById('tablewrap').className = 'gallery';

               $(wrap2).animate(
                                {
                                  className: 'open',
                  width: '630px'

                                },
                                slidespeed, function(){ $('#gallery').fadeIn(slidespeed)  ;}

                              );




            //document.getElementById('tablewrap').className = 'gallery';
            //document.getElementById('contentmain').style.width = '640px';
            //newSlidedown(myContent, slidespeed, wrap1);


             });

   } else if(lasttab == 'none'  ){
     document.getElementById('tablewrap').className = 'gallery';
     //document.getElementById('contentmain').className = 'text-area open';
             $('#gallery').fadeIn(speed);

   } else {
  //not leaving menu
          //document.getElementById('tablewrap').className = 'gallery';


    $(wrap1).slideUp(slidespeed, function(){

              $(wrap1).html('<div class="txt-inner">&nbsp;</div>');

              document.getElementById('tablewrap').className = 'gallery';

                $('#gallery').fadeIn(speed);


                 })
      /*


            $(wrap2).fadeOut(500);
      $(wrap1).html(myContent).fadeIn(500);

                   $('#galwrap').animate(
                                {
                                  className: 'open2',
                  opacity: 'show'
                                }, slidespeed);
           */
   }


}




//leave the gallery
function leaveMenu(myContent, lasttab, relAttr, speed, slidespeed, wrap1, wrap2){
//alert('here');
  if(relAttr == 'm-eat' | relAttr == 'm-drink' | relAttr == 'm-breakfast'){
    //leaving a menu
    /*
    $(wrap2).fadeOut(1000);
    $(wrap1).html(myContent);
    $(wrap2).fadeIn(1000)  ;
      */
           $(wrap1).slideUp(slidespeed, function(){
             document.getElementById('main').className = 'curr_' + relAttr;
             document.getElementById('tablewrap').className = 'menu';
            $(wrap1).html(myContent);

            $(wrap1).slideDown(slidespeed);
             });



  } else {


       $(wrap1).slideUp(slidespeed, function(){

            $(wrap1).html(myContent);
            document.getElementById('main').className = 'curr_' + relAttr;
            document.getElementById('tablewrap').className = 'normal';
            $(wrap1).slideDown(slidespeed);

             });

  }

}


//enter the gallery

function enterMenu(myContent, lasttab, relAttr, speed, slidespeed, wrap1, wrap2){



   if(lasttab == 'm-eat' | lasttab == 'm-drink' | lasttab == 'm-breakfast' ){
     //lasttab was a menu

    leaveMenu(myContent, lasttab, relAttr, speed, slidespeed, "#contentmain", "#contentmain .txt-inner");

   } else if(lasttab == 'none'){
     document.getElementById('tablewrap').className = 'menu';
     newSlidedown(myContent, slidespeed, '#contentmain');
   } else {
          $(wrap1).slideUp(slidespeed, function(){
             document.getElementById('tablewrap').className = 'menu';
            $(wrap1).html(myContent);

            $(wrap1).slideDown(slidespeed);
             });
   }


}







 $(document).ready(
      function()
      {
    //Automatically assign  onnclick event to menu links
        $('#submenu a').bind(
          'click',
          function()
          {

            //set the variables

           var relAttr = $(this).attr("rel");
           var myContent =  $("#" + relAttr).html();
           var lasttab = document.getElementById('lasttab').value;

           var speed = 500;
           var slidespeed = 1000;

//alert('yo');
            var wrap1 = '#contentmain';

             if(lasttab == 'none'){
                         //new
                         document.getElementById('main').className = 'curr_' + relAttr;
                        if(relAttr == 'm-eat' | relAttr == 'm-drink' | relAttr == 'm-breakfast')  {
                            document.getElementById('tablewrap').className = 'menu';
                         } else {
                            document.getElementById('tablewrap').className = 'normal';
                         }

                           newSlidedown(myContent, slidespeed, '#contentmain');
            } else {

                       $(wrap1).slideUp(slidespeed, function(){

                        $(wrap1).html(myContent);
                        document.getElementById('main').className = 'curr_' + relAttr;
                        if(relAttr == 'm-eat' | relAttr == 'm-drink' | relAttr == 'm-breakfast')  {
                           document.getElementById('tablewrap').className = 'menu';
                        } else {
                           document.getElementById('tablewrap').className = 'normal';
                        }
                        $(wrap1).slideDown(slidespeed);     });




          }



        /*

       if(relAttr == 'm-eat' | relAttr == 'm-drink' | relAttr == 'm-breakfast'){
        //entering a menu
        enterMenu(myContent, lasttab, relAttr, speed, slidespeed, "#contentmain", "#contentmain .txt-inner");
      } else if(relAttr == 'gallery'){
        //entering a gallery
        enterGallery(myContent, lasttab, relAttr, speed, slidespeed, "#contentmain", "#contentmain .txt-inner");
      } else if(lasttab == 'm-eat' | lasttab == 'm-drink' | lasttab == 'm-breakfast'){
        //leaving a menu
          leaveMenu(myContent, lasttab, relAttr, speed, slidespeed, "#contentmain", "#contentmain .txt-inner");
      } else if(lasttab == 'gallery') {
        //leaving a gallery
        leaveGallery(myContent, lasttab, relAttr, speed, slidespeed, "#contentmain", "#contentmain .txt-inner");
      }  else {
        //standard crossfade
        if(lasttab == 'none'){
         //new
         newSlidedown(myContent, slidespeed, '#contentmain');
            } else {



          }



      }
         */



       //set the last tab
            document.getElementById('lasttab').value = relAttr;

          }
        );







        //Hide the menu function

        $('#closebutton').bind(
          'click',
          function()
          {

           // $('#contentmain').stopAll().fadeTo(1000,0, function(){$(this).hide();});


          //  $('#contentmain').slideUp(800, function(){ document.getElementById('contentmain').style.width = '300px';});
           $('#contentmain').slideUp(800);

        document.getElementById('lasttab').value = 'none';
        document.getElementById('main').className = '';

          }
        );



        $('#contentmain').hover( function() {
      //$('#closebutton').fadeIn('slow');
      document.getElementById("closebutton").style.display = 'block';
      },function(){
      document.getElementById("closebutton").style.display = 'none';
     // $('#closebutton').fadeOut('slow');
    });



        $('#closebutton').hover( function() {
      //$('#closebutton').fadeIn('slow');
      document.getElementById("closebutton").style.display = 'block';
      },function(){
      document.getElementById("closebutton").style.display = 'none';
     // $('#closebutton').fadeOut('slow');
    });






           $('#about-text').hover( function() {
      //$('#closebutton').fadeIn('slow');
      document.getElementById("closebutton-home").style.display = 'block';
      },function(){
      document.getElementById("closebutton-home").style.display = 'none';
     // $('#closebutton').fadeOut('slow');
    });



        $('#closebutton-home').hover( function() {
      //$('#closebutton').fadeIn('slow');
      document.getElementById("closebutton-home").style.display = 'block';
      },function(){
      document.getElementById("closebutton-home").style.display = 'none';
     // $('#closebutton').fadeOut('slow');
    });

         $('#closebutton-home').bind(
          'click',
          function()
          {
           $('#about-text').slideUp(1000);


          }
        );








    $('#northern a img').hide();

    $('#northern a').hover( function() {
      $('#northern a img').fadeIn('slow');
      },function(){
      $('#northern a img').fadeOut('slow');
    });



    $('#googlemap a').hover(function(){
      $('#googlemap a img').fadeOut('slow');
    },function(){
      $('#googlemap a img').fadeIn('slow');
    });




  //home landing area
  
  // $('#home-landing a.h-ishka img').hide();  
    $('#home-landing a.h-ishka').hover(function(){
      $('#home-landing a.h-ishka img').show();
    },function(){
      $('#home-landing a.h-ishka img').hide();
    });

 //  $('#home-landing a.h-akoya img').hide();
    $('#home-landing a.h-akoya').hover(function(){
      $('#home-landing a.h-akoya img').show();
    },function(){
      $('#home-landing a.h-akoya img').hide();
    });

  // $('#home-landing a.h-rieds img').hide();
    $('#home-landing a.h-rieds').hover(function(){
      $('#home-landing a.h-rieds img').show();
    },function(){
      $('#home-landing a.h-rieds img').hide();
    });

  // $('#home-landing a.h-lower img').hide();
    $('#home-landing a.h-lower').hover(function(){
      $('#home-landing a.h-lower img').show();
    },function(){
      $('#home-landing a.h-lower img').hide();
    });






 //create fonts with js
 // Cufon.replace('.page-promos- h3', { fontFamily: 'glyph' });
  Cufon.replace('.page-promos- h2', { fontFamily: 'glyph' });  
  Cufon.replace('#navlist li a', { fontFamily: 'glyph' });
  Cufon.replace('#main h5', { fontFamily: 'glyph' });
  Cufon.replace('.submenu a', { fontFamily: 'glyp' , hover: true});



  //make promos clickable 
         $('.view-display-id-block_2 .views-row').bind(
          'click',
          function()
          {  document.location = '/promos'; }        
        );


  //make home promo clickable 
         $('.view-display-id-block_1 .views-row').bind(
          'click',
          function()
          {  document.location = '/promos'; }        
        );


  //scroll to correct pos for gallery
         $('.galscroller').bind(
          'click',
          function()
          {  var cur = this.rel;
		     if(cur == 'breakwater'){cur = 'bar';}
		     var scrollto = document.getElementById( cur + "-drop").value;
			 scrollToGal(scrollto);
			 return false;
		   }        
        );





   /// end the document ready
      }
    );





