MMGallery.prototype = {
	ref : null,
	currentAtt : -1,
	maxSize : 565,
	imgs : null,
	
	init : function(data){
		/*var att = data[0];
		if(att.type == "img"){
			this.loadImage(att.url);
		}
		else{
			this.loadMovie(att.url);
		}*/
		
		var This = this;
		this.next.click(function(){
			This.load(1);
		});
		
		this.prev.click(function(){
			This.load(-1);
		});
		
		This.load(1);
	},
	
	loadImage : function(url){
		this.ref.html("<img src='"+url+"' />");
	},
	
	loadMovie : function(url){
		var poster = url.substr(0,url.length - 3)+".jpg";
		if(this.iphone == "iphone"){
			this.ref.html('<video controls="controls" src="'+url+'" width="'+this.maxSize+'px" poster="'+poster+'">'+
			'</video>');
		}
		else{
			this.ref.html('<a href="'+url+'" id="fallback"></a>');
			flowplayer("fallback", this.player, 
				{
					clip: {
						url: url,
						autoPlay: false,
						autoBuffering: true
					}
				});
		}
	},
	
	load : function(i){
		this.currentAtt += i;
		if(this.currentAtt == this.imgs.length){
			this.currentAtt = 0;
		}
		if(this.currentAtt < 0){
			this.currentAtt = this.imgs.length - 1;
		}
		var w,h;
		var att = this.imgs[this.currentAtt];
		this.ref.addClass("loading");
		if(att.type == "img"){
			w = att.w;
			h = att.h;
			this.loadImage(att.url)
		}
		else{
			w = 565;
			h = 315; // CHECK THIS
			this.loadMovie(att.url);
		}
		
		this.ref.animate({
			width: w,
			height: h,
		},400,"linear",function(){
			//$(this).animate({
			//	height:h
			//},300,"linear",function(){
				$(this).removeClass("loading");
			//})
		});
	}
}

function MMGallery(ref,data,player){
	this.next = $("#next");
	this.prev = $("#prev");
	this.ref = ref;
	this.player = player;
	this.imgs = data.imgs;
	this.iphone = data.iphone;
	this.init(data);
	
	
}
