function logThis(logitem) {
  if (window.console) {
    console.log(logitem);
  }
}

/*$(document).ready(function() {
  $("ul.nav ul").bbgiframe();
  
  $('li.dropdown').hover(function(){
    $('ul', this).css('visibility','visible');
  }, function(){
    $('ul', this).css('visibility','hidden');
  });

 
  $('#carousel').jCarouselLite({
    auto: 4000,
    btnNext: "span.right-arrow",
    btnPrev: "span.left-arrow",
    easing: "easeOutQuart",
    speed: 1000
  });
  */
  
  // EVENT CALENDAR
    $('table.sm_calendar td.eventDay').each(function(){
      $(this).hover(function(){
        $('div.events_today',this).show();
      },function(){
        $('div.events_today',this).hide();
      });
    });
    
  $('input[name="search"]').focus(function(){ if(this.value!=''){this.value=''}; });  
  $('input[name="search"]').blur(function(){ if(this.value==''){this.value='search site'}; });

  $('input[name="person-name"]').focus(function(){ if(this.value=='Name'){this.value=''}; });  
  $('input[name="person-name"]').blur(function(){ if(this.value==''){this.value='Name'}; });
  
  // QUICK SEARCH BAR

  $('a#go').css('visibility','hidden');
  $('select#services').change(function(){
    var servicePageLink = $('select#services option:selected').attr('title') 
    window.location = servicePageLink;
  });
  $('select#sectors').change(function(){
    var sectorPageLink = $('select#sectors option:selected').attr('title')   
    window.location = sectorPageLink;
  });
  
  
 $("div.scrollable").scrollable({size: 5}).circular();
  
  
  //preload gallery images
  $("ul.items li a").each(function() {
    var newImgPath = $(this).attr("href");
    img = new Image();
    img.src=newImgPath;
  });
  
  
  $("ul.items li a").click(function() {
    
    //$(".main_project_image img").remove();
    if( !$(this).parents(".image_gallery").hasClass("opened") ) {
      
      $("<img class='gallery_main_img' src="+$(this).attr('href')+" alt=''></img>")
      .appendTo($(this).parents(".image_gallery").find(".main_image"));
      
      $(this).parents(".image_gallery").find(".main_image").slideDown();
      $(this).parents(".image_gallery").addClass("opened");
      $(this).parents(".image_gallery").find(".open_gallery").text("Click to close gallery");
      
      $.scrollTo($(this).parents(".image_gallery"),800);  
      return false;  
    }
    else {
      $(this).parents(".image_gallery").find(".main_image img").attr("src", $(this).attr('href'));
    }
    
    return false;
    
  });
  
  $("img.gallery_main_img").live("click", function(){
    var currentImg = $(this).parent().parent("div.image_gallery").find("ul.items a[href="+ $(this).attr('src') +"]");
    var currentRel = parseInt(currentImg.attr("rel"));  
    //
    logThis("This Image:"  + currentImg.attr("href") + " - (REL) " + currentRel);
    //
    var api = $(this).parent().parent("div.image_gallery").find("div.scrollable").scrollable({api: true, size:5});
    if(currentImg.hasClass("last")) {
      $(this).parents(".image_gallery").find(".main_image img").attr("src", $(this).parents(".image_gallery").find("ul li a.first").attr("href"));
      logThis("last image?");
    }
    else {
      var nextImage = currentImg.parent("li").next().find("a");
      logThis("Next Image:"  + nextImage.attr("href") + " - (REL) " + nextImage.attr("rel") );
      $(this).parents(".image_gallery").find(".main_image img").attr("src", $(this).parents(".image_gallery").find("ul li a[rel="+(currentRel+1)+"]").attr("href"));
    }
    api.next();
  });

  
  $("a.open_gallery").click(function() {
    
    //$(".main_project_image img").remove();
    
    if( !$(this).parents(".image_gallery").hasClass("opened") ) {
      
      $("<img class='gallery_main_img' src="+$(this).parent('.image_gallery').find('ul.items li:first-child a').attr('href')+" alt=''></img>")
      .appendTo($(this).parent(".image_gallery").find(".main_image"));
      $(this).parent(".image_gallery").find(".main_image").slideDown();
      $(this).text("Click to close gallery");
      
      $(this).parents(".image_gallery").addClass("opened");
      
      $.scrollTo($(this).parents(".image_gallery"),800);  
    }
    else {
        $(this).parent(".image_gallery").find(".main_image").slideUp( 500, function(){
            
            $(this).parents(".image_gallery").find(".main_image img").remove();
          });
        $(this).text("Click to see the full images");

        $(this).parents(".image_gallery").removeClass("opened");

        $.scrollTo($(this).parents(".image_gallery"),800);
    }
    
    return false;
    
  });
  
    var addPrintFooter = (function() {
        var p = document.createElement('p');
        p.className = 'print-footer';
      p.innerHTML = '<strong>url:</strong> ' + window.location.href;
        document.body.appendChild(p);
      })(); 

  
  
});





