var imageArray = [];
var counter = 1;
var prevcounter = 2;
var nextcounter = 0;
var windowWidth;
var imgCounter = 0;
var heightArray = [];

$(function(){
	$('body').append('<p id="loader">&nbsp;</p>');
	$('#photo img').hide();
	$('#meta_controls').hide();
	$("#goback").hide();
	$('#news').hide();
	$('.summary').hide();
	$('.description').hide();
	
	if (jQuery.browser.msie) {
	  if(parseInt(jQuery.browser.version) == 6) {
	    $.ifixpng('/images/pixel.gif');
		$('img[@src$=.png]').ifixpng();
	  }
	}

	$('body').css('overflow-y', 'auto');
	$('body').css('overflow-x', 'hidden');
	
});

	
window.onload = function(){	
							
			numImgs = $('#photo img').length;
			windowWidth = $(window).width();	
		
		$('#photo img').each(function(){

			currentImage = $(this);
			
			var imageHeight = currentImage.height();
			heightArray.push(imageHeight);
					
			if(imgCounter == 0){
					var imageObj = {};
					imageObj.image = currentImage;
					imageObj.imageWidth = currentImage.width();
					imageArray[0] = imageObj;
					imageArray.push(imageObj);
					
					imgCounter++;

					currentImage.css('top', '176px');
					currentImage.css('left', '189px');
					currentImage.css('position', 'absolute');
					currentImage.css('margin', '0');
					currentImage.show();
					$('.description').css({visibility: 'visible'});	
									
			}else if(imgCounter > 0){
				var imageObj = {};
				
				imageObj.image = currentImage;
				imageObj.imageWidth = currentImage.width();
				imageArray.push(imageObj);
				
				currentImage.css('position', 'absolute');
				currentImage.css('top', '176px');
				currentImage.css('left', -imageObj.imageWidth);
				currentImage.css('margin', '0');
				currentImage.show();
				$('.description').css({visibility: 'visible'});
				
				imgCounter++;
				
			}

		});	
		
		heightArray.sort();
		var biggestImage = heightArray.pop();	
		var descPos = biggestImage + 140;
		

		$('#meta_controls').show();
		$('.summary').show();   
		$("#goback").show();
		$('.description').show();
		$('#news').show();
		$('#loader').hide();
};


$(function(){
	
	jQuery.easing.def = "easeOutQuart";
	
	function animate(btnName){
		
		if(counter==imgCounter && btnName=='right'){
			counter=imgCounter;
			return;
		}
		if(counter==1 && btnName=='lefty'){
			counter=1;
			return;
		}
		
		if(btnName=='right'){
					currentImage = imageArray[counter].image;
					nextImage = imageArray[prevcounter].image;
					prevImage = imageArray[nextcounter].image;
			
					$(currentImage).animate({'left' : windowWidth}, 'easeOutQuart', HideIt );
					$(nextImage).animate({'left' : '290'}, 'easeOutQuart');
					
					counter++;
					prevcounter++;
					nextcounter++;
					
					$(".lil_img_holder span").each(function(){
						$(this).css({'background' : 'url(../pics/resources/black_file_icon.png)'});
					});
							
					$("span[name='" + counter + "']").css({'background' : 'url(../pics/resources/green_file_icon.gif)'});
					
			}
				
			if(btnName=='lefty'){
				
					$("span[name='" + counter + "']").css({'backgroundColor' : '#00BDF2'});
					currentImage = imageArray[counter].image;
					prevImage = imageArray[nextcounter].image;
					negWidth = imageArray[counter].imageWidth * -1;
					
					if(counter==1){
						counter=1;
						return;
					}else{
						$(currentImage).animate({'left' : negWidth}, 'easeOutQuart');
						ShowIt(prevImage);
						$(prevImage).animate({'left' : '189px'}, 'easeOutQuart');
						nextcounter--;
						counter--;
						prevcounter--;
						
						$(".lil_img_holder span").each(function(){
							$(this).css({'background' : 'url(../pics/resources/black_file_icon.png)'});
						});

						$("span[name='" + counter + "']").css({'background' : 'url(../pics/resources/green_file_icon.gif)'});
						
					}
					
					
			}
}
	
	$('a[name="left"]').click(function(){
			animate('lefty');
			return false;
	});
		
	$('a[name="right"]').click(function(){
			animate('right');
			return false;
	});	
	
	function HideIt(){
		$(this).hide();
	}		
	
	function ShowIt(img){
		$(img).show();
	}
	
	function AddThumbs(){
		var temp_counter = 1;
		$('#photo img').each(function(){
			$('.lil_img_holder').append("<span class='lil_img'" + "name='" + temp_counter +"'></span>");
			$('.lil_img_holder').addClass('clear');
			$('.lil_img').css({'background' : 'url(../pics/resources/black_file_icon.png)'})
			temp_counter++;
		});
		
		$("span[name='" + counter + "']").css({'background' : 'url(../pics/resources/green_file_icon.gif)'});
	}
	
	AddThumbs();
	
	
});


$(function(){
	
	$('a.thumbnail').hover(
		function(){		
			$(this).animate({"borderTopColor" : '#6CF538', "borderRightColor" : '#6CF538', "borderBottomColor" : '#6CF538', "borderLeftColor" : '#6CF538'}, 200).find('img').animate({'backgroundColor' : '#eee'});
		},
		function(){
			$(this).animate({"borderLeftColor" : '#000000', "borderTopColor" : '#000000', "borderRightColor" : '#000000', "borderBottomColor" : '#000000'}, 130).find('img').animate({'backgroundColor' : '#ffffff'});
		}
	);
});

window.onresize = function(){
	windowWidth = $(window).width();	
}



