// Yamaha-252; 12.04.08;
function loadImage(zone,img,imgWidth,imgHeight) {
	cwidth=ClientWidth();
	cheight=ClientHeight();

	widthPrecent=0;
	if (imgWidth>cwidth) {
		rzc=(imgWidth-cwidth)+50;
		prc=imgWidth/100;
		widthPrecent=Math.ceil(rzc/prc);
	}

	heightPrecent=0;
	if (imgHeight>cheight) {
		rzc=(imgHeight-cheight)+50;
		prc=imgHeight/100;
		heightPrecent=Math.ceil(rzc/prc);
	}

	if (widthPrecent>0 || heightPrecent>0) {
		if (widthPrecent>heightPrecent) {
			prec=widthPrecent;
		} else {
			prec=heightPrecent;
		}
		
		imgWidth=Math.ceil(imgWidth-((imgWidth/100)*prec));
		imgHeight=Math.ceil(imgHeight-((imgHeight/100)*prec));
	}	


	resLeft=((cwidth-imgWidth)/2)+ScrollLeft();
	resTop=((cheight-imgHeight)/2)+ScrollTop();

	box=document.getElementById(zone);
	box.style.position='absolute';
	box.style.top=resTop+'px';
	box.style.left=resLeft+'px';

	box.style.cursor='pointer';
	box.style.display='block';
	box.style.width=imgWidth;
	box.style.height=imgHeight;
	box.innerHTML='';
	
	box.onclick = function() { 
		box.style.display='none';
		box.innerHTML='';
	}

	image=document.createElement("img");	
	image.src=img;
	image.width=imgWidth;
	image.height=imgHeight;
	image.style.display='none';

	checkimage(image);
	
	box.appendChild(image);
}

function ClientWidth() {
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function ClientHeight() {
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}	

function ScrollLeft() {
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.scrollLeft:document.body.scrollLeft;
}

function ScrollTop() {
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.scrollTop:document.body.scrollTop;
}	



function setImage(id,num)
{
	box = document.getElementById('main_image');
	divImage(box);
	
	box.innerHTML = '';
	
	doLoad('','/ajax/set_image/'+id+'/'+num+'/',function()
	{
		image = divImage(box);

		image.style.display = 'none';
		
		checkimage(image);
	});
}

function divImage(div)
{
	img = div.getElementsByTagName('img');

	div.style.width = img[0].width;
	div.style.height = img[0].height;
	
	return img[0];
}


function checkimage(image) 
{
	if(image.complete)
		image.style.display = 'block';
	else 
		setTimeout(function(){checkimage(image)},100);
}
