function big_foto(w,h,win_name,left)
{
	var url='';
	var win_name;
	if (!win_name) win_name='big';
	if (!left) left=100;
	var features='menubar=no,scrollbars=yes,status=no,resizable=yes,top=8,left='+left+',width='+w+',height='+h;
	window.open(url,win_name,features);
}

function trim(value){return value.replace(/(^\s*)|(\s*$)/g, "")}

function go_away() {
	JsHttpRequest.query(
		'/guest.php',
		{
			'fio': $('#fio').val(),
			'email': $('#email').val(),
			'message': $('#message').val(),
			'code': $('#code').val()
		},
		function(result, errors) {
			$('#div_errors').html(errors);
			if (result) {
				//clearTimeout(send_error);
				//document.getElementById('go_').disabled=false;
				if (result['res']==1) {
					alert('Сообщение успешно отправленно');
					$('#fio').val('');
					$('#email').val('');
					$('#message').val('');
					$('#code').val('');
					$('.sec').text(result['rnd']); //
				}
				if (result['res']==2) {
					alert('Не все поля заполнены или заполнены неверно');
				}
				if (result['res']==3) {
					alert('Неверный защитный код');
				}
            }
		},
		true
	);
}

var item=0,items;
function change_item(val)
{
	var item_=item;
	if(val=='prev') item_--;
	if(val=='next') item_++;
	if ((item_>=0)&&(item_<=items-1))
	{
		item=item_;
		getItem=scr.getItems()[item];
		getItem.id='bfg'+item;
		//$(document).attr('location',$('#'+getItem.id+' > a').attr('href'));
		return $('#'+getItem.id+' > a').attr('href');
	} else return document.location;
}

function showTime()
{
	speed=1000;
	$('#old_top_img').attr('src', $('#top_img').attr('src'));
	top_imgi++;
	if (top_imgi>top_imgc) top_imgi=0;
	$("#top_img").fadeTo(speed,0);
	setTimeout(function(){$('#top_img').attr('src',imgs[top_imgi].src);$('#top_img').fadeTo(speed,1);},speed);
}

$(document).ready(function()
{

	$("input, textarea").focus(function()
	{
		if ($(this).attr('type')=="text"||$(this).attr('type')=="password"||$(this).attr('type')=="textarea")
		{
			if (!/str/.test($(this).attr('name')) && ($(this).attr('value')=="Логин" || $(this).attr('value')=="*****")) $(this).attr('value','');
			if ($(this).attr('value')=='введите запрос...') $(this).attr('value','');
			$(this).addClass('over');
		}
	});

 	$("input, textarea").blur(function()
	{
		if ($(this).attr('type')=="text"||$(this).attr('type')=="password"||$(this).attr('type')=="textarea")
		{
			if ($(this).attr('name')=='q' && $(this).attr('value')=='') $(this).attr('value','введите запрос...');
			$(this).removeClass('over');
		}
	});

	$("h1").each(function(){$(this).html('<span style="position:absolute;margin:1px 0px 0px 1px;color:white;width:530px;">'+$(this).text()+'</span>'+'<span style="position:relative">'+$(this).text()+'</span>');});
	$(".zag").each(function(){$(this).html('<span style="position:absolute;margin:1px 0px 0px 1px;color:white;width:200px;">'+$(this).text()+'</span>'+'<span style="position:relative">'+$(this).text()+'</span>');});
	
	if ($("div.scrollable").length)
	{
		$("div.scrollable").scrollable({
			vertical:true,
			size:5,
			speed:555,
			//onSeek:mmm,
			clickable: false
		});

		scr=$("div.scrollable").scrollable();
		
		$("div.scrollable > div.items > div").attr("id", function(arr){return arr;}).each(function(){if($(this).attr('sc')=='current'){item=parseInt(this.id);scr.click(item);}});

		items=scr.getSize()-1;
		if (item==0 || item>0) $("#FotoAll").html(''+(item+1)+' из '+(items)+'');
		
		

		//api.next();
		/* 		for (i=0;i<$("div.scrollable > div.items > div").length;i++)
		{
			if ($("div.scrollable > div.items > div").eq(i).attr('class')=='act')
			{
				sc = $("div.scrollable").scrollable();
				sc.click(i);
			}
		} */
		
		//setTimeout(function(){alert();}, 2000);
		/* $("div.scrollable > div.items > div").each(function(){
			i++;
			if ($(this).attr('class')=='active')
			{
				//scrolable = $("div.scrollable").scrollable();
				//scrolable.click(i);
				alert(i);
			}
		
		}); */
		
		//var ind=0,arr=0;
		//alert(ind);
		
		//alert(ind);
		//api.click(ind);
		//setTimeout(function(){api.click(ind);}, 1000);
		
		
		//alert($("div.scrollable > div.items > div.active").);
		
	}
	
	if ($(".dop_foto > div > img").length)
	{
		$(".dop_foto > div > img").css('cursor','pointer');
		$(".dop_foto > div > img").click(function(){$('#BigBadaBoom').attr('src',$(this).attr('src').replace('small','big'));});
	}
	
	//
	if ($("#top_img").length && imgs[0])
	{
		$("#top_img").before("<img id='old_top_img'>");
		$('#old_top_img').attr('width',590);
		$('#old_top_img').attr('height',333);
		$('#old_top_img').attr('src','/img/spacer.gif');
		$('#old_top_img').css('position','absolute');
		$('#old_top_img').css('background','url(/img/loading.gif) no-repeat center');
		
/* 	for (var im=0;im<=imgs.length-1;im++)
		{
			$('#top_img').attr('src', imgs[im].src).load(function(){
				imgs[im].ok=1;
			});
		} */
/* 		for (var im in imgs)
		{
			if (typeof imgs[im]=='object')
			{
				//alert(im);
				$('#top_img').attr('src',imgs[im].src).load(function(){
					if (im==imgs.length-1) alert(im);
				});
			}
		} */
		//$('img').bind('load', function(){ 
			//alert(1);
		//});
		var n = $('.img1').length-1;
		$('.img1').each(function(ir){
			//alert(ir+' == '+n);
			//$(this).bind('load',function(){
				if(ir == n) 
				{
					setInterval("showTime()",5000);
				}
			//});
		});
		
		//if (imgs.length>1) 
	}

	function mmm()
	{
		//$("#FotoPageNav").html(sc.getPageIndex()+1);
		//var maxScroll = $(".items").height()-777;
		//var maxScroll =$(".scrollable").attr("scrollHeight") - $(".scrollable").height();
		//spst1 = $(".scrollable").attr('scrollTop');
		//$(".items").height() - $(".scrollable").attr("scrollHeight");
		//kkk = (maxScroll / 777);
		//val = ($(".scrollable").attr("scrollHeight")-777) / kkk-(158/kkk);
		//val = 777 - (maxScroll/777);
		
		//$('#errors').text(val);
		//$('#slider-vertical').slider('value', val);
	}
/* 	
	if ($("#slider-vertical").length)
	{
		$("#slider-vertical").slider({
			animate: true,
			orientation: "vertical",
			min: 1,
			max: 777,
			value:777,
			change:handleSliderChange,
			slide: handleSliderSlide
		});
		function handleSliderChange(e, ui)
		{
			var maxScroll = $(".scrollable").attr("scrollHeight") - $(".scrollable").height();
			var spst = maxScroll - (ui.value * (maxScroll / 777));
			$(".scrollable").attr({scrollTop: spst });
		}
		function handleSliderSlide(e, ui)
		{
			var maxScroll = $(".scrollable").attr("scrollHeight") - $(".scrollable").height();
			spst = maxScroll - (ui.value * (maxScroll / 777));
			$(".scrollable").attr({scrollTop: spst });
			
			$('#errors').text(spst + ' = ' + maxScroll +' - '+ ui.value + ' * ' + maxScroll +' / '+ 777);
		}
	} */


	//var api = $("div.scrollable").scrollable();
	//api.click(function(){
//		alert($(this).getIndex());
//	});
	//alert(api.getIndex());
/*	setTimeout(function(){api.seekTo(1);}, 1000);
	api.vertical='true';
	api.size=3;
	api.next();
	//api.seekTo(5); */
	
	//$('.sc').jScrollPane({animateTo:true, showArrows:true, scrollbarWidth:11});
	
/* 	$('#left_pane li a').click(function(event){
		var target = $('#right_pane a[name='+$(this).attr('href').replace('#','')+']');
		var cont = $('#right_pane .scrollable');
		var p = target.parent();
		var h = parseInt(p[0].offsetTop);
		cont[0].scrollTo(h);
		event.preventDefault();
	}); */
	
	/*
	$("div").attr("id", function (arr) {
	  return "div-id" + arr;
	})
	.each(function () {
	  $("span", this)
	  .html("(ID = '<strong>" + this.id + "</strong>')");
	});
	*/
});