function s(id) {$('#fld'+id).show();}
function h(id) {$('#fld'+id).hide();}
function show(id) {$('#fld'+id).toggle(); return false;}

function checkForm(field)
{
	ok = 1;
	$("."+field).each(function () {
		if($(this).val() == '') { $(this).css("border-color", "red"); $(this).css("background-color", "#ffd2d2"); ok = 0; }
		else { $(this).css("border-color", "#7bba2d");  $(this).css("background-color", "#fff");  }
    });
	if(!ok)
	{
		alert("Ошибка! Не заполены необходимые поля формы.");
		return false;
	}
	return true;
}

function slideShow() {

    //Set the opacity of all images to 0
    $('#slider div').css({opacity: 0.0});

    //Get the first image and display it (set it to full opacity)
    $('#slider div:first').css({opacity: 1.0});

    //Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
    setInterval('gallery()',5000);

}

function gallery() {

    //if no IMGs have the show class, grab the first image
    var current = ($('#slider div.show')?  $('#slider div.show') : $('#slider div:first'));

    //Get next image, if it reached the end of the slideshow, rotate it back to the first image
    var next = (current.next().length) ?  current.next() : $('#slider div:first');

    //Set the fade in effect for the next image, show class has higher z-index
    next.css({opacity: 0.0})
    .addClass('show')
    .animate({opacity: 1.0}, 1000);

    //Hide the current image
    current.animate({opacity: 0.0}, 1000)
    .removeClass('show');

}

$(document).ready(function() {

	var h = $('#middle').height();
	$('#sideLeft').height(h);
	$('#sideRight').height(h);

	 slideShow();
	
	$("a.fancybox").fancybox({
		'hideOnContentClick':true,
		'transitionIn'  : 'elastic',
		'transitionOut'  : 'elastic',
		'overlayColor'    : '#000',
		'overlayOpacity'  : 0.7,
		'titlePosition'    : 'over'
	});
	
	$('div.pngfix').pngFix( );

	$('#search-q').click(function() {
		if($(this).val() == 'Поиск')
			$(this).val('');
	}).focusout(function(){
		if($(this).val() == '')
			$(this).val('Поиск');
	});

	$(".bm-inner").mouseenter(function() {
		$(this).children('.bm-small').hide();
		$(this).children('.bm-full').css({opacity: 0.0}).show().animate({opacity: 1.0}, 500);
	});
	$(".bm-inner").mouseleave(function() {
		$(this).children('.bm-small').show();
		$(this).children('.bm-full').animate({opacity: 0.0}, 500, function() { $(this).hide(); } );
	});




});
