jQuery.ifastFind = {
	tileWidth : 0,
	tileInset : 0,
	tileCount : 0,
	tilesOnPg : 20,
	animation : false,
	helperImg : false,
	build : function (o)
	{
		var s = {
			url 	  :	'feed.php',
			params    :	false,
			tileWidth :	240,
			tileInset :	0,
			tilesOnPg :	20,
			tileCount : 0
		};
		if(o) jQuery.extend(s,o);
		jQuery.ifastFind.tileWidth = s.tileWidth;
		jQuery.ifastFind.tileInset = s.tileInset;
		jQuery.ifastFind.tileCount = s.tileCount;
		jQuery.ifastFind.tilesOnPg = s.tilesOnPg;
		if(!jQuery.ifastFind.helperImg)
		{
			helperImg = document.createElement('img');
			helperImg.src = 'al_img/ajax.gif';
			helperImg.style.position = 'absolute';
			helperImg.style.top = '5px';
			helperImg.style.left = '145px';
			helperImg.style.display = 'none';
			helperImg.id = 'ifM_helper';
			jQuery('#debug').append(helperImg);
			jQuery('img#ifM_helper').css('z-index','999999');
			jQuery.ifastFind.helperImg = true;
		}
		jQuery("img#ifM_helper").ajaxStart(function(){ jQuery(this).animate({opacity:'show'},'fast'); });
		jQuery("img#ifM_helper").ajaxStop(function(){ jQuery(this).animate({opacity:'hide'},'slow'); });
		return this.each(
		function ()
		{
			jQuery.ifastFind.createTile(s.url,s.params);
		}
		);
	},

	countTiles : function ()
	{
		jQuery.ifastFind.tileCount = parseInt(jQuery('div.ifM_tile').size());
	},

	createTile : function (u,p,b,first)
	{

		var ptr = document.createElement('div');
		jQuery.ifastFind.countTiles();
		var ctr = jQuery.ifastFind.tileCount + 1;
		ptr.id = 'ifM_tile'+ctr;
		if (b=="back"){

			last = jQuery('div.ifM_wrapper')[0].lastChild.id;
			var ptrId = ptr.id;
			jQuery('div.ifM_wrapper').append(ptr);
			var tileOffset = - jQuery.ifastFind.tileWidth * jQuery.ifastFind.tileCount + jQuery.ifastFind.tileInset;
			var tileOffset = 0 + jQuery.ifastFind.tileInset;
		}else{
			jQuery('div.ifM_wrapper').append(ptr);
			var tileOffset = jQuery.ifastFind.tileWidth * jQuery.ifastFind.tileCount + jQuery.ifastFind.tileInset;
		}

		jQuery('#ifM_tile'+ctr).addClass('ifM_tile');
		jQuery('#ifM_tile'+ctr).css(
		{
			top		: 	0,
			left		:	tileOffset+'px',
			position	:	'absolute',
			overflow	:	'hidden',
			margin		:	0,
			padding		:	0,
			border		:	0,
			display		:	'block'
		});
		jQuery('#ifM_tile'+ctr).load(u, p,
		function()
		{
			jQuery('div.ifM_content a',this)
			.bind(
			'click',
			function ()
			{
				if(jQuery.ifastFind.animation==true) return false;
				var rslt = jQuery.ifastFind.parseLink(jQuery(this).attr('href'));
				if(rslt.status == 'link')
				document.location.href = rslt.link;
				else
					{
						jQuery.ifastFind.animation = true;
						jQuery.ifastFind.createTile(u,rslt);
					}
					return false;
				}
				);
				jQuery('div.ifM_back a', this)
				.bind(
				'click',
				function ()
				{
					var rslt = jQuery.ifastFind.parseLink(jQuery(this).attr('href'));
					if(rslt.status != 'link')
					{
						if(rslt.previous==false){
							base = "base";
						}else{
							base="";
						}
						jQuery.ifastFind.animation = true;
						jQuery.ifastFind.createTile(u,rslt,'back',base);
					}
					return false;
				}
				);
				jQuery('div.ifM_reset a', this)
				.bind(
				'click',
				function ()
				{
					jQuery.ifastFind.scrollToTile(0,1000);
					return false;
				}
				);
				jQuery('div.ifM_pager a', this)
				.bind(
				'click',
				function ()
				{
					var scroll = 'Down';
					if(jQuery(this).attr('rel')!='Down')
					scroll = 'Up';
					jQuery.ifastFind.scrollContent(0,scroll);
					return false;
				}
				);
				if (b=="back"){
					jQuery('div#'+last).attr("id",ptrId);
					jQuery(ptr).attr("id",last);
				}
				jQuery.ifastFind.scrollToTile(ctr,'slow',b,first);
			}
			);
		},
		scrollToTile : function (n,s,b,first)
		{
			if (b=="back"){
				n = n -2;
			}
			jQuery.ifastFind.countTiles();
			if(n>jQuery.ifastFind.tileCount) n = jQuery.ifastFind.tileCount;
			if(!s) s = 'slow';
			if(n<1) n = 1;
			var tmp = (jQuery.ifastFind.tileWidth * n) - jQuery.ifastFind.tileWidth;
			var now = tmp * -1;
			if (b=="back"){
				var tmp = jQuery.ifastFind.tileWidth -(jQuery.ifastFind.tileWidth * n);
				var now = tmp;
			}
			jQuery.ifastFind.animation = true;
			jQuery('div.ifM_wrapper')
			.animate( { left: now },s, function ()
			{
				if(n<jQuery.ifastFind.tileCount)
				jQuery.ifastFind.cleanTiles(n);
				if(now!=0) now += 'px';
				jQuery(this).css('left',now);
				jQuery.ifastFind.animation = false;
			}
			);
			cufonizza();
		},

		cleanTiles : function (n)
		{
			jQuery.ifastFind.countTiles();
			if(n>=jQuery.ifastFind.tileCount) return false;
			var start = n + 1;
			var end   = jQuery.ifastFind.tileCount;
			for(var i = start; i <= end; i++)
			{
				jQuery('#ifM_tile'+i).remove();
			}

		},
		AlbcleanTiles : function (n)
		{
			jQuery.ifastFind.countTiles();
			var start = n + 1;
			var end   = jQuery.ifastFind.tileCount;
			for(var i = start; i <= end; i++){jQuery('#ifM_tile'+i).remove();}
		},
		scrollContent : function (e,d)
		{
			jQuery.ifastFind.countTiles();
			var pop = jQuery('#ifM_tile'+jQuery.ifastFind.tileCount);
			var box = jQuery(pop).children('.ifM_content');
			var bit = new Array();
			var ctr = 0; var top = 0; var lim = 20;	// 8 Per Page
			var amt = jQuery(box).children('a').length;
			jQuery(box).children('a').each(
			function ()
			{
				bit[ctr] = this;
				if(jQuery(this).attr('rel')=='first')
				top = ctr;
				ctr++;
			}
			);
			if(d == 'Up') top--; else top++;
				var pgr = jQuery(pop).children('.ifM_pager');
				if(top < 1)
				{
					top = 0;
					jQuery(pgr).children('a').each(function(){if(jQuery(this).attr('rel')=='Up')jQuery(this).hide();});
				}
				else { jQuery(pgr).children('a').each(function(){if(jQuery(this).attr('rel')=='Up')jQuery(this).show();}); }
					if(top >= amt - lim)
					{
						top = amt - lim;
						jQuery(pgr).children('a').each(function(){if(jQuery(this).attr('rel')=='Down')jQuery(this).hide();});
					}
					else { jQuery(pgr).children('a').each(function(){if(jQuery(this).attr('rel')=='Down')jQuery(this).show();}); }
						for(i=0;i<amt;i++)
						{
							if(i==top)
							jQuery(bit[i]).attr('rel','first');
							else
								jQuery(bit[i]).attr('rel','');
								if(i>=top && i<=top+lim)
								jQuery(bit[i]).css('display','block');
								else
									jQuery(bit[i]).css('display','none');
								}

							},

							parseLink : function (raw)
							{
								if(raw.substr(0,8) == 'fetch://')
								{
									var json = raw.substr(8,raw.length-8);
									var data = jQuery.ifastFind.parseJSON(json);
									data.status = 'ajax';
									return data;
								}
								var myOb = { 'link': raw, 'status': 'link' };
								return myOb;
							},

							toggleDisplay : function (r,f)
							{
								if(jQuery(this).css('display')=='block')
								var toggle_value = 'hide';
								else
									var toggle_value = 'show';
									if(f==true)
									{
										jQuery(this).toggle();
									}
									else
										{
											jQuery(this).animate(
											{
												opacity: toggle_value
											}, 'slow', function ()
											{
												if(r==true)
												jQuery.ifastFind.scrollToTile(1,'fast');
											}
											);
										}
									}

									,parseJSON : function (d)
									{
										var data = d;
										var self = this;
										if (typeof d == 'undefined')
										{
											return self;
										}
										if(jQuery.browser.msie && (jQuery.browser.version < 8) )
										data = data.substr(0,data.length-1);
										if (d.constructor == Array)
										{
											data={};
											for(var i=0;i<d.length;i++)
											if (typeof data[d[i].name] != 'undefined')
											if (data[d[i].name].constructor!= Array)
											data[d[i].name]=[data[d[i].name],d[i].value];
											else
												data[d[i].name].push(d[i].value);
												else
													data[d[i].name]=d[i].value;
												}
												else
													data = eval('('+data+')');
													return data;
												}

											}

											jQuery.fn.fastFind 		= jQuery.ifastFind.build;
											jQuery.fn.fastFindToggle 	= jQuery.ifastFind.toggleDisplay;
											jQuery.fn.reverse 		= function() {return this.pushStack(this.get().reverse(), arguments);};
