/*
* BCDC.US - simple image showcase jQuery plugin
* Examples and documentation at: http://bcdc.us
* Version: 1.0 ( Nov-25-2009 )
* Copyright (c) 2009 Bruno Correia
* Requires: jQuery v1.3+
* Demo at http://bcdc.us/jquery.plugins/jquery.showcase/demo.html
*/


(function($) {
	$.fn.showcase = function(customOptions) {
				var options = $.extend({},$.fn.showcase.defaultOptions, customOptions);

				if ( options.openingImage == 'random' ) {
				var n = $(this).parent().nextAll().length+1; // return the total amount of items
				//options.openingImage = Math.floor( Math.random() * n + 1 );
				options.openingImage = $('body ul.showcase li a').eq(0);
				alert(options.openingImage.attr("href"));
			}
				
				if ( $('#showcase img').length == 0 ) {
				$('#showcase').append('<img src="' + options.imagePath + '/' + options.openingImage + '.' + options.imageExtension + '" alt="" />');
				$('#showcase img').css({'display':'none'});
				}

				var $current = $('body').find('ul.showcase li a').eq(options.openingImage-1);
						$current.addClass('current');
						
				var $showcase = $('#showcase img');
				if ( options.imageCaptions == true ) {
				$('#showcase').after('<div id="captions"></div>');
				$("#captions").text( $current.attr('rel') );
				}
								
				if ( options.pageLink == true ) {
				$showcase.wrap('<a href="' + $current.attr('href') + '" alt=""></a>');
				}
				
				$showcase.load(function() {
				$(this).fadeIn(options.fadeInSpeed);
			
				
				});

				$(this).click(function(event) {
//$('#showcaseWrapper').css("background-color", "#ffffff");	
$('#showcaseWrapper').css("background-image", "none");	
				event.preventDefault();
					var $showcase = $('#showcase img');
					var requested = $(this).attr("href"); // return eq position

					if ( $(this).hasClass('current') == false ) {
						 $showcase.fadeOut(options.fadeOutSpeed, function() {
						 $showcase.attr({ src: options.imagePath + '/' + requested + '.' + options.imageExtension })
							 .load(function() { $showcase.hide().fadeIn(options.fadeInSpeed);
							 });
						 });
						 if ( options.pageLink == true ) {
								$('#showcase a').attr('href', $(this).attr('href') );
						 }
						 if ( options.imageCaptions == true ) {
								$('#captions').html( $(this).attr('rel'));
//testing here
//$('#captions').text( $(this).parent.p);
						 }
						 $('ul.showcase li a').removeClass('current');
						 $(this).addClass('current');
					}
				});
	};

		$.fn.showcase.defaultOptions = {
		imagePath: '../products',
		imageExtension: 'jpg',
		imageCaptions: true,
		openingImage: '1', // may use 'random'
		pageLink: true,
		fadeInSpeed: 600,
		fadeOutSpeed: 700
		};

})(jQuery);
