if (window.self != window.top) window.top.location = window.self.location; 

// Nasty kludgy Soft-hyphen hack / v0.1 by yoz@yoz.com, 17/01/05
var doneshytags = false; // set to true once we've rebuilt the HTML
var counter = 0; // used for generating numeric IDs
var shys = new Array(); // used for storing refs to our Shy objects
var shyids = new Array(); // used for storing num IDs to Shy elements
function replacer(s, n, full) {
	var splitword = s.split(/\xAD/i);
	var newword = "";
	for (i=0;i<splitword.length;i++)
	{
		if (newword != "")
		{
			newword += "<span id='shy"+(++counter)+"'>- </span>";
			shyids.push(counter);
		}
		newword += "<span id='shy"+ (++counter) + "'>" + splitword[i] + "</span>";
	}
	return newword;	
}
function doShyTags() {
	var wordre = /[\w]+\xAD[\w\xAD]+/gi; // RE to match words with &shy;
	document.body.innerHTML = document.body.innerHTML.replace(wordre,replacer);
	for(i=0;i<shyids.length;i++)
	{
		shys.push(new Shy(shyids[i]));
	}
	doneshytags = true;
}
function Shy(n) {
	this.style = document.getElementById("shy"+n).style;
	this.next = document.getElementById("shy"+(n+1));
	this.prev = document.getElementById("shy"+(n-1));
	return this;
}
function shyreflow() {
	for (i=0;i<shys.length;i++)
	{
		shys[i].style.display = "";
	}
	for (i=0;i<shys.length;i++)
	{
		if (shys[i].next.offsetTop == shys[i].prev.offsetTop)
		{
			shys[i].style.display = "none";
		}
	}
}
// end yoz's script


function newWin(url, winWidth, winHeight) {
		var countWin;
		var idle;
		if (!winWidth) { winWidth = screen.availWidth; idle=true; }
		if (!winHeight) winHeight = screen.availHeight;
		PopupWin = window.open(url, 'newWin'+countWin, 'width='+winWidth+', height='+winHeight+',menubar=no,status=no,titlebar=no,toolbar=no,location=no,resizable=yes,scrollbars=no');
		if (idle) PopupWin.moveTo(0, 0);
		countWin++;
}

preloadImages = {
	init:		function() {
					var image_root = 'img';
					var imagesArray = new Array(
						'b-hdr-bg.gif',
						'mnu-bg-hv.gif'
					);
					for (var im = 0; im < imagesArray.length; im++) {
						imgpath = image_root + '/' + imagesArray[im];
						preloadImages.preload(imgpath);
					}
				},
	preload:	function(imgsrc) {
					if (document.images) {	
						var image = new Image();
						image.src = imgsrc;
					}
	}
}


calendar = {
	init:		function() {
					my_add = new Array();
					day = document.getElementById('fday');
					month = document.getElementById('fmonth');
					year = document.getElementById('fyear');
					if ((month.selectedIndex == 0) || (month.selectedIndex == 2) || (month.selectedIndex == 4) || (month.selectedIndex == 6) || (month.selectedIndex == 7) || (month.selectedIndex == 9) || (month.selectedIndex == 11)) {
						if (month.options.length < 31) {
							day.innerHTML = '';
							calendar.add(31);
						}
					}
					if ((month.selectedIndex == 3) || (month.selectedIndex == 5) || (month.selectedIndex == 8) || (month.selectedIndex == 10)) {
						day.innerHTML = '';
						calendar.add(30);
					}
					if (month.selectedIndex == 1) {
						day.innerHTML = '';
						febYear = year.options[year.selectedIndex].innerHTML;
						febDate = new Date (febYear,2,1);
						febDate = new Date (febDate - (24*60*60*1000));
						febDays = febDate.getDate();
						calendar.add(febDays);
					}
				},
	add:		function(endDays) {
					for (i = 0; i < endDays; i++) {
						my_add[i] = document.createElement('option');
						day.appendChild(my_add[i]);
						my_add[i].value = i+1;
						my_add[i].innerHTML = i+1;
					}
				}
}

gallery = {
	width: 	0,
	init: 	function() {
					if (document.getElementById('photo-parent')) {
						setInterval('gallery.check()', 1);
						td = document.getElementById('photo-parent').getElementsByTagName('td');
						table = document.getElementById('photo-parent').getElementsByTagName('table');
						count = 0;
						row = false;
					}
				},
	check: 	function() {
					if (document.body.clientWidth != gallery.width) {
						gallery.width = document.body.clientWidth;
						gallery.inline();
					}
				},
	inline: 	function() {
					document.getElementById('photo-parent').style.visibility = 'hidden';

					for (var i = 0; (table.item(i)); i++) td.item(i).style.height = 'auto';
					for (var i = 1; (table.item(i)); i++) if ((row == false) && (table.item(i).offsetTop == table.item(i-1).offsetTop)) count++; else row = true;
					count++;

					for (var i = 0; (td.item(i)); i=i+count) {	
						myHeight = 0;	
						for (var o = 0; (td.item(i+o) && o < count); o++) if (td.item(i+o).offsetHeight > myHeight) myHeight = td.item(i+o).offsetHeight;
						for (var o = 0; (td.item(i+o) && o < count); o++) td.item(i+o).style.height = myHeight + 'px';
					}
					document.getElementById('photo-parent').style.visibility = 'visible';
				}
}

rollover = {
	init: 	function() {
					if (document.getElementById('rollover')) {
						rlvA = document.getElementById('rollover').getElementsByTagName('a');
						for (var r = 0; (rlvA.item(r)); r++) {
							rlvA.item(r).onmouseover = rollover.over;
							rlvA.item(r).onmouseout = rollover.out;
							for (var j = 0; (rlvA.item(r).getElementsByTagName('img').item(j)); j++) {
								ovrsrc = rlvA.item(r).getElementsByTagName('img').item(j).src.replace(/([\w\-\/\.]+)\.(\w+)/, "$1-ovr.$2");
								preloadImages.preload(ovrsrc);
							}
						}
					}
	},
	over: 	function() {
					for (var j = 0; (this.getElementsByTagName('img').item(j)); j++) {
						this.getElementsByTagName('img').item(j).src = this.getElementsByTagName('img').item(j).src.replace(/([\w\-\/\.]+)\.(\w+)/, "$1-ovr.$2");
					}
	},
	out: 		function() {
					for (var j = 0; (this.getElementsByTagName('img').item(j)); j++) {
						this.getElementsByTagName('img').item(j).src = this.getElementsByTagName('img').item(j).src.replace(/([\w\-\/\.]+)\-ovr([\w+\.]+)/, "$1$2");
					}
	}
}

formCheck = {
	init:		function() {
					for (var i = 0; i < document.forms.length; i++) {
						document.forms[i].onreset = function() {
							if (confirm('Вы действительно хотите очистить все поля?')) return true
								else return false;
						}
					}
				}
}


function init() {
	rollover.init();
	formCheck.init();
	gallery.init();
}

if (loaded) init();
loaded = true;

