$(document).ready(function(){

$(".nojs").hide();
$(".slideControl").show();

$(".sl1conbox").css({"height":"180px"});
$("#sl1container, #sl1container2").css({"height":"170px","overflow":"hidden"});
$("#sl1slidesbox, #sl1slidesbox2").css({"height":"170px","width":"8760px"});
$(".sl1box").css({"height":"170px"});
$("ul.sl1").css({"height":"170px","width":"auto"});

$(".hidden").hide();
$("#kenLink").colorbox({width:"660px", inline:true, href:"#ken"});
$("#erinLink").colorbox({width:"660px", inline:true, href:"#erin"});
$(".whatLink").colorbox({width:"660px", inline:true, href:"#what"});
$("#title").colorbox({width:"660px", inline:true, href:"#bpp"});

$(".whyLink").colorbox({width:"660px", inline:true, href:"#why"});
$(".faqLink").colorbox({width:"660px", inline:true, href:"#faqs"});
$(".processLink").colorbox({width:"660px", inline:true, href:"#process"});
$(".blogLink").colorbox({width:"660px", inline:true, href:"#blog"});

$(".revLink").colorbox({width:"660px", inline:true, href:"#rev"});

$(".contactLink").colorbox({width:"660px", height:"80%", iframe:true});


/*
$("#page").css({'background-image':'url(/img/logo3.png)'});

$("#info").hover(
  function () {
    if(!EGG1ON) {
      $("#page").css({'background-image':'url(/img/bling3.gif)'});
    }
  },
  function () {
    if(!EGG1ON) {
      $("#page").css({'background-image':'url(/img/logo3.png)'});
    }
  }
);
*/



function startWaves() {

    if($.browser.msie){

    } else {

      $("html.bgwater #inner").animate({backgroundPosition: '(-30px 400px)'}, 1000)
                   .animate({backgroundPosition: '(-20px 390px)'}, 1000)
                   .animate({backgroundPosition: '(-30px 390px)'}, 1000)
                   .animate({backgroundPosition: '(-40px 400px)'}, 1000, function(){startWaves();});

    }


}

var EGG1ON = false;

$("#waterlink").click(function () {

  if(!EGG1ON) {
    //$('html').removeClass('bgshell').addClass('bgwater');
    $('html').addClass('bgwater');
    $("#page").css({'background-image':'url(/img/logo_sand.png)'});
    $('#inner').prepend('<div id="fishy"></div>');
    $('#fishy').animate({
        opacity: 0.95,
        right: '+=1800',
        top: '+=140px'
      }, 14000, function() {
        $('#inner').find("#fishy").fadeOut('slow');
    });
    startWaves();
    EGG1ON = true;
  } else {
    $('html').removeClass('bgwater');
    $("#page").css({'background-image':'url(/img/logo3.png)'});
    $("#inner").stop(true);
    $('#inner').find("#fishy").remove();
    EGG1ON = false;
  }
  return false;
});

$("#nautilislink").click(function () {
  $('html').removeClass('bgwater').addClass('bgshell');
  $('#inner').find("#fishy").remove();
  $("#inner").stop(true);
  return false;
});

$("#defaultlink").click(function () {
  $('html').removeClass('bgwater').removeClass('bgshell');
  $("#inner").stop(true);
  $('#inner').find("#fishy").remove();
  return false;
});



$("#randlink").click(function () {

    var numofselections = 2;
    var n=Math.floor(Math.random()*numofselections);

    switch(n) {
      case 0:
        $('#page').removeClass('photo');
        $('body').addClass('water');
        $('#inner').addClass('go');
        startWaves();
        break;
      case 1:
        $('body').removeClass('water');
        $('#inner').removeClass('go');
        $('#page').addClass('photo');
        break;
      default:
         break;
    }

    return false;
});


$(window).load(function () {});



$("#kenLink").hover(
  function () {
    $("#names").css({"backgroundPosition":"0 -340px"});
  },
  function () {
    $("#names").css({"backgroundPosition":"0 0"});
  }
);

$("#erinLink").hover(
  function () {
    $("#names").css({"backgroundPosition":"0 -170px"});
  },
  function () {
    $("#names").css({"backgroundPosition":"0 0"});
  }
);



/* Slides
---------------------------------------------- */

  var numSets = 2;

  $("#sl1slidesbox, #sl1slidesbox2").css({'left':'0px'});
  $("#goleft, #goleft2").hide();

  var gboxwidth = 804;  // == to ul.sl1 + 14px
  var rtFadeSet = (numSets-2)*gboxwidth;
  var lastSet =  numSets*gboxwidth;
  var currbox = 0;
  var currbox2 = 0;


  $("#goleft").click(function () {
    if( $("#goright").css('display') == 'none') {$("#goright").fadeIn();}
    if(currbox == gboxwidth) {$("#goleft").fadeOut();}

    if(currbox != 0) {
      var newLeft = currbox-gboxwidth;
    } else {
      var newLeft = currbox;
    }
    var thisleft = "-"+newLeft+"px";
    $("#sl1slidesbox").animate({left: thisleft}, 1000, "easeinout");
    currbox = newLeft;
    return false;
  });
  
  $("#goleft2").click(function () {
    if( $("#goright2").css('display') == 'none') {$("#goright2").fadeIn();}
    if(currbox2 == gboxwidth) {$("#goleft2").fadeOut();}

    if(currbox2 != 0) {
      var newLeft = currbox2-gboxwidth;
    } else {
      var newLeft = currbox2;
    }
    var thisleft = "-"+newLeft+"px";
    $("#sl1slidesbox2").animate({left: thisleft}, 1000, "easeinout");
    currbox2 = newLeft;
    return false;
  });

  $("#goright").click(function () {
    
    // to accomodate safari, we have to call this each time
    if($.browser.safari) {
      $("#goleft").show();
    } else {
      $("#goleft").fadeIn();
    }

    if(currbox == rtFadeSet) {$("#goright").fadeOut();}

    if(currbox != lastSet) {
      var newLeft = currbox+gboxwidth;
    } else {
      var newLeft = currbox;
    }
    var thisleft = "-"+newLeft+"px";
    $("#sl1slidesbox").animate({left: thisleft}, 1000, "easeinout", function () {
        // safari does not like the callback or the if stmt
        //if( $("#goleft").css('display') == 'none') {$("#goleft").fadeIn();}
    });


    currbox = newLeft;
    return false;
  });
  
  $("#goright2").click(function () {
    
    // to accomodate safari, we have to call this each time
    if($.browser.safari) {
      $("#goleft2").show();
    } else {
      $("#goleft2").fadeIn();
    }

    if(currbox2 == rtFadeSet) {$("#goright2").fadeOut();}

    if(currbox2 != lastSet) {
      var newLeft = currbox2+gboxwidth;
    } else {
      var newLeft = currbox2;
    }
    var thisleft = "-"+newLeft+"px";
    $("#sl1slidesbox2").animate({left: thisleft}, 1000, "easeinout", function () {
        // safari does not like the callback or the if stmt
        //if( $("#goleft").css('display') == 'none') {$("#goleft").fadeIn();}
    });

    currbox2 = newLeft;
    return false;
  });

  /* replace portfolio thumb titles */
  $('.special :last-child').each(function(index) {

    var message = $(this).parent().attr('title');
    $(this).after('<div class="upslide"><span>'+message+'</span></div>');
    
    $(this).parent().removeAttr('title');


  });

  $('.upslide').hide();

  $('.special').hover(
    function () {

      var thisMsg = $(this).children('div.upslide');

      $(thisMsg).stop(true, true).animate({
          height: "80px"
      }, 100 );
      
      if($(this).hasClass('comingsoon')) {
        // don't add the onclick
         $(this).children('div.upslide').css('cursor','default');
      } else {
        $(this).children('div.upslide').click(function () {
          var togo=$(this).siblings('a').attr('href');
          window.open(togo,'new');
          return false;
        });
      }

    },
    function () {

      $('.upslide').stop(true, true).animate({
          height: "0px"
       }, 100 );
       
       $(this).children('div.upslide').unbind();

    }
  );
  
  /*
  $("").click(function () {

    return false;
  });
  */

});
