var isIE4=(navigator.appVersion.indexOf("MSIE")!=-1 && parseFloat(navigator.appVersion)>=4)?true:false;

var isNN4=(navigator.appName=="Netscape" && parseFloat(navigator.appVersion)<5)?true:false;

var isNN6=(navigator.appName=="Netscape" && parseFloat(navigator.appVersion)>=5)?true:false;

var isOPERA=(navigator.appName=="Opera" && parseFloat(navigator.appVersion)>=7)?true:false;



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 SendLink(link_name) {

	window.open("/send/?link="+link_name, "SendLink", "scrollbars=0, resizable=1, width=370, height=230").focus();

}



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;

}







function openImage(image) {

	if (image) window.open("/popup.php?img="+image, "popupimage", "scrollbars=1, resizable=1, width=750, height=500").focus();

	return false;

}

 

function preload() {

	b=preload.arguments; 

	preload_images = new Array();

	for(i=0; i<b.length; i++) {

		preload_image = new Image;

		preload_image.src=b[i];

		preload_images[i]=preload_image;

	}

}







function menu_sw(x,name,turn) {

	td2=x.parentElement;

	tr=td2.parentElement;

	td1=tr.children(0);

	img=td1.children(0);

	img.src='/images/smenu/'+name+'_ico'+turn+'.gif';

}



function mout(myId,ext){

		s = document.getElementById('img'+myId).src;

		l = s.length;

		s = s.substr(0,l-5);



		document.getElementById('img'+myId).src = s+'.' + ext;

		

}

function mout_menu(myId){

	document.getElementById('smenu'+myId).style.backgroundColor = '#489442';

}

function mover_menu(myId){

	document.getElementById('smenu'+myId).style.backgroundColor = '#6DA968';

}

//____________________________________________________________________________



function menu_show(id){

	if (document.getElementById('submenu'+id).style.display == 'block') {

		document.getElementById('submenu'+id).style.display = 'none';

		document.getElementById('arr'+id).src = 'images/arr.gif';

	}

	else {

		document.getElementById('submenu'+id).style.display = 'block';

		document.getElementById('arr'+id).src = 'images/arr_act.gif';

	}





}



function Submenu(menuId,submenuId) {

	hide(submenuId);

	setDiv(submenuId, getDivX(menuId), 168);

//	x = getDivX(menuId);

//	y = getDivY(menuId)+38;

//	alert(x);

}

var timeout;

var DivSet='div355';

function ShowIt (parametr,div,div2) {

	if (parametr == true) {

		clearTimeout(timeout);hide();

		x=getDivX(div);

		y=getDivY(div);

		shiftY=getDivHeight(div);

		setDiv(div2,x,y+shiftY);

		DivSet=div2;

	}

	if (parametr == false) {

		timeout=setTimeout('hide()',100);

	}

}



function getDivHeight(divName){

	
		return document.getElementById(divName).offsetHeight;


}





// get X coordinate of element's upper-left corner

function getDivX( szDivName )

{

	

		return document.getElementById( szDivName ).offsetLeft;



}		



// get Y coordinate of element's upper-left corner

function getDivY( szDivName )

{


		return document.getElementById( szDivName ).offsetTop;



}



function setDiv(DivName,x,y){



 document.getElementById(DivName).style.left=x;

 document.getElementById(DivName).style.top=y+4;

 document.getElementById(DivName).style.display="block";


}



function hide(){

 if(isIE4){

 document.all[DivSet].style.display="none";

 }

 if(isNN4){

 document.layers[DivSet].display="none";

 }

 if(isNN6 || isOPERA){

 document.getElementById(DivSet).style.display="none";

 } 

}

// --------------------------------------------------
// ---- Отображение галереи на странице объекта -----
// --------------------------------------------------
var i=0;
var timer;
// --- Клик на кнопку Вперед/Назад
function showGallery(count, mode, rotate){
	i = parseInt(i) + parseInt(mode);
	if (rotate) {
		if (i>=count) i=0;
		if (i<0) i=count-1;
	} else {
		if (i>=count) i=count-1;
		if (i<0) i=0;
	}
	if (i>=0 && (i-1)<count) {
		if (document.getElementById('object_image') && par[i]) {
			document.getElementById('object_image').innerHTML = par[i];	
			document.getElementById('object_alt').innerHTML = alt[i];	
		}
	}

	changeImageArrows(count);
	return false;
}
function changeImageArrows(count){
	if (i==0) document.getElementById('link_prev').innerHTML = '<span class="prev" style="background: none">Предыдущая</span>';
	else document.getElementById('link_prev').innerHTML = '<a href="javascript:void();" class="prev" onclick="showGallery(' + count + ',-1); return false;" id="prev">Предыдущая</a>';	

	if ((i+1)>=count) document.getElementById('link_next').innerHTML = '<span class="next" style="background: none">Следующая</span>';	
	else document.getElementById('link_next').innerHTML = '<a href="javascript:void();" onclick="showGallery(' + count + ',1); return false;" class="next" id="next">Следующая</a>';
}
// --- Клие на превью
function SelectImage(type, image, bigimage, width, height, num, count){
	if (this.timer) stopGallery();
	showGallery(count, num-this.i, false);
}
// --- Клик на кнопку Play
function playGallery(count, timeout){
	// Надо вызывать функцию showGallery с какой-то задержкой
	this.timer = window.setInterval("showGallery("+count+", 1, true)", timeout);
	document.getElementById('play').src = '/images/controls_stop_active.gif';
	document.getElementById('play_link').onclick = function(){stopGallery(count); return false;};
}
// --- Клик на кнопку Stop
function stopGallery(count){
	window.clearInterval(this.timer);
	document.getElementById('play').src = '/images/controls_play_active.gif';
	document.getElementById('play_link').onclick = function(){playGallery(count); return false;};
}

function ShowMiddleImage(imagepath, largeimagepath, alt, page, pos, count) {
	this.i = pos;
	document.getElementById('object_alt').innerHTML = alt;
	var image = '';
	if (largeimagepath) {
		image += '<a href="' + largeimagepath + '" onclick="showGallery('+count+',1); return false;">';
	}
	image += '<img src="' + imagepath + '" border="0">';
	if (largeimagepath) {
		image += '</a>';
	}
	document.getElementById('object_image').innerHTML = image;
	document.getElementById('return_link').onclick = function() {ShowSmallImage(page); return false};
	document.getElementById('small_photo_div'+page).style.display = 'none';
	document.getElementById('middle_photo_div').style.display = 'block';
}

function ShowSmallImage(page) {
	document.getElementById('small_photo_div'+page).style.display = 'block';
	document.getElementById('middle_photo_div').style.display = 'none';
}

var _page = 1;
// Переход на заданную страницу галереи
function gotoPage(page) {
	document.getElementById('small_photo_div'+page).style.display = 'block';
	document.getElementById('small_photo_div'+_page).style.display = 'none';
	_page = page;
}
// --------------------------------------------------