function _dynamic_pic() {
	var loaded;
	var pic_data;
	this.start = function() {
		loaded = Array();
	}
	/*
		Preload
	*/
	this.preload = function(obj) {
	}	
	/*
		Definiowaie obiektów
	*/
	this.show = function(obj,id) {
		if(this.wyzwolone==null) {
			itemId = id;
			local_obj = obj;
			this.create_new_div();	
			this.load_data();
			this.wyzwolone = true;
		} 
	}
	this.create_new_div = function() {
		this.newdiv = document.createElement('div');
		this.newdiv.setAttribute('id', 'prev_box'+itemId);
		document.body.appendChild(this.newdiv);	
	}
	/*
		Ładowanie
	*/
	this.load_data = function() {
		if(array_chk(itemId)>=1) {
			document.getElementById('prev_box'+itemId).style.display = '';
		} else {
			http.open('get', '_ajax/_read_dynamic_pic.php?itemId='+itemId);
			http.onreadystatechange = read_dynamic_pic_Response;
			http.send(null);
		}
	}
	/*
		Mouse out of the image
	*/
	this.out = function() {
		/*
			Hide all box
		*/
		for(var i=0;i<loaded.length;i++)
		{
			document.getElementById('prev_box'+loaded[i]).style.display = 'none';
		}
		this.wyzwolone = null;
	}
	/*
		Setting the position
	*/
	this.set_pos_div = function() {
		this.img_width = 100;
		this.img_height = 200;
		clearInterval(this.int_ID);
		var w = this.square_size;
		var h = this.square_size;
		wf = parseFloat(this.prev_box_ID.style.width)/2;
		hf = parseFloat(this.prev_box_ID.style.height)/2;
		sp_left = this.pic_pos_left-this.mouse_pos_x+wf;
		sp_left_w = sp_left-(wf*2)+this.img_width;
		sp_top = this.pic_pos_top-this.mouse_pos_y+hf;
		sp_top_w = sp_top-(hf*2)+this.img_height;
		if(sp_left<2&&sp_left_w>0) {
			this.prev_box_ID.style.left = this.mouse_pos_x-(w/2)+'px';
		}
		if(sp_top<2&&sp_top_w>0) {
			this.prev_box_ID.style.top = this.mouse_pos_y-(h/2)+'px';
		} 
		left_percent = (parseFloat(this.prev_box_ID.style.left)-this.pic_pos_left)*100/(parseFloat(this.img_width)-this.square_size)
		document.getElementById('picture_indiv').style.left = (((this.Bigimg_width-this.preview_size)*left_percent)/100)*(-1)+'px';
		top_percent = (parseFloat(this.prev_box_ID.style.top)-this.pic_pos_top)*100/(parseFloat(this.img_height)-this.square_size); 
		document.getElementById('picture_indiv').style.top = (((this.Bigimg_height-this.preview_size)*top_percent)/100)*(-1)+'px';
	}
	/*
		Draw BOX
	*/
	draw_box = function(width,height) {
		if(width>0) {
			obj = local_obj;
			this.square_height = height;
			this.square_width = width;
			var wi = obj.width;
			var hi = obj.height;
			this.mouse_pos_x = document.getElementById('pic_'+itemId).offsetLeft+wi+this.square_width+5;
			this.mouse_pos_y = document.getElementById('pic_'+itemId).offsetTop+(this.square_height/2)+(hi/2);
			this.prev_box_ID = document.getElementById('prev_box'+itemId);
			this.prev_box_ID.style.display = '';
			this.prev_box_ID.style.position = 'absolute';
			this.prev_box_ID.style.width = this.square_width+'px';
			this.prev_box_ID.style.height = this.square_height+'px';
			this.prev_box_ID.style.left = (this.mouse_pos_x-(this.square_width))+'px';
			this.prev_box_ID.style.top = (this.mouse_pos_y-(this.square_height))+'px';
			this.prev_box_ID.style.border = "#999999 solid 1px";
			this.prev_box_ID.style.background = "#FFFFFF";
		}
	}
	array_chk = function(obj) {
		var cd = "";
		for(var i=0;i<loaded.length;i++)
		{
			if(loaded[i]==obj) {
				cd++;	
			}
		}
		return cd;
	}
	/*
		Dynamic pic response
	*/
	read_dynamic_pic_Response = function() {
		if(http.readyState==4) {
			loaded.push(itemId);
			var data = http.responseText.split('|');
			draw_box(parseFloat(data[0]),parseFloat(data[1]));
			document.getElementById('prev_box'+itemId).innerHTML = data[2];
			document.getElementById('prev_box'+itemId).style.display = '';
		}
	}
}
_dynamic_pic = new _dynamic_pic();
_dynamic_pic.start();
