//***********************************************
// Title: fGrow - jQuery Plugin
// Author: Mark Appleby
// Current Version: 1.4
// Last Edited: Thur, Jan, 7, 2010
// Last Changes: Adjustable Columns
//
// All Right Reserved
// Please do not alter this plugin without the
// author's permission
//***********************************************

$.fn.fGrow = function(options){

    var defaults = { 
		fDimensions:75,
		fStartDimensions:100,
		fSpeed:200,
		fSpacing:10,
		fColumns:5,
		fBorder:true,
		fOpacity:1
	}; 
	
	var options = $.extend(defaults, options);
	
	$('div.fGrow')
	.css('overflow','hidden')
	.css('width',options.fDimensions)
	.css('height',options.fDimensions)
	.css('cursor','pointer')
	.css('position','absolute')
	.css('left',0)
	.css('top',0)
	.css('margin-top',options.fSpacing)
	.css('margin-left',options.fSpacing);
	
	if(options.fTotal==undefined){
		alert('Please define the total number of thumbnails');	
	}
	
	yShift=0;
	xShift=0;
	columnCount=0;
	for(i=1; i<=options.fTotal; i++){
		x=options.fDimensions+options.fSpacing;
		y=options.fDimensions+options.fSpacing;
		if(columnCount==options.fColumns){
			yShift++;
			xShift=0;
			columnCount=0;
		}
		$('div.fGrow#'+i).css('left',x*xShift).css('top',y*yShift);
		xShift++;
		columnCount++;
	}
	
	if(options.fBorder==true){
		$('div.fGrow')
		.css('border-color','white')
		.css('border-style','solid')
		.css('border-width',1);
	}
	
	current=0;
	
	active=new Array();
	for(i=1;i<=options.fTotal;i++){
		active[i]=true;
	}
	
	$('div.fGrow').mouseover(function(){
		if(active[this.id]==true){
			active[this.id]=false;
			$('div.fGrow#'+current).animate({"width":options.fDimensions,"height":options.fDimensions, "marginLeft":0+options.fSpacing,"marginTop":0+options.fSpacing},options.fSpeed,function(){active[this.id]=true;});			
			$('div.fGrow#'+current).css('z-index',50);
			current=this.id;
			$(this).css('z-index',100);
			$(this).animate({"width":options.fStartDimensions,"height":options.fStartDimensions,"marginLeft":(((options.fStartDimensions-options.fDimensions)/2)*-1)+options.fSpacing,"marginTop":(((options.fStartDimensions-options.fDimensions)/2)*-1)+options.fSpacing},options.fSpeed,function(){active[this.id]=true;});
		}
	});
	
	$('div.fGrow').mouseout(function(){
		if(active[this.id]==true){
			active[this.id]=false;
			$(this).css('z-index',50);
			$(this).animate({"width":options.fDimensions,"height":options.fDimensions, "marginLeft":0+options.fSpacing,"marginTop":0+options.fSpacing},options.fSpeed,function(){active[this.id]=true;});
		}
	});		
}
