function Showcase() {
	this.compareUrl = "compare.html?compare=";
	this.excessCardsRight = new Array();
	this.excessCardsLeft = new Array();
	this.pageSize = 7;
	this.maxCards = 7;
	
	/**
	* Searches through an unordered array to see if a value is present
	*
	*/
	this.inArray = function (needle,haystack) {
		var exists = false;
		if(typeof(haystack) == 'string') {
			eval('haystack = ['+haystack+'];');
		}
		$.each(haystack,function(i,n) {
			if(n==needle) {
				exists = true;
			}
		});
		return exists;
	}
	
	/**
	* Modifies the compare form to reflect the correct cards to compare
	*
	*/
	this.modifyCompareData = function (cardIdList) {
		$('#compareCardIds').attr('value',cardIdList);
	}
	
	this.initCardOverflowButtons = function() {
		if($('#cardOverflow').children().size() > 0) {
			$.each($('#cardOverflow .showcaseFisheyeItem'), function(n) {
				showcase.excessCardsRight[showcase.excessCardsRight.length] = $(this).attr('id').substring(5);
				showcase.moveCardIntoBank($(this));
			});
			$('.moreCardsRight').addClass('moreCardsRightActive');
			$('.moreCardsRight').click(function () {
				showcase.pageCards(1);
			});
		}
	}
	
	
	/**
	* Resets the more cards buttons
	*
	*/
	this.resetCardOverflowButtons = function() {
		if(showcase.excessCardsRight.length > 0) {
			$('.moreCardsRight').addClass('moreCardsRightActive');
			$('.moreCardsRight').unbind('click');
			$('.moreCardsRight').click(function () {
				showcase.pageCards(1);
			});
		} else {
			$('.moreCardsRight').removeClass('moreCardsRightActive');
			$('.moreCardsRight').unbind('click');
		}
		if(showcase.excessCardsLeft.length > 0) {
			$('.moreCardsLeft').addClass('moreCardsLeftActive');
			$('.moreCardsLeft').unbind('click');
			$('.moreCardsLeft').click(function () {
				showcase.pageCards(-1);
			});
		} else {
			$('.moreCardsLeft').removeClass('moreCardsLeftActive');
			$('.moreCardsLeft').unbind('click');
		}
	}
	
	/**
	* Puts cards from the excess cards arrays into the display
	*
	*/
	this.pageCards = function(direction) {
		if(direction > 0) {
			if(showcase.excessCardsRight.length > 0) {
				//scrolls cards right
				for(i = 0; i < showcase.pageSize && i < showcase.excessCardsRight.length; i++) {
					card = $('#visibleCards').children().slice(0,1);
					showcase.excessCardsLeft[showcase.excessCardsLeft.length] = card.attr('id').substring(5);
					showcase.moveCardIntoBank(card, false);
				}
				
				totalToMove = showcase.excessCardsRight.length;
				for(i = 0; i < showcase.pageSize && i < totalToMove; i++) {
					var cardID = showcase.excessCardsRight.shift();
					if(cardID) {
						showcase.moveCardIntoDisplay($('#card_'+cardID),false);
					}
				}
			}
		} else {
			//scroll cards left
			if(showcase.excessCardsLeft.length > 0) {
				for(i = 0; i < showcase.pageSize && i < showcase.excessCardsLeft.length; i++) {
					sliceStart = $('#visibleCards').children().size() -1;
					card = $('#visibleCards').children().slice(sliceStart,sliceStart+1);
					showcase.excessCardsRight.unshift(card.attr('id').substring(5));
					showcase.moveCardIntoBank(card);
				}
				totalToMove = showcase.excessCardsLeft.length;
				for(i = 0; i < showcase.pageSize && i < totalToMove; i++) {
					cardID = showcase.excessCardsLeft[showcase.excessCardsLeft.length - 1];
					if(cardID) {
						showcase.moveCardIntoDisplay($('#card_'+cardID),true);
						showcase.excessCardsLeft[showcase.excessCardsLeft.length - 1] = null;
						showcase.excessCardsLeft.length--;
					}
				}
			}
		}
		showcase.unbindFisheyeEvents();
		showcase.initFisheye();
		showcase.resetCardOverflowButtons();
		showcase.initCardHover();
	}
	
	
	
	/**
	* Sets up the fisheye menu
	*
	*/
	this.initFisheye = function() {
		// hide spans
		$('.showcaseFishEyeMenu span').css('display','none');
	
			$('#cardImageHolder').Fisheye(
					{
						itemWidth: 80,
						maxWidth: 20,
						items: 'a',
						itemsText: 'span',
						container: '.showcaseFishEyeMenu',
						proximity: 50,
						halign : 'center'
					}
				);	
		
		// set the pageSize and maxCards based on thr actual number of cards in the base page
		showcase.pageSize = $("#visibleCards a.showcaseFisheyeItem").length;
	}
	
	/**
	* Unbinds the events bound by the fisheye menu
	*/
	this.unbindFisheyeEvents = function() {
		$(document).unbind();
		$('#cardImageHolder').children().unbind();
		$('#showcaseFisheyeItem').children().unbind();
	}
	
	/**
	* Undoes the action of the FishEye init
	*/
	this.unInitFisheye = function() {
		$('.showcaseFishEyeMenu a').css('width', '150px');
		//$('.showcaseFishEyeMenu a').css('left', 'auto');
		$('.showcaseFishEyeMenu a span').css('display', 'block');
		$('.showcaseFishEyeMenu a').unbind();
		this.unbindFisheyeEvents();
	}
		
	/**
	* Moves the card from the display area into the card bank
	*
	*/
	this.moveCardIntoBank = function(card,prepend) {
		clone = card.clone(true);
		card.remove();
		if(prepend) {
			clone.prependTo('#cardBank');
		} else {
			clone.appendTo('#cardBank');
 		}
	}
	
	/**
	* Moves the card from the display area into the card bank
	*
	*/
	this.moveCardIntoDisplay = function(card,prepend) {
		clone = card.clone(true);
		card.remove();
		if(prepend) {
			clone.prependTo('#visibleCards');
		} else {
			clone.appendTo('#visibleCards');
		}
	}
	
	/**
	* Initialises the finder filter application
	*
	*/
	this.finderFilterInit = function () {
		//setting up the click events on the filter buttons
		$(".filterButton").click(function() {
			var rel = $(this).find('a').attr('rel');
			if(rel) {
				var relParts = rel.split("|");
				$.each(relParts,function(i,n) {
					if(n) {
						if(n.substring(0,5) == 'cards') {
							showcase.excessCardsLeft = new Array();
							showcase.excessCardsRight = new Array();
							cardNumbers = n.substring(6);
							cardNumberArray = cardNumbers.split(',');
							
							//Move all cards out of the display
							$("#visibleCards a").each(function(i) {
								showcase.moveCardIntoBank($(this));
							});
							
							//Move cards into the display area
							for(j = 0;j < cardNumberArray.length && j < showcase.maxCards; j++) {
								showcase.moveCardIntoDisplay($('#card_'+cardNumberArray[j]));
							}
							//Put extra cards into the excess array
							for(j = cardNumberArray.length; j > showcase.maxCards; j--) {
								showcase.excessCardsRight.unshift(cardNumberArray[j-1]);
							}

							//Modifying the cards to compare
							showcase.modifyCompareData(cardNumbers);
							//reinitialises the fisheye using the current items
							showcase.unbindFisheyeEvents();
							showcase.initFisheye();
							//reinitialise the hover
							showcase.initCardHover();
							showcase.resetCardOverflowButtons();
						} else {
							//Displays and hides sections
							var nodeInfo = n.split(':');
							var cssClass = (nodeInfo[1]);
							var nodeIdInfoParts = nodeInfo[0].split('_');
							$('.'+nodeIdInfoParts).addClass(cssClass);
							$('#'+nodeInfo[0]).removeClass(cssClass);
						}
					}
				});
			}
		});
	}
	
	
	/**
	* Initialises the event handlers for the hover event
	*
	*/
	this.initCardHover = function () {
		//$('#visibleCards .showcaseFisheyeItem').unbind();
		$('#visibleCards .showcaseFisheyeItem').hover(function () {
			showcase.cardHoverIn($(this));
		},
		function() {
			showcase.cardHoverOut($(this));
		});
	}
	
	/**
	* Defines what is done when the mouseover event is triggered on the card
	*
	*/
	this.cardHoverIn = function(object) {
		cardID = object.attr('id').substring(5);
		//Displaying the card description
		$('#cardDescription_'+cardID).css('display','block');
//		showcase.fadeSiblings(object);
	}
	
	/**
	* Defines what is done when the mouseout event is triggered on the card
	*
	*/
	this.cardHoverOut = function(object) {
		cardID = object.attr('id').substring(5);
		//hiding the card description
		$('#cardDescription_'+cardID).css('display','none');
//		showcase.removeSiblingFade(object);
	}
	
	/**
	* Puts opacity on the object's siblings
	*
	*/
	this.fadeSiblings = function(object) {
		object.siblings().addClass('cardFader');
	}
	
	/**
	* Removes the opacity from the object's siblings
	*
	*/
	this.removeSiblingFade = function(object) {
		object.siblings().removeClass('cardFader');
	}
	
	/**
	* The sIFR replace function
	*
	*/
}

