// ----------------------------------------------------------
function ImgDB_frame(r, tbw, tbh, lrw, lrh, c, ce)
{
	this.ram		= r;
	this.tb_width	= tbw;	// top - bottom
	this.tb_height	= tbh;
	this.lr_width	= lrw;	// left - right
	this.lr_height	= lrh;
	this.lframe;
	this.tframe;
	this.rframe;
	this.bframe;
	this.cena		= c;
	if (ce) {
	    this.cenae		= c * 30.126;
	}
}
// ----------------------------------------------------------
function img_db_add_frame(r, tbw, tbh, lrw, lrh, c, ce)
{
	this.zoznam[this.zoznam.length] = new ImgDB_frame(r, tbw, tbh, lrw, lrh, c, ce);
}
function img_db_format_cena(c)
{
	var cena, out, first;
	out = "";
	cena = c+"";
	first = cena.length % 3;
	out = cena.substring(0, first);
	for( var ii=first; ii+3 <= cena.length; ii=ii+3)
		out += " "+cena.substring(ii,ii+3);
	return out;
}
function img_db_format_cenae(c)
{
	return c.toFixed(2);
}
function img_db_new_navig(r)
{
	var kosik, ram, a, out;
		
	kosik = document.getElementById(this.idor).value;
	//alert( r );
	ram = r.match( /\d+/g );
	ram = ram[0];
	//alert( kosik );
	//alert( ram );

	a = kosik.match( /\d+/g );
	if( a != null && (a.length == 1 || a.length == 2) )
		out = "obrazy."+a[0]+"."+ram;

	//alert( out );
	//alert( document.getElementById(this.st_bez).value+"&fr="+ram );
	document.getElementById(this.idor).value = out;
	document.getElementById(this.st).value = document.getElementById(this.st_bez).value+"&fr="+ram;
	
}
function img_db_preload()
{
	var ii;
	for( ii = 0; ii < this.zoznam.length; ii++ ){
		this.zoznam[ii].lframe = new Image();
		this.zoznam[ii].lframe.src = this.path+"l/"+this.zoznam[ii].ram;
		this.zoznam[ii].tframe = new Image();
		this.zoznam[ii].tframe.src = this.path+"t/"+this.zoznam[ii].ram;
		this.zoznam[ii].rframe = new Image();
		this.zoznam[ii].rframe.src = this.path+"r/"+this.zoznam[ii].ram;
		this.zoznam[ii].bframe = new Image();
		this.zoznam[ii].bframe.src = this.path+"b/"+this.zoznam[ii].ram;
	}
	
}
function img_db_show_frame(r)
{
	var ii, nasiel;

	nasiel = false;
	for( ii = 0; ii < this.zoznam.length; ii++ )
		if( r == this.zoznam[ii].ram ){
			nasiel = true;
			break;
		}
	if( nasiel ){
		if( typeof(this.zoznam[ii].tframe) == "object" && this.zoznam[ii].tframe.complete ){
			this.top.setAttribute("src",this.zoznam[ii].tframe.src);
		}
		else {
			this.top.setAttribute("src", this.path+"t/"+this.zoznam[ii].ram);
		}
		
		if( typeof(this.zoznam[ii].rframe) == "object" && this.zoznam[ii].rframe.complete )
			this.right.setAttribute("src",this.zoznam[ii].rframe.src);
		else
			this.right.setAttribute("src", this.path+"r/"+this.zoznam[ii].ram);
		
		if( typeof(this.zoznam[ii].bframe) == "object" && this.zoznam[ii].bframe.complete )
			this.bottom.setAttribute("src",this.zoznam[ii].bframe.src);
		else
			this.bottom.setAttribute("src", this.path+"b/"+this.zoznam[ii].ram);

		if( typeof(this.zoznam[ii].lframe) == "object" && this.zoznam[ii].lframe.complete )
			this.left.setAttribute("src",this.zoznam[ii].lframe.src);
		else
			this.left.setAttribute("src", this.path+"l/"+this.zoznam[ii].ram);

		this.top.style.width = this.zoznam[ii].tb_width;
		this.top.style.height = this.zoznam[ii].tb_height;
		this.bottom.style.width = this.zoznam[ii].tb_width;
		this.bottom.style.height = this.zoznam[ii].tb_height;
		this.left.style.width = this.zoznam[ii].lr_width;
		this.left.style.height = this.zoznam[ii].lr_height;
		this.right.style.width = this.zoznam[ii].lr_width;
		this.right.style.height = this.zoznam[ii].lr_height;
		
		document.getElementById(this.cenaRamuID).innerHTML = this.formatCena(this.zoznam[ii].cena);
		document.getElementById(this.hcenaRamuID).value = this.zoznam[ii].cena;
		document.getElementById(this.cenaSpoluID).innerHTML = this.formatCenaE(parseFloat(this.cenaObrazu) + parseFloat(this.zoznam[ii].cena));

		if (this.zoznam[ii].cenae) {
		    document.getElementById(this.cenaRamuIDE).innerHTML = this.formatCenaE(this.zoznam[ii].cenae);
//		    document.getElementById(this.hcenaRamuIDE).value = this.zoznam[ii].cenae;
		    var x = (parseFloat(this.cenaObrazu) + parseFloat(this.zoznam[ii].cena))*30.126;
		    document.getElementById(this.cenaSpoluIDE).innerHTML = this.formatCenaE(x)+' Sk';
		}
		this.newNavig(this.zoznam[ii].ram);
	}
	
}
function img_db_init()
{
	this.top = document.getElementById(this.t);
	this.left = document.getElementById(this.l);
	this.right = document.getElementById(this.r);
	this.bottom = document.getElementById(this.b);
}
function ImgDB(p, c)
{
	this.path = p;			// url k ramom
	this.cenaObrazu = c;	// cena obrazu

	// ID pre zobrazenie casti ramov
	this.t = "top";
	this.l = "left";
	this.r = "right";
	this.b = "bottom";
	
	// Navigacia a identifikacia pre kosik
	this.idor = "id_obr_ram"; 		// hidden id obrazu alebo aj ramu
	this.st = "site"; 				// id pre site path
	this.st_bez = "bez_ramu_site";	// site path bez parametra pre ram

	// Odkazy na Dom objekty
	this.top;
	this.left;
	this.right;
	this.bottom;
	
	// ID pre zobrazenie ceny ramu, obrazu, spolu a hidden poloziek
	this.cenaRamuID = "cram";		// zobrazena cena
	this.hcenaRamuID = "cramh";		// hidden cena
	this.cenaSpoluID = "cspolu";		// zobrazena cena spolu

	this.cenaRamuIDE = "eram";		// zobrazena cena
//	this.hcenaRamuIDE = "eramh";		// hidden cena
	this.cenaSpoluIDE = "espolu";		// zobrazena cena spolu

	
	this.zoznam = new Array();

	this.addFrame = img_db_add_frame;
	this.showFrame = img_db_show_frame;
	this.initImgDB = img_db_init;
	this.formatCena = img_db_format_cena;
	this.formatCenaE = img_db_format_cenae;
	this.newNavig = img_db_new_navig;
	this.preload = img_db_preload;
}
function Preload()
{
	setTimeout("frm.preload()",1);
}
// ----------------------------------------------------------
