function gallery(elem) {
	this.list=$(elem);
	
	this.items=this.list.find('li');
	
	this.selected_item=this.list.find('li.selected');
	
	this.big_picture=$('#big-photo-container');
	
	this.events();
	
	this.anim_func = EEQ.Quartic.easeInOut;
	
	this.anim_dur = 20;
	
	this.animating=false;
};

gallery.prototype = {
	events:function() {
		var me=this;
		this.list.find('a').click(
			function() { 
			if ($(this).parent().is('.selected')){
			return false;
			}
			if (this.animating){
				return false;
			}
			var par=$(this).parent();
			var target=$(this).attr('href');
			return me.changePictures(target,par);
		}
		);
	
	},
	changePictures:function(target,parent) {
		this.animating=true;
		var me=this;
		this.loader_icon = parent.find('i').eq(0);
		this.icon_timeout = setTimeout(function(){me.loader_icon.addClass("on");},100);
		var old_img=this.big_picture.find('img').eq(0);
		
		var new_img=$('<img>');
		new_img.attr('src', target);
		
		
		this.big_picture.prepend(new_img);
		
		
		var new_left=this.big_picture.width()+'px';
		var old_left=-this.big_picture.width()+'px';
		new_img.css({
					position:'absolute',
					left:new_left,
					zIndex:'10'});
		
		var tw1 = new Tween(old_img, 'left', this.anim_func, '0', old_left, this.anim_dur);
		
		tw1.onMotionFinished = function(obj){
			
			$(obj).remove();
		};
		clearInterval(me.icon_timeout);
		this.loader_icon.removeClass("on");
		var tw2 = new Tween(new_img, 'left', this.anim_func, new_left, '0', this.anim_dur);
		this.animating=false;
		
		
		tw2.onMotionFinished = function(obj){
			me.list.find('li.selected').find('img').eq(0).css('display','block');
			me.list.find('li.selected').removeClass('selected');
			parent.toggleClass('selected');
			parent.find('img').eq(0).css('display','none');
		};
		return false;
		//new_img.animate({ left:"0" },500);
		//old_img.animate({ left:"-100%" },500);
		//old_img.remove();
	}
};
$(function(){
			new gallery('#gallery');
});

// random woman
$(function() {
	var women = [2, 5, 6, 8, 73, 108, 121, 128];
	var woman_id = women[Math.floor(Math.random()*women.length)];
	$('body.inner #woman').css('background-image', 'url('+ siteURL +'/im/woman_'+ woman_id +'.jpg)');
});