var agent=navigator.userAgent.toLowerCase();
var ver=navigator.appVersion;
var isIE4 = (agent.indexOf("msie")>-1);

styles();

function MM_findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

var ie=(document.all && document.all.item && !window.opera)?1:0;

function changemapover(map)
{
	var obj=MM_findObj(map); 
	obj.src = "images/menu/pix_.gif";
}

function changemapout(map)
{
	var obj=MM_findObj(map); 
	obj.src = "images/menu/pix.gif";
}

function menuover(menuid, over, s)
{
	obj = MM_findObj(menuid);
	obj.background = '../images/'+s+'menu/'+over+'.gif';
}

function changewidth()
{
	width = document.body.clientWidth;
	var obj = MM_findObj("content");
	var obj1 = MM_findObj("tabl");
	if (width-280-10<300) {if (obj) obj.style.width = 300; if (obj1) obj1.style.width = 300;}
	else if (width-280-10>700) {if (obj) obj.style.width = 700; if (obj1) obj1.style.width = 700;}
	else {if (obj) obj.style.width = width-280-10; if (obj1) obj1.style.width = width-280-10;}
}

function openImage(image) {
	window.open("/popup.php?img="+image, "popupimage", "scrollbars=1, resizable=1, width=286, height=72").focus();
}

var last_content_id1 = 'bigphoto0';
var m, t;
function GetCont1(id){
	if (id == last_content_id1) return;
	m = new Array(0,100); t = new Array();
	if (t[0]) {
		clearTimeout(t[0]);
		document.getElementById(last_content_id1).style.display = 'none';
	}
	nextImage(last_content_id1, id);
	last_content_id1 = id;
}
var last_content_id2 = 'bigphoto20';
function GetCont2(id){
	if (id == last_content_id2) return;
	m = new Array(0,100); t = new Array();
	if (t[0]) {
		clearTimeout(t[0]);
		document.getElementById(last_content_id2).style.display = 'none';
	}
	nextImage(last_content_id2, id);
	last_content_id2 = id;
}

function nextImage(_a1, _a2) {
	try {
		if (document.getElementById(_a1)) var obj1 = document.getElementById(_a1);
		else {
			var obj1 = _a1;
			_a1 = obj1.id;
		}
		if (document.getElementById(_a2)) var obj2 = document.getElementById(_a2);
		else {
			var obj2 = _a2;
			_a2 = obj2.id;
		}
		m[0]+=5; m[1]-=5;
		setOpacity(m[1]/100, obj1);
		setOpacity(m[0]/100, obj2);
		obj2.style.display = 'block';
		t[0] = setTimeout("nextImage('" + _a1 + "', '" + _a2 + "')", 1);
		if (m[0]>98) {
			clearTimeout(t[0]);
			obj1.style.display = 'none';
		}
	} catch (e) {
		if (e.description) alert(e.description); else alert(e);
	}
}

// Установка прозрачности
function setOpacity(nOpacity, elem) {
	if (isIE4) {
		nOpacity *= 100;	
	    var oAlpha = elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
		if (oAlpha) oAlpha.opacity = nOpacity;
		else elem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";
	} else {
		try {
			elem.style.opacity = nOpacity;
			elem.style.MozOpacity = nOpacity;
			elem.style.KhtmlOpacity = nOpacity;
		} catch (e) {}
	}
}

function styles(){
document.write('<style>div.pro{display:none}</style>');
}

function addstyle(){

document.write( "<style>#tooltip {display: none;} </style>" );

}
function ShowMail(user, domain1, domain2) {
	var email = user+'&#64;'+domain1+'&#46;'+domain2;
	if (ShowMail.arguments[3]) name = ShowMail.arguments[3];
	else name = email;
	document.writeln('<a href="mailto:'+email+'">'+name+'</a>');
}

function showBanner() {
	if (document.getElementById('popupBanner').style.display = 'block') 
		{
		document.getElementById('popupBanner').style.display = 'none';
	}
	else {
		document.getElementById('popupBanner').style.display = 'none';
	}
}

function getClientWidth(){
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function showCenterBanner(img_width){
    if (!document.getElementById("popupBanner")) return;
	client_width = getClientWidth();
	left = (client_width/2) - (img_width/2);	
	document.getElementById("popupBanner").style.left = left;
	document.getElementById('popupBanner').style.display = 'block'
}

function ShowInterImage(inter, src_old, src_new) {    
    document.getElementById('img').src = "/files/images/" + src_new;
    var link = document.getElementById('inter_link');
    if (inter == true) {
        // Фото в интерьере
        link.childNodes[0].src = '/images/popup_look_to_interer.png';    
        link.childNodes[0].alt = 'Посмотреть основное изображение';
        link.href = "javascript:ShowInterImage(false, '" + src_new + "', '" + src_old + "')";
    }
    else {
        // Основное фото
        link.childNodes[0].src = '/images/popup_look_to_interer0.png';    
        link.childNodes[0].alt = 'Посмотреть в интерьере';
        link.href = "javascript:ShowInterImage(true, '" + src_new + "', '" + src_old + "')";
    }
}

function imgHoverSpan() {
	$('.catalogPic li .content span').each(function(){
		var spanHeight = $(this).innerHeight();
		$(this).css('top', (92 - spanHeight) / 2);
	});
}