function addRollover(img, rolloverURL) {
	if (typeof img == "string") {
		var id = img;
		img = null;
		if (document.getElementById){
			img = document.getElementById(id);
		}else if (document.all){
			img = document.all[id];
		}
		if (!img){
			img = document.images[id];
		}
		if (!img){
			return;
		}
	}
	if (img.tagName.toLowerCase() != "img"){
		return;
	}
	var baseURL = img.src;
	(new Image()).src = rolloverURL;
	img.onmouseover = function() { img.src = rolloverURL; }
	img.onmouseout = function() { img.src = baseURL; }
}
function initImage() {
	var images = document.getElementsByTagName("img");
	for(var i = 0; i < images.length; i++) {
		var image = images[i];
		var rolloverURL = image.getAttribute("rollover");
		if (rolloverURL){
			addRollover(image, rolloverURL);
		}
		var largeURL = image.getAttribute("largeurl");
		if (largeURL){
			var altText = image.getAttribute("alt");
			if(!altText){
				altText = '';
			}
			addLargeURL(image, largeURL, altText);
		}
		var thisURL = image.getAttribute("thisurl");
		if (thisURL){
			//image.src = thisURL;
		}
	}
}

function addDivOver(div, rollClass) {
	if (typeof div == "string") {
		var id = div;
		div = null;
		if (document.getElementById){
			div = document.getElementById(id);
		}else if (document.all){
			div = document.all[id];
		}
		if (!div){
			return;
		}
	}
	if (div.tagName.toLowerCase() != "div"){
		return;
	}
	var baseClass = div.className;

	div.onmouseover = function() { div.className = rollClass; }
	div.onmouseout = function() { div.className = baseClass; }
}
function initDiv() {
	var divs = document.getElementsByTagName("div");
	for(var i = 0; i < divs.length; i++) {
		var div = divs[i];
		var rollClass = div.getAttribute("rollclass");
		if (rollClass){
			addDivOver(div, rollClass);
		}
	}
}

function initAll(){
	initImage();
	initDiv();

}


if(window.addEventListener){
	window.addEventListener('load',initAll, false);
}else if(window.attachEvent){
	window.attachEvent('onload',initAll);
}else{
	alert('Не могу прослушивать события');
}

function addLargeURL(img, largeURL, altText){
	if (typeof img == "string") {
		var id = img;
		img = null;
		if (document.getElementById){
			img = document.getElementById(id);
		}else if (document.all){
			img = document.all[id];
		}
		if (!img){
			img = document.images[id];
		}
		if (!img){
			return;
		}
	}
	if (img.tagName.toLowerCase() != "img"){
		return;
	}
	img.style.cursor = 'pointer';

	img.onclick = function() { showLarge(largeURL, altText); }

}
function showLarge(path, alt){
	var areaLarge = 'large_area';

	var img = new Image();
	img.src = path;
	imgHeight = img.height;



	$areaLarge = document.getElementById(areaLarge);
	$areaLarge.innerHTML = '<div class="large-show-item" id="large_item" title="Закрыть"><table align="center" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="middle" id="large_table_cell"><table align="center" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="middle"><div id="overblok" style="overflow:auto;"><img src="' + path + '" class="img-border" id="large_img"/></div></td></tr><tr><td height="50" align="left" valign="middle" class="table-large" ><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="75%" align="left" valign="middle"><div class="large-show-alt">' + alt + '</div></td><td width="25%" align="right" valign="middle" nowrap="nowrap"><a href="javascript:void(hideLarge());" class="large-show-item-link" id="large_item" title="Закрыть">Закрыть<img src="/content/default/img/large-close.png" width="25" height="25" align="absmiddle" style="margin-left:15px"/></a></td></tr></table></td></tr></table></td></tr></table></div><div class="large-show-area-bg"></div>';

	$areaLarge.style.display = '';
	$height = $areaLarge.scrollHeight;
	document.getElementById('large_table_cell').height = $height;

	var overblok = document.getElementById('large_img');

	if(imgHeight>$height){
		overblok.style.height = ($height-70)+'px';
		//document.getElementById('large_table_cell').height = imgHeight;
	}


	var areaFlash = 'flash_id';
	$areaFlash = document.getElementById(areaFlash);
	$areaFlash.style.display = 'none';



}


function hideLarge(){
	var areaLarge = 'large_area';
	var areaFlash = 'flash_id';
	$areaFlash = document.getElementById(areaFlash);
	$areaLarge = document.getElementById(areaLarge);
	$areaLarge.innerHTML = '';
	$areaLarge.style.display = 'none';
	$areaFlash.style.display = '';
}