/******************************************************************************** 
 * Copyright © 2010 Ignition Interactive. All Rights Reserved.  				*
 * Programmer: Codin Pangell  / codin[at]evoke.la    			 				*
 *                                           									*
 * NOTE: Requires jQuery.                    									*
 * Feel free to use this source. Just please notify us and give me credibility. *
 ********************************************************************************
/								                                              */


//-----------------
// GET THIS PARTY STARTED
//-----------------			
$(document).ready(function(){
	
	//import snazzier fonts
	Cufon.replace('.innerWrapper p', { fontFamily: 'Helvetica Neue LT Std' });
	Cufon.replace('.rightCol h2', { fontFamily: 'Helvetica Neue LT Std' });

	
	$('.collection li').click(function(){
		loadDetail($(this).find('img').attr('rel'));
	});
	
	$('.mainImageItem').click(function(){
		var _tmp=$(this).attr('src');
		
		_tmp=_tmp.split("_thumb").join("");
		$('.blockScreenDetail2').fadeTo(250, 0.6);
		$('.blockScreenDetail2').css('display','block');

		scrollToTop();
		
		
		$('.largeImage').attr('src',_tmp);
		if (_tmp.indexOf("AW24.jpg")>0){
			//96px difference
			$('#detailContainerLarge').height('689px');
			$('.closebutton img').css('top','672px');
		}else{
			$('#detailContainerLarge').height('785px');
			$('.closebutton img').css('top','768px');
		}
		
		$('#detailContainerLarge').fadeIn(500, function(){
			determineBG_Height();
		});
	});
	
	//preload big images
	preLoader();
	
});
function preLoader(){
	//--kick this off with preloading our images.
	var cyclerLoaded = false;
	var numberOfPreloaded = 0;
	function imageLoaded(){      
		numberOfPreloaded++;
		if (numberOfPreloaded >= 3 && !cyclerLoaded){
			cyclerLoaded = true;
		}
	}
	$('img.preload').each(function(){
		var image = new Image();
		image.src = $(this).attr('src');
		if (image.complete){     
			imageLoaded();        
		}else{       
			image.onload = imageLoaded;
		}
	});	
}
function closeDetail(){
	$('.blockScreenDetail').fadeOut(500);
	$('.blockScreenDetail2').fadeOut(500);
	$('#detailHolder').fadeOut(500);
	$('#detailContainer').fadeOut(500);
	$('#detailContainer').html('');
	$('#detailContainerLarge').fadeOut(500);
}
function loadDetail(item){

	$('#detailContainer').html('');
	$('.blockScreenDetail2').fadeTo(250, 0.6);
	$('.blockScreenDetail2').css('display','block');
	$('#detailContainer').html('<img src="images/'+item+'" style="border:7px solid #0C0C0C;" />');
	$('#detailContainer').fadeIn(500, function(){
		$('#detailHolder').css('display','block');
		determineBG_Height();
	});
	
	scrollToTop();

	
}
function determineBG_Height(){
	//This is a hack to determine the height of the webpage and set the BG to 100% of the page. FF doesn't like the CSS that does it.
	$('.blockScreenDetail').height(($(document).height()+10)+'px');
}
function scrollToTop(){
	$('body').animate({scrollTop:0}, 'slow');
	$('html').animate({scrollTop:0}, 'slow');
	$('html, body').animate({scrollTop:0}, 'slow'); 
}
function notop(){}
