var timerBig;
function setBigImg(id, clear) {
	if(id==lastBigImg) return;

	if(clear==1) {
		clearTimeout(timerBig);
		timerBig = setTimeout("setTimerBigImg()", motiveTime*1000);
	}
	
	$("#sq_"+lastBigImg).toggleClass("act");

/*
	$("#motive_" + lastBigImg).hide();
	$("#imgAnons_" + lastBigImg).hide();
*/
	$("#motive_" + lastBigImg).fadeOut(300)
	$("#imgAnons_" + lastBigImg).fadeOut(300)

	$("#sq_"+id).toggleClass("act");

/*
	$("#motive_" + id).show();
	$("#imgAnons_" + id).show();
*/
	$("#motive_" + id).fadeIn(300);
	$("#imgAnons_" + id).fadeIn(300);
	
	lastBigImg = id;

}
function setTimerBigImg() {
	var next = lastBigImg+1;
	if(next==6) next = 1;
	setBigImg(next, 0)
	clearTimeout(timerBig);
	timerBig = setTimeout("setTimerBigImg()", motiveTime*1000);
}


//////////////////////////////////////////////////////////////////////////////

function setTimerBigImgThree(toc_id) {
//	alert(toc_id)
	var next = lastBigImgThree[toc_id]+1;
	if(next==4) next = 1;
	setBigImgThree(next, 0, toc_id)
	clearTimeout(timerBigThree[toc_id]);
	timerBigThree[toc_id] = setTimeout(function(){setTimerBigImgThree(toc_id)}, motiveTimeThree[toc_id]*1000);
}

var timerBigThree = new Array();
var motiveTimeThree = new Array();
var lastBigImgThree = new Array();

function setBigImgThree(id, clear, toc_id) {
	if(id==lastBigImgThree[toc_id]) return;

	if(clear==1) {
		clearTimeout(timerBigThree[toc_id]);
		timerBigThree[toc_id] = setTimeout("setTimerBigImgThree()", motiveTime*1000);
	}
	
	$("#sq_" + toc_id + "_" + lastBigImgThree[toc_id]).toggleClass("act");

//	$("#motive_" + toc_id + "_" + lastBigImgThree[toc_id]).fadeOut(300)
	$("#imgAnons_" + toc_id + "_" + lastBigImgThree[toc_id]).fadeOut(300)

	$("#sq_" + toc_id + "_" + id).toggleClass("act");

//	$("#motive_" + toc_id + "_" + id).fadeIn(300);
	$("#imgAnons_" + toc_id + "_" + id).fadeIn(300);
	
	lastBigImgThree[toc_id] = id;

}
//////////////////////////////////////////////////////////////////////////////



function showFormGuestVisit() {
	if ($("#formGuestVisit").css("display") == "none" ) {
		$("#formGuestVisit").show();
		$(".banner-ind").css({
			visibility: "hidden"
		});
	}
	else {
		$("#formGuestVisit").hide();
		$(".banner-ind").css({
			visibility: "visible"
		});
	}
}

function showHideBlock(id) {
	if ($("#"+id).css("display") == "none" ) {
		$("#"+id).show();
	}
	else {
		$("#"+id).hide();
	}
}


$(document).ready(function(){

//Gallery
	
	//shadow
		var shadow = $('#shadow');
		var marginLeft;
		var marginTop;
		var shadowHeight = $(document).height();
		$('#shadow').css('height',shadowHeight+'px');
	
	$('.pro_gallery .image').click(function(){
		
		var obj = $(this).parent().children('.bigIt');
		shadow.fadeIn('fast');		
		marginLeft = ($(window).width() - obj.width())/2 + 'px';
		marginTop = (($(window).height() - obj.height())/2 + $(window).scrollTop()) + 'px';
		$('#box').css('top', marginTop);
		$('#box').css('left', marginLeft); 
		var clon = obj.clone();
		$('#box').append(clon);
		clon.css('display','block');
		$('#box').delay('300').fadeIn('fast');
		$(this).parent().attr('current','1');	
	});
	
	$('#shadow').click(function(){
		$('#box').fadeOut('fast', function(){
			$(this).empty();
		}) ;
		$('#shadow').delay('300').fadeOut('fast');
		$('.pro_gallery li').attr('current','0');
	
	});
	
	$('.close img').live('click',function(){
		$('#box').fadeOut('fast', function(){
			$(this).empty();
		}) ;
		$('#shadow').delay('300').fadeOut('fast');
		$('.gallery .it').attr('current','0');	
		
	});
	
	$('.next_1').live('click',function(){
		var elm = $(".pro_gallery li[current='1']");
		var next_elm = elm.next('li');
		var next_elmImg = elm.next('li img');
		if(next_elm.size() == 0)
		{
			$(this).addClass('no');	
			return;
		}
		$('#box').css('display','none') ;
		$('#box').empty();
		marginLeft = ($(window).width() - next_elm.children('.bigIt').width())/2 + 'px';
		marginTop = (($(window).height() - next_elm.children('.bigIt').height())/2 + $(window).scrollTop()) + 'px';
		$('#box').css('top', marginTop);
		$('#box').css('left', marginLeft); 
		var clon = next_elm.children('.bigIt').clone();
		$('#box').append(clon);
		clon.css('display','block');
		$('#box .im').css('display','none');
	   	$('#box').css('display','block') ;
		$('#box .im').fadeIn('normal')
		elm.attr('current', '0');
		next_elm.attr('current','1');
	});
	
	$('img#prev').live('click',function(){
		var elm = $(".pro_gallery li[current='1']");
		var prev_elm = elm.prev('li');
		if(prev_elm.length == 0)
		{
			$(this).addClass('no');	
			return;
		}
		$('#box').css('display','none') ;
		$('#box').empty();
		marginLeft = ($(window).width() - prev_elm.children('.bigIt').width())/2 + 'px';
		marginTop = (($(window).height() - prev_elm.children('.bigIt').height())/2 + $(window).scrollTop()) + 'px';
		$('#box').css('top', marginTop);
		$('#box').css('left', marginLeft); 
		var clon = prev_elm.children('.bigIt').clone();
		$('#box').append(clon);
		clon.css('display','block');
		$('#box .im').css('display','none');
	   	$('#box').css('display','block') ;
		$('#box .im').fadeIn('normal')
		elm.attr('current', '0');
		prev_elm.attr('current','1');	
	});
	
	$('body').append('<div id="shadow" class="shad"></div><div id="box" class="sert_box" style="display:none"></div>');
	$('.rait_html a').click(function(){
					var src = $(this).children('img').attr('src');
					$('#box').append('<div class="close cls" style="opacity:0;" id="close"><img alt="" src="/img/cl.gif"></div><div class="clr">&nbsp;</div> <img class="bigimg" src="'+src+'" />');
					var w_h = $(window).height();
					$('#box').find('.bigimg').css('height',w_h-115);
					$('#shadow').css('height',shadowHeight+'px');
					$('#shadow').fadeIn('fast');
					marginLeft = ($(window).width() - $('#box').width())/2 + 'px';
					marginTop = (($(window).height() - $('#box').height())/2 + $(window).scrollTop()) + 'px';
					$('#box').css('top', '25px');
					$('#box').css('left', marginLeft);
					$('#box').delay('300').fadeIn('fast');
					$('#box').find('.bigimg').click(function(){
						$('#box').fadeOut('fast', function(){
						$(this).empty();
						$('.shad').delay('300').fadeOut('fast');
					}) ;
					})
				});
				
				$('.shad').live('click',function(){
					$('#box').fadeOut('fast', function(){
						$(this).empty();
					}) ;	
					$(this).delay('300').fadeOut('fast');
		
					});
	$('#box img').live('hover',function(){
		$('.cls').animate({opacity:1},500);	
		});
		
		//LOGIN
		marginLeft = ($(window).width() - $('.err').width())/2 + 'px';
		marginTop = (($(window).height() - $('.err').height())/2 + $(window).scrollTop()) + 'px';
		$('.err').css('left', marginLeft);
		$('.err').css('top', marginTop);
		$('#shad').css('height',shadowHeight );
		$('#shad').click(function(){
			$('.err').fadeOut('fast', function(){
				$('#shad').fadeOut('fast')
			});
		});
		$('.err').find('span').click(function(){
			$('.err').fadeOut('fast', function(){
				$('#shad').fadeOut('fast', function(){
					$('.cb').trigger('click');	
				})
			});
			
		})
});


