var scrollTO;

function setIcons(inc){
	clearTimeout(scrollTO);
	if((startIcon+inc)>=0 && (startIcon+inc+cells)<=top_icons.length){
		startIcon = startIcon+inc;
		for(i=0;i<cells;i++) document.getElementById('iCell'+i).innerHTML = '<a href="'+top_icons[i+startIcon][2]+'" title="'+top_icons[i+startIcon][1]+'"><img src="'+top_icons[i+startIcon][0].src+'" class="pic_touricon"></a><br/><a href="'+top_icons[i+startIcon][2]+'" title="'+top_icons[i+startIcon][1]+'">'+top_icons[i+startIcon][1]+'</a>';
		if(inc!=0) scrollTO=setTimeout("setIcons("+ inc + ")",  100);
	}
}

function viewPage(page,allpages){
	for(i=1;i<allpages+1;i++) document.getElementById('prices'+i).style.display = "none";
	document.getElementById('prices'+page).style.display = "block";
}

function showText(){
	document.getElementById('fulltext').style.display = (document.getElementById('fulltext').style.display == 'block')? "none" : "block";
	document.getElementById('fulltextlink').innerHTML = (document.getElementById('fulltext').style.display == 'block')? "Скрыть текст" : "Показать весь текст";
}

function createPictureWindow(_pic,_width,_height) {
	wTop = (screen.height-_height)/3;
	wLeft = (screen.width-_width)/2;
	WinFeatures = "top="+wTop+",left="+wLeft+",width="+_width+",height="+_height+",maximize=no,minimize=no,Status=no,toolbar=no,menubar=no,location=no,directories=no,scrollbars=no,resize=no";
	_newPicture = window.open("/zoom.php?id="+_pic+"&dir=pictures","frontendPictureWindow",WinFeatures);
}

function createPopup(file){
	var p = Math.ceil(Math.random()*10000);
	var q = Math.ceil(Math.random()*p);
	windowName = p+'X'+p+p*q;
	WinFeatures = "top=50,left=50,width=100,height=100,Status=no,toolbar=no,menubar=no,location=no,directories=no,scrollbars=yes";
	w = window.open(file,windowName,WinFeatures);
}

function createDynamicWindow(Path,Width,Height,Title)
{
	var p = Math.ceil(Math.random()*10000);
	var q = Math.ceil(Math.random()*p);
	windowName = p+'X'+(Width*p)+(Height*q);
	WinFeatures = "top="+(screen.height-Height)/2+",left="+(screen.width-Width)/2+",width="+Width+",height="+Height+",Status=no,toolbar=no,menubar=no,location=no,directories=no,scrollbars=no";
	w = window.open("",windowName,WinFeatures);
	w.document.open();
	w.document.write('<head><title>&quot;'+Title+'&quot;</title><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"></head>');
	w.document.write("<body bgcolor='#FFFFFF' leftmargin='0' topmargin='0' marginwidth='0' marginheight='0'><img src='"+Path+"' height='"+Height+"' width='"+Width+"' alt='&quot;"+Title+"&quot;'></body>"); 
	w.document.close();
}

function createDescriptionWindow(_file,_width,_height)
{
	wTop = (screen.height-_height)/3;
	wLeft = (screen.width-_width)/2;
	WinFeatures = "top="+wTop+",left="+wLeft+",width="+_width+",height="+_height+",maximize=no,minimize=no,Status=no,toolbar=no,menubar=no,location=no,directories=no,scrollbars=yes,resize=no";
	_newDescription = window.open(_file,"frontendDescriptionWindow",WinFeatures);
}

function message(form) {
	formElement = document.forms[form].elements;
	isFilled = true;
	for(j=0; j<formElement.length; j++) if(formElement[j].value == '') isFilled = false;
	if (!isFilled)  {
		alert('Все поля формы должны быть заполнены!'); return false;
	}
	else return true;
}

function checkFields(form) {
	f1 = document.forms[form].name.value;
	f2 = document.forms[form].email.value;
	f3 = document.forms[form].attachment.value;
	
	if (f1 == "") {
		alert("Введите, пожалуйста, Ваше имя");
		return false;
	}
 	else if ((f2 == "") || (f2.indexOf('@')<0) || (f2.indexOf('.')<0)) {
		alert("Введите, пожалуйста, корректный e-mail");
		return false;
	}
	else if (f3 == "") {
		alert("Выберите, пожалуйста, Ваше фото");
		return false;
	}
 	else return true;
}

var PhotoGal = 
{
	init:function()
	{
		if(!$('PhotoGallery') || !$('GalleryLinks')) return;
		$('PhotoGallery').addEvent('click', this.clickHandler);
	},
	clickHandler:function(event)
	{
		event = new Event(event);
		event.preventDefault();
		var firstPic = $('GalleryLinks').getElement('a');
		Lightbox.click(firstPic);
	}
}

window.addEvent('domready', PhotoGal.init.bind(PhotoGal));

