FullImage=function(parent,imagesrc,createFrame,params){

	this.main=document.createElement("div");
	this.amplia=document.createElement("div");
	this.image=document.createElement("img");

	this.main.className="rightImageWrapper";

	this.image.src=imagesrc;

	var thisp=this;
	this.amplia.onclick=function(){
		thisp.preShowImage();
		thisp.preShowImage();
	}
	this.amplia.style.cursor="pointer";



	this.amplia.appendChild(document.createTextNode("amplia"));
	this.main.appendChild(this.image);
	this.main.appendChild(this.amplia);
	parent.appendChild(this.main);

	this.createWrapper(createFrame,params);

}

FullImage.prototype={
	preImg:0,
	frameOpacity:0,
	frame:0,
	framePreWrapper:0,
	frameWrapper:0,
	frameTop:0,
	tanca:0,
	opacity:0.7,

	createWrapper:function(createFrame,params){
		this.frameOpacity=document.createElement("div");
		this.framePreWrapper=document.createElement("div");
		this.frameWrapper=document.createElement("div");
		this.frameTop=document.createElement("div");
		this.frame=createFrame(this,params);
		this.tanca=document.createElement("div");
		if (navigator.userAgent.indexOf("MSIE 6.0")!=-1){
			this.frameOpacity.className="ieDialogHack";
		}else{
			this.frameOpacity.style.position="fixed";
			this.frameOpacity.style.width="100%";
			this.frameOpacity.style.top="0px";
			this.frameOpacity.style.left="0px";
			this.frameOpacity.style.height="100%";
		}
		this.frameOpacity.style.background="#000";
		this.frameOpacity.style.zIndex="700";
		try{ this.frameOpacity.style.filter="alpha(opacity='"+this.opacity*100+"')"; }catch(e){}
		try{ this.frameOpacity.style.opacity=this.opacity;}catch(e){}
		try{ this.frameOpacity.style.mozOpacity=this.opacity;}catch(e){}
		this.framePreWrapper.style.textAlign="center";
		this.framePreWrapper.style.position="absolute";
		this.framePreWrapper.style.top="0px";
		this.framePreWrapper.style.left="0px";
		this.framePreWrapper.style.width="100%";
		this.framePreWrapper.style.zIndex="800";

		this.frameWrapper.style.textAlign="left";
		this.frameWrapper.style.marginLeft="auto";
		this.frameWrapper.style.marginRight="auto";
		this.frameWrapper.style.background="#000";
		this.frameWrapper.style.marginTop="15px";
		this.frameWrapper.style.padding="10px";
		this.tanca.style.background="#888";
		this.tanca.style.height="10px";
		this.tanca.style.width="10px";
		this.tanca.style.cursor="pointer";
		this.tanca.style.styleFloat="right";
		this.tanca.style.cssFloat="right";
		var thisp=this;
		this.tanca.onclick=function(){thisp.tancaWrapper();}

		this.frameTop.appendChild(document.createTextNode("Imatge completa"));
		this.frameTop.appendChild(this.tanca);
		this.frameWrapper.appendChild(this.frameTop);
		this.frameWrapper.appendChild(this.frame);
		this.framePreWrapper.appendChild(this.frameWrapper);


	},
	showImage:function(){

		var rel=this.frame.width/this.frame.height;
		if (this.frame.width>600){
			var res=600-this.frame.width;
			this.frame.width+=res;
			this.frame.height+=res/rel;
		}
		this.frameWrapper.style.width=this.frame.offsetWidth+"px";
		var body=document.getElementsByTagName("body")[0];
		body.appendChild(this.frameOpacity);
		body.appendChild(this.framePreWrapper);
	},
	detectWidth:function(){
		var thisp=this;
		if (!this.preImg.complete){
				setTimeout(function(){thisp.detectWidth();},20);
		}
		this.showImage();
	},
	preShowImage:function(){
		var pimg=document.getElementById("dialog").getElementsByTagName("img");
		if (pimg.length){
			document.getElementById("dialog").removeChild(pimg[0]);
		}
		this.preImg=document.createElement("img");
		this.preImg.src=this.image.src;
		this.detectWidth();
	},
	tancaWrapper:function(){
		var body=document.getElementsByTagName("body")[0];
		body.removeChild(this.frameOpacity);
		body.removeChild(this.framePreWrapper);
	}
};
