var agent = navigator.userAgent.toLowerCase();
var major = parseInt(navigator.appVersion);
var minor = parseFloat(navigator.appVersion);

var isNN = ((agent.indexOf('mozilla') != -1) && ((agent.indexOf('spoofer') == -1) && (agent.indexOf('compatible') == -1)));
var isNN4 = (isNN && (major == 4));
var isNN6 = (isNN && (major >= 5));

var isOPERA = agent.indexOf("opera")>-1 && window.opera;
var isIE4 = (agent.indexOf("msie") != -1 && !isOPERA);

var flash_version = 0; // Версия флеш-проигрывателя
var fz=0;
if (isIE4){
	ie = 1;
	for (var i=3; i<7; i++){
		try {
			if (eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash."+i+"')")) flash_version = i;
		}
		catch (e) {}
	}
}
if ((isOPERA || isNN || isNN4 || isNN6) && (navigator.plugins)){
	for (var i=0; i<navigator.plugins.length; i++){
		if (navigator.plugins[i].name.indexOf("Flash")> -1){
			fz = parseInt(navigator.plugins[i].description.charAt(16));
			if (fz > flash_version) flash_version=fz;
		}
	}
}
	
//-------------------------------------------------------------------//
function rusoft() {
  window.open('http://www.rusoft.ru');
}

function ShowHTTP(href, display, target, style, title) {
	if (display == '') display = href;
	if (target == '') target = '_blank';
	document.writeln('<a href="'+href+'" target="'+target+'" title="'+title+'" style="'+style+'">'+display+'</a>');
}

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 openImage(image, ev) {
    var ev = window.event || ev;
    if (ev == undefined) {
	   if (image) window.open("/popup.php?img="+image, "popupimage", "scrollbars=0,resizable=0,width=100,height=100,location=0,menubar=0,status=0,toolbar=0").focus();
	   return false;
    }
    var obj = ev.srcElement || ev.target;
    if (obj.tagName == 'IMG') obj = obj.parentNode;
    return hs.expand(obj);
}

function openPhoto(id) {
	if (id) window.open("/popupf?id="+id, "popup", "scrollbars=1, resizable=1, width=700, height=450").focus();
}

function imgOpen(imgURL,imgWidth,imgHeight,Title) {
	var imgWndw=window.open('','_blank','width='+imgWidth+',height='+
	imgHeight+',toolbar=no,menubar=no,location=no,status=no,'+
	'resizable=yes,scrollbars=no');
	var imgTitle=(Title)?Title:imgURL+": "+imgWidth+'x'+imgHeight;
	with (imgWndw.document){
		open();
		write('<ht'+'ml><he'+'ad><ti'+'tle>'+imgTitle+'</ti'+'tle>'+
		'</he'+'ad><bo'+'dy leftmargin="0" '+
		' topmargin="0" '+
		'rightmargin="0" bottommargin="0" marginwidth="0" '+
		'marginheight="0"><img src="'+imgURL+'" width="'+imgWidth+
		'" height="'+imgHeight+'" border="0" alt="'+imgTitle+
		'"></bo'+'dy></ht'+'ml>');
		close();
	}
	return false
}

function OpenPopup(src) {
	if (arguments[1]) popup_name = arguments[1];
	else popup_name = 'popup';
	if (arguments[2]) popup_width = arguments[2];
	else popup_width = 500;
	if (arguments[3]) popup_height = arguments[3];
	else popup_height = 400;
	window.open(src, popup_name, 'toolbar=no,location=no,status=no,menubar=no,resizable=yes,directories=no,scrollbars=yes,width='+popup_width+',height='+popup_height).focus();
	return false
}

function SetCookie(sName, sValue){
	document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 2070 23:59:59 GMT; path=/;";
}

function changeImage(id, img) {
	document.getElementById(id).src = img;
}

function insertFlash(v, fl, gif, lnk, w, h, id){
	if (flash_version >= v) {
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + w + '" height="' + h + '" id="flash' +  id + '" align="center"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + fl + '"><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" /><embed src="' + fl + '" wmode="transparent" quality="high" width="' + w + '" height="' + h + '"></embed></object>');
	} else if (gif != '') {
		document.write("<a href='"+lnk+"'><img src='"+gif+"' width='" + w + "' height='" + h + "' border=0></a>");
	}
}


// --------------------------------------------------
// ---- Отображение галереи на странице объекта -----
// --------------------------------------------------
// пропорциональное уменьшение размеров картинок превью
function imgResize(id)
{
    var image = document.getElementById(id);

    var width = image.width;
    var height = image.height;
    var prop = image.height/image.width;
    
    var size = 135;

    if (width > size || height > size)
    {
        height = prop*size;
        width = size;
        
        if (height > size)
        {
            height = size;
            width = size/prop;
        }
	}
    image.width = width;
    image.height = height;
}

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(0);" 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(0);" 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) {
	this.i = pos;
	document.getElementById('object_alt').innerHTML = alt;
	var image = '';
	if (largeimagepath) {
		image += '<a href="' + largeimagepath + '" onclick="openImage(\'' + largeimagepath + '\'); 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 = 0;
// Переход на заданную страницу галереи
function gotoPage(page) {
	document.getElementById('small_photo_div'+page).style.display = 'block';
	document.getElementById('small_photo_div'+_page).style.display = 'none';
	_page = page;
}

// классы инпутам
function setInputClass() {
	var input = document.getElementsByTagName('input');
	for (var i = 0; i <= input.length - 1; i++) {
		if (input[i].type == 'text') {
			input[i].className = 'text';
		}
		
		if (input[i].type == 'checkbox' || input[i].type == 'radio') {
			input[i].className = 'check';
		}
	}
}