albumSETUP=function(){
		$('.album').live('click',function(e){
			e.preventDefault();
			var activeAlbum=$(this).attr('href');
			$(this).addClass('activeAlbum').siblings().removeClass('activeAlbum');
			$('#reset-album').show();
			if( $(this).parent().is('#right-album')){
				$('#right-album .album').flyOneByOne('#left-album',400,function(){ $(activeAlbum).viewAlbum();});
			}
			else{
				$(activeAlbum).viewAlbum();
			}
		}).hover(
				function(){$(this).find('p').hide().slideDown(200);},
				function(){$(this).find('p').slideUp(200);
		}).find('div').css({opacity:.6});
		
		$('#reset-album').live('click',function(e){
			e.preventDefault();
			$(this).hide();
			$('#right-album-gallery .galleryview').fadeOut('fast');
			$('#left-album .album').flyOneByOne('#right-album',400,function(){}).removeClass('activeAlbum');
		});	
}

$.fn.viewAlbum=function(){
	$(document).stopTime("transition");
	$(this).show().siblings().hide();//.find('.filmstrip').stop();
	if(!$(this).hasClass('galleryViewInitiated')){
	$(this).galleryView()
			.find('.filmstrip img')
			.css({opacity:.5})
			.hover(
				function(){$(this).fadeTo('slow',1)},
				function(){$(this).fadeTo('slow',.5)}
			).eq(0);
	}
	
	return $(this).addClass('galleryViewInitiated');
}

rc=function(){
	var cc='123456789abcdef';
	var nc=cc.match(/\w{1}/g).sort(function() {return 0.5 - Math.random()}).slice(0,6).join('');
	return '#'+nc;
}
$.fn.static2absolute=function(){
	return this.each(function(i,o){
				  var pos=$(o).offset();
				  var left=pos.left-parseInt($(o).css('marginLeft'));
				  var top=pos.top-parseInt($(o).css('marginTop'));
				  var css={left:left,top:pos.top,zIndex:100-i,display:'block',width:$(o).width(),height:$(o).height()};
				  $(o).css(css);
			  }).css({position:'absolute'}).appendTo(document.body);
			  
}
$.fn.flyOneByOne=function(flyTo,time,callback){
	var self=this;
	var $flyTo=$(flyTo);
	var pos=$flyTo.offset();
	var flyWidth=$flyTo.innerWidth();
	var oLength=total=$(self).length;
	var selfWidth=$(self).outerWidth(true);
	var selfHeight=$(self).outerHeight(true);
	var totalWidth=selfWidth*total;
	var colMax=Math.floor(flyWidth/selfWidth);
	var col=row=0;
	$(this).static2absolute().eq(0).fly(flyTo,pos,time,function(){
												if(!$(this).next().length&&callback) $(this).delay(time,callback);
												var xy={};
												var len=(total-(--oLength))+1;
												var fixLeft=selfWidth*len;
												var fixTop=selfWidth*len;
												var mod=len%colMax;
												col=(len==colMax || mod==0)?colMax:mod;
												if(col==1){++row};
												//$(this).find('h3').html(row+','+col);
												var fixLeft=selfWidth*(col-1);
												var fixTop=selfHeight*(row-0);
												xy.left=pos.left+fixLeft;
												xy.top=pos.top+fixTop;
								 				$(this).next().fly(flyTo,xy,time,arguments.callee);
								 			});
	return $(this);
}
$.fn.fly=function(flyTo,pos,time,callback){
	var self=this;
	var $flyTo=$(flyTo);
	var pos=pos||{left:0,top:0};
	return this.each(function(i){
		
		  //var len=$flyTo.children().length;
		  //var fixLeft=$(self).outerWidth()*len;
		  //var fixTop=$(self).outerHeight()*len;
		  var left=pos.left;
		  var top=pos.top;
		  $(this).animate({left:left,top:top},{ duration: time, easing: 'easeOutQuad', complete: function(){
							  callback.call(self);
							  $(this).appendTo($flyTo)
									 .removeAttr('style');
									 //alert($flyTo.children().length);
							  }
			  })
	})
}

$.fn.delay = function(time, callback) {
    var self = this;
    setTimeout(function() {
        callback.call(self);
    }, time);
	return $(this);
};


