/* GLOBALS */
var trading = false;
var goingToFrontLeft;
var goingToFrontTop;
var goingToFrontWidth;
var goingToFrontHeight;
var oldClass = "medium";

var emptyX = 600;
var emptyY = 400;

function getAct(thumb) {
	var clazz = toplessClass($(thumb).attr('class'));
	if (typeof(style_size[clazz]) == 'undefined') imageSizes(thumb);
	if (typeof(style_size[clazz].act) == 'undefined') style_size[$(thumb).attr('class')].act = '';
	return(style_size[clazz].act);
}
function setAct(thumb, value) {
	var clazz = toplessClass($(thumb).attr('class'));
	if (typeof(style_size[clazz]) == 'undefined') imageSizes(thumb);
	style_size[clazz].act = value;
	return;
}

function lightUp(image) {
	if (trading) return;
	$(image).stop().animate({ 'opacity': 1 }, 250);
}
function lightDown(image) {
	if (trading) return;
	$(image).stop().animate({ 'opacity': 0.4 }, 250);
}

function setGallery() {

	$("#canvas img").click(function(){
	
//		if ($(this).attr('id') == "clr") {
		if ($(this).attr('id') == "clr" || $(this).attr('id') == "moreimage") {
			return true;
		}
		
		// You can't swap images if a swap is in progress (trading) or if the image is already the featured image
		if (trading || $(this).hasClass('featuredImage')) return;
		
		var newImage = this;
		
		trading = true;
		goingToFrontLeft = $(this).css('left');
		goingToFrontTop = $(this).css('top');
		goingToFrontWidth = $(this).css('width');
		goingToFrontHeight = $(this).css('height');
		var text = $(this).attr('rel');

//		$('.spotlight').stop().animate({ 'opacity': 1 }, 0).hide();
		$('.featuredImage').stop().animate({
			height: goingToFrontHeight,
			width: goingToFrontWidth,
			left: goingToFrontLeft,
			top: goingToFrontTop
		}, 500, function(){
			$(this).attr('class', '').addClass(oldClass);
			$(this).animate({ 'opacity': 0.4 }, 250);
			
		});

		// save the old class
		oldClass = $(newImage).attr('class');
		
		$(newImage).stop().addClass('top').animate({ 'opacity': 1 }, 0).animate({
			height: '502px',
			width: '771px',
			left: '112px',
			top: '0px'
		}, 500, function(){
			$(newImage).attr('class', '').addClass('featuredImage');
//				$('.spotlight').fadeIn('slow');
			$('.description').html(text);
			$('#homemore a').attr("href", text)
			trading = false;
			
		});

	});
	
	/* Portfolio thumbs should light up on hover */
	$('#canvas img').live('mouseover',function(){ 
		lightUp(this); 
	});
	$('#canvas img').live('mouseout',function(){ 
		lightDown(this); 
	});
	$('#homemore img').live('mouseover',function(){ 
		lightUp(this); 
	});
	$('#homemore img').live('mouseout',function(){ 
		lightUp(this); 
	});
	
	/* Don't let the featured image change opacity */
	$('#canvas img.featuredImage').live('mouseover',function(){ 
		lightUp(this); 
	});
	$('#canvas img.featuredImage').live('mouseout',function(){ 
		lightUp(this); 
	});
}


/* Button for more on home page slides */
var slide_min = 250;
var slide_max = 325;

//$(function() {
function addMoreButton() {
	$('#canvasholder').hover(function() {
		$('#homemore').stop().animate({
			height: 27
		}, 500, function(){
			
		});

	}, function() {
		$('#homemore').stop().animate({
			height: 0
		}, 500, function(){
		
		});

	});
	
	$('#homemore').hover(function() {
		$('#homemore').stop().animate({
			height: 27
		}, 500, function(){
			
		});

	}, function() {
		$('#homemore').stop().animate({
			height: 0
		}, 500, function(){
		
		});
	
	});
}
//});


/* Execute jQuery */
$(document).ready(function() {
	setGallery();
	addMoreButton();
});

