//initial function for centering image
function center() {
$('.piece').each(function () {
  var high = $(this).height();
  var wit = $(this).width();
  var witdif = 960 - wit;
  var dif = 520 - high;
  var valy = dif / 2;
  var witval = witdif / 2;
  if(high < 520)
  {
  $(this).css({marginTop:valy+"px", marginBottom:valy+"px"});
  }
  if(wit < 960)
  {
  $(this).css({marginLeft:witval+"px"});
  $(this).next().css({marginLeft:witval+"px"});
  }


  	
});

}

 $(window).load(function () {
 	
 	
 	
 	
 //rollover for thumbs 
 $('.thumby').children().children('img').css({opacity:"0.7"});
	
    $(".thumby").hover(
      function () {
        $(this).children().children('img').animate({opacity:"1.0"}, 500);
      }, 
      function () {
         $(this).children().children('img').animate({opacity:"0.7"}, 500);
      }
    );
    
    
    
    //rollover for thumbs 
 $(".blam").css({opacity:"0.6"});
	
    $(".blam").hover(
      function () {
        $(this).animate({opacity:"2.0"}, 500);
      }, 
      function () {
         $(this).animate({opacity:"0.6"}, 500);
      }
    );







 	

 //centering the images in the gallery
  center();
  
 //dealing with slow load of centering 
$("#container").css({visibility:'visible'});


});

 $(document).ready(function(){
 	
 	



 
  	
 	//making scroller open and close
 	$("#collect").click(function () {
	$("#bigger").animate({top:'75%'}, { easing:'easIn' });
});

 	
 	
 	$("#gallery").click(function() {
 	$("#bigger").animate({top:'100%'},{easing:'easeIn' });
 	});
 
 
 	//making thumbs react to click
 	$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
    $(pager).find('li').click(function () { 
      $("#bigger").animate({top:'100%'},{easing:'easeIn' });
   
    });       
}; 

//initializing gallery
$('#gallery').cycle({ 
    fx:     'fade', 
    speed:  'slow', 
    pager:  '#thumbBox', 
    next:   '#next', 
    prev:   '#prev' ,
     
   

     
    // callback fn that creates a thumbnail to use as pager anchor 
    pagerAnchorBuilder: function(idx, slide) { 
 blim =  $(slide).find('img').attr('src');
        return '<li class="thumby"  style="position:relative; width:95px; height:95px;" ><a href="#"><img src="' + blim + '" width="95" height="95" /></a></li>'; 
       
    } 
    


    

});


//calculating width for scroller
var width = 0;
$('.thumby').each(function() {
    width += $(this).outerWidth( true );
});
$('#thumbBox').css('width', width);


 	  

$("#worky").click(function() {
	$("#mainNav").fadeIn();
	
});


 });



