var IMAGE_WIDTH   = 1500;
var IMAGE_HEIGHT  = 1050;
var CURRENT_SLIDE_INIT = true;
var CURRENT_SLIDE_IDX  = 0;
var IE_FADE_STEP_COUNT = 40;

$.fn.navigation = function() {
  return $(this).each(function(e) {
    var $nav = $(this);
    var visibleElement = false;

    $("a", this).not('#contact-link, #about-nav-link').click(function(e) {

      if ( $(this).siblings("ul").size() ) {

        if (false && /about$/.test($(this).attr("href")) && $('body#about-body').size() == 0) {
          return false;
        }

        if (false && /contact$/.test($(this).attr("href")) && $('#contact').size() == 0) {
          return;
        }

        var $ul = $(this).siblings("ul");

        if ( $ul.is(":visible") ) {
          $ul.hide();
          $(this).removeClass("hover");

          if (/^(Services|Portfolio)$/i.test($(this).html())) {
            e.preventDefault();
            e.stopPropagation();
            return false;
          }

          if (!/portfolio|about/.test($(this).attr("href"))) {
            $('#gallery-data .tabs-navigation').show();
            $('#contact').show();
            $('body#about-body ul.about-nav, body#about-body ul.about-nav li, body#about-body #about .shell.foreground').show();
          }

          if ( $nav.find("ul:visible ul:visible").size() == 0 ) {
            visibleElement = false;
          }
        }
        else {
          $('#gallery-data .tabs-navigation').hide();
          $('a[href="#project-data"], a[href="#project-chooser"]').removeClass('active');
          //$('.link-close:visible').click();
          $('#contact, #project-data, #project-chooser, .link-close').hide();
          $('body#about-body ul.about-nav, body#about-body ul.about-nav li, body#about-body #about .shell.foreground').hide();

          /*
            if this ul extends past the right hand side of the page,
            move it so it opens to the left
            if it's past the left of the page, open it in the middle
          */
          if ($ul.is('.main .sub .tertiary .tertiary')) {
window.$ula = $ul;
            $ul.css('left',0);
            var width = 0;
            $ul.find('li').each(function(){
              width += $(this).is('.two-cell') ? 302 : 151;
            });
            if (width < 151 * 4) {
              $ul.width(width);
            }
          }

          $ul.show();

          if ($ul.is('.main .sub .tertiary .tertiary')) {
            if (100 + $ul.offset().left + $ul.width() >= $(window).width()) {
//console.log(1);
              $ul.css({
                left: -1 * $ul.width()
              });
              if ($ul.offset().left <= 0) {
//console.log(2);
                $ul.css({ left: (-1 * $ul.width()) + parseInt($ul.width() / 2, 10) });
              }
            }
          }

          $(this).addClass("hover");
          visibleElement = true;

          if ( $ul.is(".text-data") ) {
            $ul.css({
              left: -($(this).offset().left - $(this).parents("ul:eq(0)").offset().left)
            });
          }
          if ( $(this).parents(".right").size() ) {
            $ul.css({
              width: $ul.find("li").size() * $ul.find("li").outerWidth()
            })
          }

          $(this).parent().siblings("li").find(" a.hover").each(function() {
            $(this).removeClass("hover").siblings("ul").hide();
          });
        }

        return false;
      }
      else {
        return true;
      }

    });

    $("body").bind("click", function(e) {
      if ( visibleElement && !$(e.target).parents("#navigation").size() ) {
        $("#navigation a.hover").each(function() {
          $(this).removeClass("hover").siblings("ul").hide();
        });
      }
//alert($(e.target).attr("href"));
      if (!/portfolio|about/.test($(e.target).attr("href"))) {
        $('#gallery-data .tabs-navigation').show();
        $('#contact').show();
        $('body#about-body ul.about-nav, body#about-body ul.about-nav li, body#about-body #about .shell.foreground').show();
      }
    });
  });
}

$.fn.preload = function(path, images) {
  for (var i = 0; i < images.length; i++) {
    var $image = $("<img />");
    $image.attr('src', path + "/" + images[i]);
  }
}

$.fn.tabs = function(preactivate) {
  return $(this).each(function() {
    var $t = $(this);

    var $nav = $t.find(".tabs-navigation");
    var $tabs = $t.find(".tabs-content");

    $nav.find("ul a").click(function() {
      if ( $(this).attr("href") == "#" || $( $(this).attr("href") ).size() == 0 ) {
        return false;
      }

      var $href = $( $(this).attr("href") );

      if ( $href.is(":visible") && $t.find(".default-tab").size() ) {
        $href.hide();
        $t.find(".default-tab").show();
        $(this).removeClass("active");
      }
      else {
        $nav.find("ul a").removeClass('active');
        $(this).addClass("active");
        
        $tabs.find(".tab").hide();
        $( $(this).attr("href") ).show();
      }

      if ($(this).attr("href") == '#project-data' || $(this).attr("href") == '#project-chooser') {
        $('a.link-close').show();
      }

      return false;
    });

    if (preactivate) {
      $nav.find("ul a").eq(0).click();
    }
  });
}

/*
  get an object with current gallery image size data:
  image_width
  image_height
  side_padding = how much width of each adjascent slide image is visible?

 */
function get_sizes() {
  var $window = $(window);
  var $slider = $("#gallery-slider");
  var $slider_ul = $slider.find('ul');
  var $slides = $slider_ul.find('li');

  var headerHeight = $("#header").outerHeight() + $("#navigation").outerHeight();

  var availableHeight = $window.height() - headerHeight - 34;
  var availableWidth  = $window.width();

  var CURRENT_IMAGE_WIDTH  = IMAGE_WIDTH;
  var CURRENT_IMAGE_HEIGHT = IMAGE_HEIGHT;
  var CURRENT_SIDE_PADDING = 0;

  if ((availableWidth / availableHeight) < (IMAGE_WIDTH / IMAGE_HEIGHT)) {
//    $('#slogan p').html('too tall');
    CURRENT_IMAGE_WIDTH  = availableWidth;
    CURRENT_IMAGE_HEIGHT = (IMAGE_HEIGHT / IMAGE_WIDTH) * availableWidth;
  }
  else if ((availableWidth / availableHeight) > (IMAGE_WIDTH / IMAGE_HEIGHT)) {
//    $('#slogan p').html('too wide');
    CURRENT_IMAGE_WIDTH  = (IMAGE_WIDTH / IMAGE_HEIGHT) * availableHeight;
    CURRENT_IMAGE_HEIGHT = availableHeight;
    CURRENT_SIDE_PADDING = parseInt((availableWidth - CURRENT_IMAGE_WIDTH) / 2, 10);
  }
//  else {
//    $('#slogan p').html('just right');
//  }

  var current_left = parseInt($slider_ul.css('left'), 10);
  var current_slide = current_left ? parseInt(Math.round((current_left * -1) / CURRENT_IMAGE_WIDTH), 10) : 0;

  if ((window.NOT_INIT && CURRENT_SLIDE_INIT) || (current_left && CURRENT_SLIDE_INIT)) {
    current_slide = 2;
    CURRENT_SLIDE_INIT = false;
  }

  return {
    image_width:   parseInt(CURRENT_IMAGE_WIDTH, 10),
    image_height:  parseInt(CURRENT_IMAGE_HEIGHT, 10),
    side_padding:  parseInt(CURRENT_SIDE_PADDING, 10),
    current_slide: current_slide
  }
}

function prev_portfolio() {
  // find this portfolio 
  var href = document.location.href.replace(/http:\/\/.+?\//, '/').replace(/#.*$/, '');
  var $pl  = $('ul.tertiary a[href="' + href + '"]');

  // find the previous one
  if ($pl.parent('li').prev('li').find('a').size()) {
    var $prev = $pl.parent('li').prev('li').find('a');
  }
  else {
    // find the next portfolio menu
    if ($pl.parents('.residential').size()) {
      $prev = $('.remodel a:last');
    }
    else if ($pl.parents('.commercial').size()) {
      $prev = $('.residential a:last');
    }
    else if ($pl.parents('.remodel').size()) {
      $prev = $('.commercial a:last');
    }
    else if ($pl.parents('.fabrication').size()) {
      $prev = $('.fabrication a:last');
    }
    else if ($pl.parents('.before-and-after').size()) {
      $prev = $('.design a:first');
    }
    else if ($pl.parents('.details').size()) {
      $prev = $('.before-and-after a:last');
    }
    else if ($pl.parents('.design').size()) {
      $prev = $('.details a:last');
    }
  }

    window.$pl = $pl;
    window.$prev = $prev;
  if (!$prev) {
    alert('I did not find the next portfolio...?');
  }

  // go there
//alert('the prev one: "' + $prev.html() + '"');
  document.location.href = $prev.attr('href');
}

function next_portfolio() {
  // find this portfolio 
  var href = document.location.href.replace(/http:\/\/.+?\//, '/').replace(/#.*$/, '');
  var $pl  = $('ul.tertiary a[href="' + href + '"]');

  // find the next one
  if ($pl.parent('li').next('li').find('a').size() > 0) {
    var $next = $pl.parent('li').next('li').find('a');
  }
  else {
    // find the next portfolio menu
    if ($pl.parents('.residential').size()) {
      $next = $('.commercial a:first');
    }
    else if ($pl.parents('.commercial').size()) {
      $next = $('.remodel a:first');
    }
    else if ($pl.parents('.remodel').size()) {
      $next = $('.residential a:first');
    }
    else if ($pl.parents('.fabrication').size()) {
      $next = $('.fabrication a:first');
    }
    else if ($pl.parents('.before-and-after').size()) {
      $next = $('.details a:first');
    }
    else if ($pl.parents('.details').size()) {
      $next = $('.design a:first');
    }
    else if ($pl.parents('.design').size()) {
      $next = $('.before-and-after a:first');
    }
  }

    window.$pl = $pl;
    window.$next = $next;
  if ($next.size() == 0) {
    alert('I did not find the next portfolio...?');
  }

  // go there
//alert('the next one: "' + $next.html() + '"');
  document.location.href = $next.attr('href');
}

function fill_project_ul() {
  // find this portfolio 
  var href = document.location.href.replace(/http:\/\/.+?\//, '/').replace(/#.*$/, '');
  var $pl  = $('ul.tertiary a[href="' + href + '"]');

  // find all siblings
  var $dest_ul = $('#project-chooser ul');
  var $ul = $pl.parent('li').parent('ul');
//console.log('pl: ' + $pl.attr('href'));
  $ul.find('li').each(function(){
    var $clone = $(this).clone();
//console.log('clone: ' + $clone.attr('href'));
    if ($clone.find('a').attr('href') == $pl.attr('href')) {
      $clone.find('a').addClass('active');
    }
    $dest_ul.append($clone);
  })
}

function next_slide() {
  $('body, .link-close').click();

//  alert('next');
  var sizes = get_sizes();
  var next_slide = sizes.current_slide + 1;

  var $slider_ul = $('#gallery-slider ul');
  var $slides = $slider_ul.find('li');

  if (next_slide > $slides.size() - 2) {
    sizes.current_slide = 1;
    var left = parseInt(-1 * (sizes.image_width - sizes.side_padding), 10);
    $slider_ul.css('left', left);
    next_slide = 2;
  }

  var left = parseInt(-1 * (next_slide * sizes.image_width - sizes.side_padding + (4 * sizes.current_slide)), 10);

  $slider_ul.animate({ left: left }, 500);
  if (false && /private_residence/.test(document.location.href)) {
    $slides.eq(sizes.current_slide).animate({ opacity: .5 }, 500);
    $slides.eq(next_slide).animate({ opacity: 1 }, 500);
  }

  return false;
}

function prev_slide() {
  $('body, .link-close').click();
//  alert('prev');

  var sizes = get_sizes();
  var prev_slide = sizes.current_slide - 1;

  var $slider_ul = $('#gallery-slider ul');
  var $slides = $slider_ul.find('li');

  if (prev_slide <= 0) {
    sizes.current_slide = $slides.size() - 2;
    var left = parseInt(-1 * (sizes.current_slide * sizes.image_width - sizes.side_padding + (4 * (sizes.current_slide+1))), 10);
    $slider_ul.css('left', left);
    prev_slide = sizes.current_slide - 1;
//    return false;
  }

  var left = parseInt(-1 * (prev_slide * sizes.image_width - sizes.side_padding + (4 * sizes.current_slide)), 10);

  $slider_ul.animate({ left: left }, 500);
  if (false && /private_residence/.test(document.location.href)) {
    $slides.eq(sizes.current_slide).animate({ opacity: .5 }, 500);
    $slides.eq(prev_slide).animate({ opacity: 1 }, 500);
  }

  return false;
}

function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */
try {
var matchArray=emailStr.match(emailPat);
} catch (e) {alert(e);}
if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
return false;
   }
}

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
return false;
}

if (len<2) {
return false;
}

return true;
}

function contact_send() {

  var errors = false;

  if ($('#contact-input-from').val() == '') {
    errors = true;
    $('label[for=contact-input-from]').addClass('error');
  }
  else {
    $('label[for=contact-input-from]').removeClass('error');
  }

  if (!emailCheck($('#contact-input-email').val())) {
    errors = true;
    $('label[for=contact-input-email]').addClass('error');
  }
  else {
    $('label[for=contact-input-email]').removeClass('error');
  }

  if ($('#contact-input-message').val() == '') {
    errors = true;
    $('label[for=contact-input-message]').addClass('error');
  }
  else {
    $('label[for=contact-input-message]').removeClass('error');
  }

  if (errors) {
    $('div#contact-messages').addClass('error').html('PLEASE FILL OUT ALL FIELDS, THEN CLICK SEND.');
    return;
  }

  $('div#contact-messages').removeClass('error').html('LOADING...');

  $.ajax({
    type: 'post',
    url: 'http://www.schmittcompany.com/index.php/contact-submit',
    data: $('form#contact-form').serialize(),
    error: function(){
      $('div#contact-messages').addClass('error').html('THERE WAS AN ERROR. PLEASE TRY AGAIN LATER.');
    },
    success: function(data){
      if (data) {
        window.contact_response = data;
        $('div#contact-messages').removeClass('error').html('THANK YOU. YOUR MESSAGE HAS BEEN SENT.');
      }
      else {
        $('div#contact-messages').addClass('error').html('THERE WAS AN ERROR. PLEASE CHECK YOUR INPUT AND TRY AGAIN.');
      }
    }
  });
}

function toggle_contact_form() {
  var $contact = $('#contact');
  if ($contact.is(':visible') || window.CONTACT_VISIBLE) {
    $contact.hide();
    window.CONTACT_VISIBLE = false;
  }
  else {
    $contact.show();
    window.CONTACT_VISIBLE = true;
  } 
}

function home_fader() {
  var $fader = $("#home-fader");

  if (!window.home_fader_interval) {
    window.home_fader_interval = setInterval(home_fader, 5000);
  }

  var $activeSlide;
  if ($.browser.msie) {
    $activeSlide = $fader.find("li:eq(" + CURRENT_SLIDE_IDX + ")")
  }
  else {
    $activeSlide = $("#home-fader li:visible");
  }
  var fadeSpeed = 2000;

  var $nextSlide = $activeSlide.next().size() ? $activeSlide.next() : $fader.find("li:eq(0)");

  if ($.browser.msie) {
    ie_fade(1, $activeSlide, $nextSlide);
    CURRENT_SLIDE_IDX = (CURRENT_SLIDE_IDX + 1) % 3;
  }
  else {
    $activeSlide.fadeOut(fadeSpeed);
    $nextSlide.fadeIn(fadeSpeed);
  }

}

function ie_fade(step, $active, $next) {

  if (step == 1) {
    $('#home-fader').find('li').not($active).find('img, p').css('filter','alpha(opacity=0)');
  }

  if (step > IE_FADE_STEP_COUNT) {
    $active.find('img, p').css('filter','alpha(opacity=0)');

    $next.find('img').css('filter','alpha(opacity=100)');
    $next.find('p').css('filter','alpha(opacity=75)');

    return;
  }

  $active.find('img').css('filter','alpha(opacity=' + (100 - (step * 100/IE_FADE_STEP_COUNT))  + ')');
  $active.find('p').css('filter','alpha(opacity='   + (75  - (step * 75 /IE_FADE_STEP_COUNT) ) + ')');

  $next.find('img').css('filter','alpha(opacity=' + (step * 100/IE_FADE_STEP_COUNT) + ')');
  $next.find('p').css('filter','alpha(opacity='   + (step * 75 /IE_FADE_STEP_COUNT) + ')');

  setTimeout(function() { ie_fade(step+1, $active, $next); }, 2000/IE_FADE_STEP_COUNT);
}

$(document).ready(function() {

  if ($.browser.msie && $.browser.version <= 7) {
    $('#slogan').css('position','static');
    $('#slogan').css('position','absolute');
/*
    setTimeout(function(){
      delete $('#slogan')[0].style.position;
      setTimeout(function(){
        $('#slogan')[0].style.position = 'absolute'
      },1);
    }, 1);
*/
  }

  $('#contact-body #contact-link').addClass('active');

  if (!/contact/.test(document.location.href)) {
    $('#contact-body #contact-link').removeClass('active');
  }

  $('#navigation .tertiary a').each(function(){
    var $this = $(this);
    if ($this.width() > 141) {
      $this.parent('li').addClass('two-cell');
    }
  });

  $('a.link-close').click(function(){
    $('a[href="#project-data"], a[href="#project-chooser"]').removeClass('active');
    $('#project-data, #project-chooser').add($(this)).hide();
    return false;
  });

  $('body#about-body a#about-nav-link').addClass('active').click(function(){ return false; });

  $('#partners a').click(function() {
    $('#partners').css({display: 'inline'});

    $('ul.about-nav a').removeClass('active'); // #B95915
    $('#about-partners-link').addClass('active');

    $('#partners a').removeClass('active');
    $(this).addClass('active');

    $('#about-data .tab').hide();
    $('#' + this.id + '-tab').show();

    return false;
  });

  $('#about-sc-link').click(function() {
    $('#partners').hide();

    $('ul.about-nav a').removeClass('active');
    $('#about-sc-link').addClass('active');

    $('#about-data .tab').hide();
    $('#about-overall-tab').show();

    return false;
  });

  $('#about-partners-link').click(function() {
    $('#partners').css({display: 'inline'});

    $('ul.about-nav a').removeClass('active');
    $('#about-partners-link').addClass('active');

    $('#partners a').removeClass('active').eq(0).addClass('active');

    $('#about-data .tab').hide();
    $('#about-partner-1-tab').show();

    return false;
  });

  $('#about-news-link').click(function() {
    $('#partners').hide();

    $('ul.about-nav a').removeClass('active');
    $('#about-news-link').addClass('active');

    $('#about-data .tab').hide();
    $('#about-news-tab').show();

    return false;
  });

  if( $("#home-fader").size() ) {

//    $('#home-fader ul p').css('opacity', .75);

/*
    var $fader = $("#home-fader");
    var $window = $(window);

    $fader.find("li").hide().eq(0).show();
    var $activeSlide = $("#fader li:visible");
    var fadeSpeed = 2000;
*/

    var $fader = $("#home-fader");
    if ($.browser.msie) {
      var $li = $fader.find('li').eq(0);
      $li.find("img").css('filter','alpha(opacity=100)');
      $li.find("p").css('filter','alpha(opacity=75)');
    }
    else {
      $fader.find("li").hide().eq(0).show();
    }

    setTimeout(home_fader, 3000);

    /* ff 3.x bug */
    setTimeout(function(){ $(window).resize(); }, 1);

/*
    $(window).bind('XXresize', function() {
    });

    $(window).resize().bind('XXload', function() {
      $(window).resize();
    });
*/
  }

  if( $("#gallery-slider").size() ) {

    $('.project-prev').click(prev_portfolio);
    $('.project-next').click(next_portfolio);

    $('.arrow-prev').click(prev_slide);
    $('.arrow-next').click(next_slide);

    fill_project_ul();

    $('#footer-push').hide();

    var $slider = $("#gallery-slider");
    var $slider_ul = $slider.find('ul');
    var $slides = $slider_ul.find('li');
    if (false && /private_residence/.test(document.location.href)) {
      $slides.css('opacity', .5);
    }
    var $window = $(window);

    // create the initial slideshow slide copies
/*
    var $clone = $slides.eq(0).clone();
    $clone.css({
      'background-color': '#ACA095'
    }).find('img').css('visibility', 'hidden');
    $slider_ul.prepend($clone);
    $slider_ul.append($clone.clone());
*/
    $slider_ul.append($slides.eq(0).clone());
    $slider_ul.prepend($slides.eq($slides.size()-1).clone());
    $slider_ul.prepend($slides.eq($slides.size()-2).clone());

    $slider_ul.hide();

    // set slide positions
    var sizes = get_sizes();

    if (false && /private_residence/.test(document.location.href)) {
      $slides.eq(sizes.current_slide + 1).css('opacity',1);
    }

    $slider.height(sizes.image_height);

    $slider_ul.width(($slider_ul.find('li').size() * sizes.image_width) + ($slides.size() * 4));
    $slider_ul.height(sizes.image_height);
    $slider_ul.css({
      left: parseInt(-1 * (1 * sizes.image_width - sizes.side_padding - 4), 10)
    });

//    $slider_ul.show();

    var headerHeight = $("#header").outerHeight() + $("#navigation").outerHeight();
    $('#footer').css({
      top:          (headerHeight + $slider.height()) - 1,
      'border-top': '35px solid #C4BAB1'
    });

    $(window).bind('resize', function() {

      $('#gallery-data').css('left', $('#navigation ul.main li:first').offset().left - 125);

      var sizes = get_sizes();

      $slider_ul.hide();

      /* set sizes */
      $slider.height(sizes.image_height);
      $slider_ul.height(sizes.image_height);
      var $slides = $slider_ul.find('li');
      $slider_ul.width(($slides.size() * sizes.image_width) + ($slides.size() * 4));
      $slides.width(sizes.image_width);

      $('#footer').css('top', (headerHeight + $slider.height()) - 1);

      var left = parseInt(-1 * (sizes.current_slide * sizes.image_width - sizes.side_padding + (4 * sizes.current_slide)), 10);
      $slider_ul.css('left', left);

      if (window.NOT_INIT) {
        $slider_ul.parent().css('background-image','none');
        $slider_ul.show();
      }
      else {
        window.NOT_INIT = true;
      }

    });
    $(window).resize().bind('load', function() {
      $(window).resize();
        /* ff 3.x bug */
      if ($.browser.mozilla && $.browser.version.substr(0,1) == 3) {
        setTimeout(function(){ $(window).resize(); }, 1);
      }
    });

  }

  $("#navigation").navigation();

  $.fn.preload("/images", ["slider-prev-hover.png", "slider-next-hover.png"]);

  $(".tabs").tabs(true);
  $("#about").tabs(false);

  if( $.browser.msie && $.browser.version.substr(0,1) == 6 ) { 
    DD_belatedPNG.fix('#navigation a, #gallery-data .tabs-navigation, #gallery-data .tabs-content, #gallery-data .tabs-navigation .project-prev, #gallery-data .tabs-navigation .project-next');
  }

});
