// Коррекция альфа-канала PNG в IE
function fix_png(element)
{
	//if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
	{
		var src;
		
		if (element.tagName=='IMG')
		{
			if (/\.png$/.test(element.src))
			{
				src = element.src;
				var w = element.width;
				var h = element.height;
				element.src = "/tmpl/ui/x.gif";
				element.width = w;
				element.height = h;
			}
			if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
		}
		else
		{
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i)
			if (src)
			{
				src = src[1];
				element.runtimeStyle.backgroundImage="none";
			}
			if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
		}
		
	}
}

function emit(text)
{
	document.write(text);
}

function emitln(text)
{
	document.writeln(text);
}

function element(i)
{
	if (document.getElementById)
		return document.getElementById(i);
	if (document.all)
		return document.all(i);
	if (document.layers)
		return document.layers(i);
}

// Открыть блок
function menu_open(id)
{
	element(id).style.display = "block"; 
}

function menu_close(id)
{
	element(id).style.display = "none";
}

function menu_swap(id)
{
	if (element(id).style.display == "block")
	{
		menu_close(id);
	}
	else
	{
		menu_open(id);
	}
}

//var menu = '1';
//var cat = '1';
var mver = '16';

// Шапка
function ui_header(menu)
{
	emit
	(
		'<table class="ui_main_table">' +
		'<tr><td>' +
		'<table style="width:100%"><tr><td class="ui_header_left"><img src="/tmpl/ui/x.gif"></td><td style="width:760px;height:320px;text-align:center" nowrap>'
	);
	
	emit('<div id="header_flash"></div>');
	var so = new SWFObject("/tmpl/ui/header.swf?" + mver, "header_swf_obj", "760px", "320px", "0", "#ff0000");
	so.addParam("wmode", "transparent");
	so.addParam("quality", "best");
	so.addParam("menu", "false");
	so.addParam("scale", "noscale");
	so.addVariable("menu", menu);
	so.write("header_flash");

	emit
	(
		'</td><td class="ui_header_right"><img src="/tmpl/ui/x.gif"></td></tr></table>' +
		'</td></tr>' +
		'<tr>' +
		'<td style="width:100%;height:100%">' +
		'<table class="ui_body_table">' +
		'<tr><td class="ui_body_left">' +
		'<table style="width:auto;height:100%">' +
		'<tr><td class="ui_body_left_bg" colspan=2></td></tr>' +
		'<tr><td style="width:100%"><img src="/tmpl/ui/x.gif"></td><td class="ui_body_left_shadow" nowrap><img src="/tmpl/ui/x.gif"></td></tr>' +
		'</table>' +
		'</td>' +
		'<td class="ui_body">'
	);
}

// Подвал
function ui_footer()
{
	emit
	(
		'</td><td class="ui_body_right">' +
		'<table style="width:auto;height:100%">' +
		'<tr><td class="ui_body_right_bg" colspan=2></td></tr>' +
		'<tr><td class="ui_body_right_shadow" nowrap><img src="/tmpl/ui/x.gif"></td><td style="width:100%"><img src="/tmpl/ui/x.gif"></td></tr>' +
		'</table>' +
		'</td>' +
		'</tr></table>' +
		'</td></tr>' +
		'<tr><td>' +
		'<table style="width:100%"><tr><td><img src="/tmpl/ui/x.gif"></td><td class="ui_body_bottom" nowrap></td><td><img src="/tmpl/ui/x.gif"></td></tr></table>' +
		'<table class="ui_copyright" style="width:100%"><tr><td style="width:50%"></td><td style="width:60px" nowrap>'
	);
}

function ui_footer_2()
{
	emit
	(
		'</td><td style="width:50%"></td></tr></table>' +
		'<div style="height:16px;overflow: hidden"></div>' +
		'</td></tr>' +
		'</table>'
	)
}

// Рамка
function ui_frame_header(width, height)
{
	emit
	(
		'<table class="ui_frame_table" style="' + (width != null ? 'width:' + width + ';' : '') + (height != null ? 'height:' + height : '') + '">' +
		'<tr>' +
		'<td class="ui_frame_top_left" nowrap></td>' +
		'<td class="ui_frame_top" nowrap>' +
		'<table class="ui_frame_title_table"><tr><td style="width:4px;" nowrap></td><td class="ui_frame_pic" nowrap></td><td style="width:99%;" class="ui_frame_title">'
	);
}

function ui_frame_header2()
{
	emit
	(
		'</td><td style="text-align:center" class="ui_frame_title2">'
	);
}

function ui_frame_body()
{
	emit
	(
		'</td></tr></table>' +
		'</td>' +
		'<td class="ui_frame_top_right" nowrap></td>' +
		'</tr>' +
		'<tr>' +
		'<td class="ui_frame_left" nowrap></td>' +
		'<td>'
	);
}

function ui_frame_footer()
{
	emit
	(
		'</td>' +
		'<td class="ui_frame_right" nowrap></td>' +
		'</tr>' +
		'<tr><td class="ui_frame_bottom_left" nowrap></td><td class="ui_frame_bottom" nowrap></td><td class="ui_frame_bottom_right" nowrap></td></tr>' +
		'</table>'
	);
}

// Рамка каталога
function ui_frc_header(width, height)
{
	emit
	(
		'<table style="' + (width != null ? 'width:' + width + ';' : '') + (height != null ? 'height:' + height : '') + '">' +
		'<tr>' +
		'<td class="ui_frc_lt" nowrap></td>' +
		'<td class="ui_frc_t" nowrap>' +
		'<td class="ui_frc_rt" nowrap></td>' +
		'</tr>' +
		'<tr>' +
		'<td class="ui_frc_l" nowrap></td>' +
		'<td style="background:white">'
	);
}

function ui_frc_text()
{
	emit
	(
		'</td>' +
		'<td class="ui_frc_r" nowrap></td>' +
		'</tr>' +
		'<tr><td class="ui_frc_lb" nowrap></td><td class="ui_frc_b" nowrap></td><td class="ui_frc_rb" nowrap></td></tr>' +
		'<tr><td colspan="3" style="text-align:center;padding-top:4px;color:#b7b7b7;white-space:normal;">'
	);
}

function ui_frc_footer()
{
	emit
	(
		'</td></tr>' +
		'</table>'
	);
}

// Новые поступления
function ui_new_prod_header_open(url, vertical)
{
	ui_detail_window(url, vertical);
}

function ui_new_prod_header(img_path_small,sid,id,flag_new,title)
{
	
	var src = '';
	if(flag_new==1){
		src = "/tmpl/ui/new_prod_new.gif";
	}
	else{
		if(flag_new==2){
			src = "/tmpl/ui/exc_prod_exc.gif";
		}
	}
	emit
	(
		'<center><div style="display:block;width:165px;height:305px;background-image:url(/tmpl/ui/new_prod_bg.gif)" nowrap>' +
		'<table style="width:100%">' +
		'<tr><td style="height:210px" nowrap><a title="Подробнее..." href="." onclick="ui_new_prod_header_open(\'/?sid=' + sid + '&act=photo&pid='+ id + '\',true);return false">' +
		(flag_new!=3 ? '<img src="' + src + '" style="position:absolute;margin-left:6px;margin-top:5px;width:50px;height:50px">' : '') + '</a>' +
		'<a class="ui_new_prod_link" href="." onclick="ui_new_prod_header_open(\'/?sid=' + sid + '&act=photo&id='+ id + '\',true);return false" style="position:absolute;margin-left:142px;margin-top:188px;width:15px;height:15px" title="Подробнее..."></a>' +
		'<a title="' + title + '" href="." onclick="ui_new_prod_header_open(\'/?sid=' + sid + '&act=photo&id='+ id + '\',true);return false"><img src="' + img_path_small + '" alt="' + title + '" style="margin-left:9px;margin-top:8px;width:130px;height:195px">' +
		'</a></td></tr>' +
		'<tr><td style="height:76px;padding-left:5px;padding-right:22px;font-size:9px;color:gray;line-height:11px" nowrap>'
	)
}

function ui_new_prod_footer()
{
	emit
	(
		'</td></tr>' +
		'</table>' +
		'</div></center>'
	)
}

// Флешь каталога
function ui_catalog_flash(cat)
{
	emit('<span id="catalog_flash"></span>');
	var so = new SWFObject("/tmpl/ui/catalog.swf?" + mver, "catalog_swf_obj", "252px", "180px", "0", "#ffffff");
	so.addParam("wmode", "transparent");
	so.addParam("quality", "best");
	so.addParam("menu", "false");
	so.addParam("scale", "noscale");
	so.addVariable("cat", cat);
	so.write("catalog_flash");
}

function ui_detail_window(url, vertical)
{
	w = vertical ? 460 : 678;
	h = vertical ? 678 : 460;
	var x, y, w, h;
	x = Math.round((screen.availWidth - w) / 2);
	y = Math.round((screen.availHeight - h) / 2);
	var param = 'toolbar=0,status=0,scrollbars=0,resizable=0' +
		',left=' + x.toString() + 
		',top=' + y.toString() +
		',width=' + w.toString() + 
		',height=' + h.toString();
	wnd=open(url, 'detail' + Math.round(Math.random() * 4000000000), param);
	wnd.focus();
	return wnd;
}

// Предзагрузка
preload_image_array = new Array();

function preload_image(image_file)
{
	preload_image_array[preload_image_array.length] = new Image();
	preload_image_array[preload_image_array.length - 1].src = image_file;
}

preload_image('/tmpl/ui/x.gif');
preload_image('/tmpl/ui/body_bg.gif');
preload_image('/tmpl/ui/frame_pic.gif');
preload_image('/tmpl/ui/frame_top.png');
preload_image('/tmpl/ui/frame_top_left.png');
preload_image('/tmpl/ui/frame_top_right.png');
preload_image('/tmpl/ui/frame_left.png');
preload_image('/tmpl/ui/frame_right.png');
preload_image('/tmpl/ui/frame_bottom.png');
preload_image('/tmpl/ui/frame_bottom_left.png');
preload_image('/tmpl/ui/frame_bottom_right.png');
preload_image('/tmpl/ui/frame_bg.gif');
preload_image('/tmpl/ui/detail.gif');
preload_image('/tmpl/ui/body_bottom.png');
preload_image('/tmpl/ui/body_left_shadow.png');
preload_image('/tmpl/ui/body_right_shadow.png');
preload_image('/tmpl/ui/logo.gif');
preload_image('/tmpl/ui/nav_next.gif');
preload_image('/tmpl/ui/nav_next_h.gif');
preload_image('/tmpl/ui/nav_prev.gif');
preload_image('/tmpl/ui/nav_prev_h.gif');
preload_image('/tmpl/ui/nav_splitter.gif');
preload_image('/tmpl/ui/new_prod_bg.gif');
preload_image('/tmpl/ui/new_prod_link.gif');
preload_image('/tmpl/ui/new_prod_link_h.gif');
preload_image('/tmpl/ui/new_prod_new.gif');
preload_image('/tmpl/ui/header_left.jpg');
preload_image('/tmpl/ui/header_right.jpg');
preload_image('/tmpl/ui/body_left.jpg');
preload_image('/tmpl/ui/body_right.jpg');