var ua = navigator.userAgent.toLowerCase();
var isOpera = (ua.indexOf('opera')  > -1);
var isIE = (!isOpera && ua.indexOf('msie') > -1);
 
function getDocumentHeight() {
  return Math.max(document.compatMode != 'CSS1Compat' ? document.body.scrollHeight : document.documentElement.scrollHeight, getViewportHeight());
}
 
function getViewportHeight() {
  return ((document.compatMode || isIE) && !isOpera) ? (document.compatMode == 'CSS1Compat') ? document.documentElement.clientHeight : document.body.clientHeight : (document.parentWindow || document.defaultView).innerHeight;
}


//---
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  

  return true
}
//--

function onRollOverMenu(id) {

	document.getElementById('id_m_'+id).src = "/_img/m_" + id + "a.png";
}

function onRollOutMenu(id) {

	document.getElementById('id_m_'+id).src = "/_img/m_" + id + ".png";
}

var aPhotos 	= Array();
var iThisPhoto 	= 0;

function photo_show(id) {

	iThisPhoto = id;
	photo_select();
	
	document.getElementById('id_photo_show').style.height = getDocumentHeight();
	document.getElementById('id_photo_show').style.display = 'block';
}

function photo_hide(id) {
	
	document.getElementById('id_photo_show').style.display = 'none';
}

function photo_select() {

	document.getElementById('id_photo').src = "/img/clinic/" + aPhotos[iThisPhoto];
	
	if (0 == iThisPhoto) {
		document.getElementById('id_photo_prev').innerHTML = '<img src="/_img/photo_prev_no.png" alt="Предыдущее" />';
	} else {
		document.getElementById('id_photo_prev').innerHTML = '<a href="javascript:photo_prev();"><img src="/_img/photo_prev.png" alt="Предыдущее" /></a>';
	}

	if (aPhotos.length - 1 == iThisPhoto) {
		document.getElementById('id_photo_next').innerHTML = '<img src="/_img/photo_next_no.png" alt="Следующее" />';
	} else {
		document.getElementById('id_photo_next').innerHTML = '<a href="javascript:photo_next();"><img src="/_img/photo_next.png" alt="Следующее" /></a>';
	}
}

function photo_prev() {
	
	if (iThisPhoto > 0) {
		iThisPhoto--;
	}
	
	photo_select();
}

function photo_next() {
	
	if (iThisPhoto < aPhotos.length - 1) {
		iThisPhoto++;
	}
	
	photo_select();
}

function photo_show_one(sPath, id) {

	document.getElementById('id_photo').src = sPath;
	
	document.getElementById('id_photo_prev').innerHTML = '';
	document.getElementById('id_photo_next').innerHTML = '';
	
	var top = tempY - 250;
	document.getElementById('id_photo_show').style.padding = top + "px 0px 0px 0px";
	document.getElementById('id_photo_show').style.height = getDocumentHeight();
	document.getElementById('id_photo_show').style.display = 'block';
}
