/*
By Adam Khan (adam@engaging.net)
*/

$(document).ready(function()
{
	
	$("img.showcase").lazyload(
	{
		container: $("#slider"),
		failurelimit : 100,
		threshold : 200
	});
	
	$(".thumb").click(function()
	{
		// Fade thumb, unfade others
		$(".thumb").stop().fadeTo(500,1);
		$(this).stop().fadeTo(500,0.3);

		// Get data
		id_array = $(this).attr('id').split("-");
		entry_id = id_array[0];
		photos_border_color = $(this).next().text();
		photos_shape = $(this).next().next().text();
		photos_darken = $(this).next().next().next().text();

		// Change site CSS
		$('h1 a, .welcome-text a, #footer a').css('color', '#' + photos_border_color);
		$('h2, #latmag').css('background-color', '#' + photos_border_color);
		$('#showcase, .thumb').css('border-color', '#' + photos_border_color);
		if ( photos_shape == "Horizontal" ) { $('#showcase-holder').css('height', '330px'); }
		if ( photos_shape == "Vertical" ) { $('#showcase-holder').css('height', '563px'); }
		$('h2').css('color', '#fff');
		if ( photos_darken == "Yes" ) { $('h2, #latmag, #slider, h1 a, h2 a, #latmag a, .welcome-text a, #footer a').css('color', '#333333'); }

		// Switch showcase image
		selected_showcase = $("#" + entry_id + "-showcase").attr("src");
		$("#showcase").fadeTo('125', 0.8).stop(true, true).attr("src", selected_showcase).fadeTo('500', 1);

		// Switch showcase caption
		selected_caption = $("#" + entry_id + "-caption").html();
		$("#caption").fadeIn().html(selected_caption);
	});
	
	/* Accordions http://bassistance.de/jquery-plugins/jquery-plugin-accordion/ */

	var hoverConfig = 
	{    
	     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
	     interval: 500, // number = milliseconds for onMouseOver polling interval    
	     over: function(){}, // function = onMouseOver callback (REQUIRED)    
	     timeout: 500, // number = milliseconds delay before onMouseOut    
	     out: function(){} // function = onMouseOut callback (REQUIRED)    
	};
		
	jQuery('#gutter').accordion(
	{
		autoheight: false,
		alwaysOpen: false, 
	    active: '.selected', 
	    selectedClass: 'active',
		header: ".handles" 
	});

	jQuery('#sidebar').accordion(
	{
		autoheight: false,
		alwaysOpen: false, 
	    active: '.selected', 
	    selectedClass: 'active',
		header: ".handle" 
	});

	/* Cycle 
	http://malsup.com/jquery/cycle/
	*/



	$('.lightbox').lightBox(
	{
		fixedNavigation: true, 
		imageLoading: 'http://www.adamkhan.net/images/lightbox-btn-loading.gif',
		imageBtnClose: 'http://www.adamkhan.net/images/lightbox-btn-close.gif',
		imageBtnPrev: 'http://www.adamkhan.net/images/lightbox-btn-prev.gif',
		imageBtnNext: 'http://www.adamkhan.net/images/lightbox-btn-next.gif',
		txtImage: 'Photo'
	});

});

function jumpMenu(targ,selObj,restore)  //v3.0 via subtraction.com
{
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}
