$(document).ready(function() {
	// Hack to make png work in ie < 7. Props to Drew McLellan
	$('#logo').supersleight({shim: 'images/Hood_Chefz_logo.gif'});
	$('#banner').supersleight({shim: 'images/Hood_Chefz_banner.gif'});
	
/*****************************************************************************/
/*************************** Chef Page ***************************************/
/*****************************************************************************/
	$('.chef_profile_box').hover(function() {
		$(this).find('span').css('color', '#990066');
	}, function() {
		$(this).find('span').css('color', '#0000ff');
	});

	$('.chef_profile_box').bind('click', function() {
		window.location = "?id=" + $(this).attr('ref');
	});
/*****************************************************************************/
/**************************** Store Page *************************************/
/*****************************************************************************/
	$('.store_category_box').bind('click', function() {
		window.location = "?category=" + $(this).attr('ref');
	});
	
	$('.store_item_link').bind('click', function() {
		window.location = "?item=" + $(this).attr('ref');
	});
/*****************************************************************************/
/**************************** Video Page *************************************/
/*****************************************************************************/
	$('.video_box').hover(function() {
		$(this).removeClass('bg_color_light').css('color', '#990066');
	}, function() {
		$(this).addClass('bg_color_light').css('color', '#0000ff');
	});

	$('.video_box').bind('click', function() {
		window.location = "?id=" + $(this).attr('id');
	});
/*****************************************************************************/
/************************* General *******************************************/
/*****************************************************************************/
  $('#nav_menu li').hover(function() {
		$(this).find('.nav_button_label').css('color', '#ffffff');
	}, function() {
		$(this).find('.nav_button_label').css('color', '#000000');
	});
	
	$('#nav_menu li').click(function() {
		$(this).siblings().children('a').removeClass('selected')
		$(this).children('a').addClass('selected');
	});

	$('.bodyLink').hover(function() {
		$(this).css('color', '#990066');
	}, function() {
		$(this).css('color', '#0000ff');
	});
	
	
/*****************************************************************************/
/******************************* Scrapbook ***********************************/	
/*****************************************************************************/	
	var currentPosition = 0;
  var scrapbookThumbImageWidth = 86;
  var scrapbookThumbImages = $('.scrapbook_thumb_img');
  var numberOfScrapbookImages = scrapbookThumbImages.length;
	
	show_scrapbook_group('scrapbook_0');

	$('.scrapbook_arrow').bind('click', function() {
		var oldPosition = currentPosition;
		
		// Determine position
		if($(this).attr('id') == 'next_arrow_img') {
			if((currentPosition + 4) < numberOfScrapbookImages) {
				currentPosition += 1;
			}
		} else {
			if(currentPosition > 0) {
				currentPosition -= 1;
			}
		}
		
		// Move scrapbook bar
		if(currentPosition != oldPosition) {
			$('#scrapbook_bar_ul').animate({'marginLeft' : scrapbookThumbImageWidth * (-currentPosition)});
		}
	});
	
	$('.scrapbook_thumb_a').bind('click', function() {
		show_scrapbook_group($(this).attr('id'));
	});
	

	$('.scrapbook_image').hover(function() {
		if(!$(this).siblings('div').hasClass('hovered')) { // reduce the odd effect caused when a person hovers and unhovers reperatedly fast
			$(this).siblings('div').addClass('hovered');
			if($(this).siblings('div').hasClass('displayed')) {
				// if description is displayed, remove displayed class
				$(this).siblings('div').removeClass('displayed');
			} else {
				// if description is NOT displayed, animate description up
				$(this).siblings('div').animate({bottom: 0}, 250);
			}
		}
	}, function() {
		window.setTimeout(remove_hovered_class, 250);
		$(this).siblings("div").animate({bottom: -20}, 250);
	});

}); // end jquery

/******************************************************************/
/****************** General Functions *****************************/
/******************************************************************/
function spaceout_elements() {
	$(".spaced_group").each(function() {
		$(this).children(".spaced_element:not(:last)").each(function() {
			$(this).css("height", $(this).height() + 10 + "px");
			var spaced_parents = $(this).parents(".spaced_element").not(".last");
			spaced_parents.css('height', spaced_parents.height() + 10 + 'px');
		});
	});
	
	$(".x_spaced_group").each(function() {
		$(this).children(".x_spaced_element:not(:last)").each(function() {
			$(this).css("width", $(this).width() + 10 + "px");
		});
	});
}
/******************************************************************/
/****************** Scrapbook Functions ***************************/
/******************************************************************/
var descriptionTimeout;

function show_scrapbook_group(groupName) {
	show_scrapbook_image(groupName + "_image");
	show_scrapbook_description(groupName + "_description");
	window.clearTimeout(descriptionTimeout);
	descriptionTimeout = window.setTimeout(hide_scrapbook_description, 2250);
}

function show_scrapbook_image(image) {
  $('.scrapbook_image').each(function() {
		if($(this).attr('id') == image) {
			// show correct image
			$(this).css('display', 'block');
		} else {
			// hide other images
			$(this).css('display', 'none');
		}
	});
}

function show_scrapbook_description(description) {
	$('.scrapbook_description').each(function() {
		if($(this).attr('id') == description) {
			// show the correct description
			$(this).css('display', 'block');
			$(this).addClass('displayed');
			$(this).animate({bottom: 0}, 250);
		} else {
			// hide any currently displayed descriptions
			$(this).css({'display' : 'none', 'bottom' : '-20px'});
			$(this).removeClass('displayed');
		}
	});
}

function hide_scrapbook_description() {
	$('.scrapbook_description').each(function() {
		// hide description after timeout and as long as image is not hovered
		if($(this).hasClass('displayed') && !$(this).hasClass('hovered')) {
			$(this).animate({bottom: -20}, 250);
			$(this).removeClass("displayed");
		}
	});
}

function remove_hovered_class() {
	$(".hovered").removeClass("hovered");
}

