$(document).ready(function() {$('#imgContainer').hide(); $('#thumbs').hide(); $('#thumbs_wrapper').hide(); $('#right').hide(); $('#left').hide(); });


var thumbsLength;
var imagesLoaded = 0;
var scene = null;
var galleryLoaded = false;


function strobeLoading()
{
    $('#loadingImg').animate({opacity: 'toggle'}, 1000, strobeLoading);
}

function imgClick(e)
{ 

 var box = $('#mainImg'); 

var src = 'resize/pic' + e.data.num + '.jpg';
if(src == box.attr('src'))
{

}


 var fadeTime = 2000; 
    $('<img src="loading.jpg" id="loadingImg"></img>').hide().appendTo('#loader');
strobeLoading();
 box.fadeOut(fadeTime, function() {box.load(function() {box.fadeIn(fadeTime); $('#loadingImg').stop().fadeOut('fast', function() {$('#loader').empty();}); }).attr('src', 'resize/pic' + e.data.num + '.jpg'); });
   
} 
   

   
 function thumbOver(e) 
 { 
 var thumb = e.target; 
 $(e.target).fadeTo(350, .5); 
 } 
   
 function thumbOut(e) 
 { 
 var thumb = e.target; 
 $(e.target).fadeTo(500, 1); 
 } 

 function fadeNav() 
 { 


 $('#nav').hide().load('vertNav2.html');
 var introImg = new Image();
 $(introImg).hide().load(function() {$('#content').append(this); $('#loadingImg').stop().fadeOut('fast', function() {$('#loader').empty();}); $('#nav').fadeIn(2000); $(this).fadeIn(2000);}).attr('src', 'resize/intro.jpg'); 

   
 } 
   

   
 function homeClick(e) 
 { 
 $('#splash').fadeOut(1000, fadeNav); 
    $('<img src="loading.jpg" id="loadingImg"></img>').hide().appendTo('#loader');
 strobeLoading();
 $('#home_icon').unbind('click'); 
   
   
 } 

function rightClick()
{
thumbsWidth = $('#thumbs').width();
thumbsLength = $('#thumbs_wrapper').width();
scrollLength = (thumbsLength - thumbsWidth) * -1;
scrollWidth = 74;
if($('#thumbs').position().left < 0 && !($('#thumbs').is(':animated')))
{
   $('#thumbs').animate({left: ($('#thumbs').position().left + scrollWidth)});
}

}

function leftClick()
{
thumbsLength = $('#thumbs').width();
thumbsWidth = $('#thumbs_wrapper').width();
scrollLength = (thumbsLength - thumbsWidth) * -1;
scrollWidth = 74;
if(scrollLength < ($('#thumbs').position().left) && !($('#thumbs').is(':animated')))
{
$('#thumbs').animate({left: $('#thumbs').position().left - 74}, 500);
}
}


function collectionsClick()
{
scene = 'gallery';



if(galleryLoaded)
{
$('#imgContainer').fadeIn(1000);
         $('#thumbs').fadeIn(1000);
         $('#thumbs_wrapper').fadeIn(1000);
          $('#right').fadeIn(1500);
          $('#left').fadeIn(1500);
$('#loadingImg').stop().fadeOut('fast', function() {$('#loader').empty();});
}



$('#left').bind('click', rightClick);
$('#right').bind('click', leftClick);



}


function contactClick() 
{    
scene = 'contact';
          $('#mainImg').attr('src', 'resize/pic1.jpg');
var img = new Image();
$(img).load(function() {$('#contact').hide().append(this);  $('#loadingImg').stop().fadeOut('fast', function() {$('#loader').empty();}); $('#contact').fadeIn(1000);}).attr('src', 'contact_info.jpg');

} 


   
function navClick(e)
{

if(scene == 'gallery')
{
     if(e.target.id == 'collections_nav')
     {
        
    }
    else
    {
          scene = 'contact';
          $('#thumbs').fadeOut(1000);
          $('#thumbs_wrapper').fadeOut(1000);
          $('#right').fadeOut(1000);
          $('#left').fadeOut(1000);
          $('#imgContainer').fadeOut(1000, contactClick);
          $('<img src="loading.jpg" id="loadingImg"></img>').hide().appendTo('#loader');
          strobeLoading();
    }
}
else if(scene == 'contact')
{
          if(e.target.id == 'collections_nav')
          {
               scene = 'gallery';
               $('#contact').fadeOut(1000, function() {$('#contact').empty(); collectionsClick();});
               $('<img src="loading.jpg" id="loadingImg"></img>').hide().appendTo('#loader');
               strobeLoading();
         }
         else
         {
              
         }
}
else
{
          if(e.target.id == 'collections_nav')
          {
               scene = 'gallery';
               $('#content').fadeOut(1000, collectionsClick);
               $('<img src="loading.jpg" id="loadingImg"></img>').hide().appendTo('#loader');
               strobeLoading();
         }
         else
         {
              scene = 'contact';
              $('#content').fadeOut(1000, contactClick);
              $('<img src="loading.jpg" id="loadingImg"></img>').hide().appendTo('#loader');
              strobeLoading();
         }
}


}



 $(window).load(function (){  
 var splashImg = new Image();
 $(splashImg).hide().load(function() {$('#splash').append(this); $(this).fadeIn(1000);}).attr('src', 'JohnBlasioli-TagLarge.jpg').bind('click', homeClick); 

   
 }); 




   
function galleryImgLoaded()
{

imagesLoaded++;
if(imagesLoaded >= 14)
{

for(var i = 1; i <= 13; i++)
{
$('#pic' + i).bind('click', {num:i}, imgClick).bind('mouseover', thumbOver).mouseout(thumbOut);

}
galleryLoaded = true;

}

}

   
