
  $(function(){
   
    $('#back-to-site').click(function(){
        var windowHeight = $(window).height(); 
        $.scrollTo('#masthead',1000);
        $(this).delay(1000,function(){
            $("#brochure .content").children().remove();
            $("#brochure").hide();
            $('#brochure-nav li a').removeClass('active');
        });
        return false;
    });
    
    $('.back-to-top').click(function(){
        $.scrollTo('#masthead',1000);
        return false;
    });
    
    $('.floating-nav a').click(function(){
        $('#content .content').height($('#content .content').height());
        var html = '<img src="'+ $(this).attr('href') +'" alt="" />';
        $('#content .content').html(html);
        $('.floating-nav li').removeClass('active');
        $(this).parent().addClass('active');
        return false;
    });
    
    
    $('.show-next').click(function(){
      $(this).parent().next().slideDown(1000);
      $(this).hide();
      return false;      
    });
    
    $('#content .hidden').click(function(){
      $(this).slideUp(500);
    });
    
    
    $('.sub-nav.shore-way-nav li a').click(function(){
      var content = $(this).attr('href');
      //alert(content);
      $('#shore-content').load(content);
      $(this).parent().siblings().removeClass('active');
      $(this).parent().addClass('active');
      return false;
    });
    
    $('.sub-nav.team-nav li a').click(function(){
      $('#content .panel:first-child').load($(this).attr('href'), {"id":$(this).attr('rel')});
      $(this).parent().siblings().removeClass('active');
      $(this).parent().addClass('active');
      //setContainerHeight();
      return false;
    });
    
    $('.sub-nav.team-nav li').click(function(){
      $(this).children().click();
      return false;
    });
    
    $('.sub-nav.team-nav li:first-child').addClass('active');
    
    $('.show-sidebar-login').click(function(){
      $('#sidebar-login').slideDown(400);
      return false;
    });
    
   
    $('.news-signup').click(function(){

        $.scrollTo('#footer',1000);
        $(this).delay(1000,function(){
          $('#newsletter-signup').effect("shake", {}, 100);

        });
        return false;
    });
    
    $('#newsletter-signup .textbox').focus(function(){
        $(this).next().slideDown(400);
        return false;
    });
    
    $('#newsletter-signup .textbox').blur(function(){
        $(this).next().slideUp(400);
        return false;
    });
    
    $(".jason").bind("mouseenter",function(){
      $(this).children('p').slideDown(250);
    }).bind("mouseleave",function(){
      $(this).children('p').slideUp(250);
    });
    
    $(".jason img").bind("contextmenu", function(e) {
              e.preventDefault();
          });

     $('.show-interiors').click(function(){
       var windowHeight = $(window).height();
      $('#brochure').height(windowHeight).show();
      $('#brochure .content').height(windowHeight-40);
      $.scrollTo('#brochure',1000);
      $(this).delay(1000,function(){
        $('#brochure .content').load('includes/brochure.php', {'deHu2w' : 'interiors'});
      });
      return false;
    });
    
    $('#brochure-nav li a').click(function(){
      $('#brochure .content').load('includes/brochure.php', {'deHu2w' : $(this).attr("rel")});
      return false;
    });
    function addCorners(){
    
      if(!$.browser.mozilla){
        
        var corners = "<img src=\"img/panel-tr.gif\" alt=\"\" class=\"tr\"/>" +
                      "<img src=\"img/panel-tl.gif\" alt=\"\" class=\"tl\"/>" +
                      "<img src=\"img/panel-br.gif\" alt=\"\" class=\"br\"/>" +
                      "<img src=\"img/panel-bl.gif\" alt=\"\" class=\"bl\"/>";
                      
        var cornersOpaque = "<img src=\"img/panel-tr-op.gif\" alt=\"\" class=\"tr\"/>" +
                      "<img src=\"img/panel-tl-op.gif\" alt=\"\" class=\"tl\"/>" +
                      "<img src=\"img/panel-br-op.gif\" alt=\"\" class=\"br\"/>" +
                      "<img src=\"img/panel-bl-op.gif\" alt=\"\" class=\"bl\"/>";
        $('#mainwrapper .panel:not(.filler)').append(corners);
        $('#mainwrapper .panel.filler').append(cornersOpaque);
        $('#splash').append("<img src=\"img/splash-tl.gif\" alt=\"\" class=\"tl\"/>");
      }else {
        $('.panel').css("-moz-border-radius", "5px");
        $('#splash').css("-moz-border-radius-topleft", "5px");
      }  
    }
    
    addCorners();
    
    
    (function ($) {
      $.fn.vAlign = function() {
      	return this.each(function(i){
      	var ah = $(this).height();
      	var ph = $(this).parent().height();
      	var mh = (ph - ah) / 2;
      	$(this).css('margin-top', mh);
      	});
      };
      })(jQuery);
    
    var mycarousel_itemList = [
      {url: 'img/logos/jo-malone.gif', title: ''},
      {url: 'img/logos/moet-hennessy.gif', title: ''},
      {url: 'img/logos/penhaligons.gif', title: ''},
      {url: 'img/logos/the-white-company.gif', title: ''},
      {url: 'img/logos/la-maison-du-chocolat.gif', title: ''},
      {url: 'img/logos/acquia-di-parma.gif', title: ''},
      {url: 'img/logos/greycoat-academy.gif', title: ''},
      //{url: 'img/logos/hayford-and-rhodes.gif', title: ''},
      //{url: 'img/logos/jane-urquart.gif', title: ''},
      {url: 'img/logos/josephine-home-short.gif', title: ''},
      {url: 'img/logos/pure-lochside.gif', title: ''},
      {url: 'img/logos/geo-f-trumper-carousel.gif', title: ''}
      //{url: 'img/logos/zoono.gif', title: ''}
    ];

    function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
    {
        // The index() method calculates the index from a
        // given index who is out of the actual item range.
        var idx = carousel.index(i, mycarousel_itemList.length);
        carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
        
    };
    
    function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
    {
        carousel.remove(i);
    };
    
    /** Item html creation helper. **/
    function mycarousel_getItemHTML(item){
        return '<img src="' + item.url + '" alt="' + item.title + '" />';
    };
  
    $('#partner-logos').jcarousel({
      scroll:5,
      animation:600,
      wrap: 'circular',
      itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
      itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });
    
  });
  
    function setContainerHeight(){
      $('.filler').height(0);
      var contentHeight = $('#content').height() + parseInt($('#content').css('padding-top')) + parseInt($('#content').css('padding-bottom'));
      var sidebarHeight = $('#sidebar').height() + parseInt($('#sidebar').css('padding-top')) + parseInt($('#sidebar').css('padding-bottom'));
      if( sidebarHeight < contentHeight ){
        var fillerHeight = contentHeight - sidebarHeight - 5;
        $('#sidebar .filler').height(fillerHeight).show();
      }else{
        var fillerHeight = sidebarHeight - contentHeight - 5;
        $('#content .filler').height(fillerHeight).show();
      }
    }
  
      function setFooterHeight(){
        var windowHeight = $(window).height(); 
        var footerTop = $('#footerwrapper').position();
        if(footerTop.top < windowHeight){
           var footerHeight = windowHeight - footerTop.top +250;
          $('#footerwrapper').height(footerHeight);
        }
      }
  
  $(window).load(function(){ 

    
    setContainerHeight();
    

    
    setFooterHeight();
    
    


    $('#partner-logos img').vAlign();
  });


