var search_form_def_val = 'Поиск по сайту';
var subscribe_form_def_val = 'Введите E-Mail';

$(document).ready(function() {

	if ($.browser.msie && $.browser.version < 8) {
		var all_topmenu_items = $('#top-menu td:not(.separator, .start, .end)').length;
		var all_topmenu_td_width = $('#top-menu').width() - 29 - ((all_topmenu_items + 1) * 3);
		
		var all_bottommenu_items = $('#bottom-menu td:not(.separator, .start, .end)').length;
		var all_bottommenu_td_width = $('#bottom-menu').width() - 34 - ((all_bottommenu_items + 1) * 3);
		
		$('#top-menu td:not(.separator, .start, .end)').width(all_topmenu_td_width/all_topmenu_items);
		$('#bottom-menu td:not(.separator, .start, .end)').width(all_bottommenu_td_width/all_bottommenu_items);
		
		if ($('#main-menu').width()) {
			$('#main-menu td').width($('#main-menu').width()/3);
			$('#main-menu td.image_1 a').mouseover();
		}
	}

	$('#top-menu td.disabled').prev('td.separator').addClass('disabled left');
	$('#top-menu td.disabled').next('td.separator').addClass('disabled right');

	$('#search-form div.input input').val(search_form_def_val);
	$('#subscribe-form div.input input').val(subscribe_form_def_val);
	
	$('div.tab-box ul.tabs li').click(function() {
		if ($(this).hasClass('active')) {
			return false;
		}
		
		var tabRegExp = /^tab-([\da-z]+)-([\da-z]+)$/;
		var tabMatches = tabRegExp.exec($(this).attr('id'));
		
		$('#tab-box-' + tabMatches[1] + ' .content').each(function() {
			$(this).hide();
		});
		$('#tab-content-' + tabMatches[1] + '-' + tabMatches[2]).show();
		
		$('#tab-box-' + tabMatches[1] + ' li.active').removeClass('active');
		$(this).addClass('active');	
	});
	
	
	$('a.lightbox2').fancybox({
		'titleShow' : false
	});
	$('a.lightbox').fancybox({
		'titlePosition' : 'inside',
		'titleFormat'   : function(title, currentArray, currentIndex, currentOpts) {
			return '<div style="height: 14px; overflow: visible;"><div style="float: right;" class="fancybox_descr_full_link_' + currentIndex + '"><a href="#" onclick="$(this).hide(); $(this).fancybox({autoScale : false, href : \'' + currentOpts.href + '\'}).click(); return false;">[оригинальный размер]</a></div></div>';
		}
	});
	
});

function search_form() {
	if ($('#search-form div.input input').val() == search_form_def_val || $('#search-form div.input input').val() == '') {
		return false;
	}
	
	return true;
}

function subscribe_form() {
	if ($('#subscribe-form div.input input').val() == subscribe_form_def_val || $('#subscribe-form div.input input').val() == '') {
		return false;
	}
	
	if (!(/[-.a-z\d]+@[-.a-z\d]+\.[a-z]+/i.test($('#subscribe-form div.input input').val()))) {
		alert('Вы должны ввести E-Mail');
		return false;
	}
	
	return true;
}

function clear_form(jqid, id) {

	$(jqid).addClass('disabled');
	
	$('#' + id + ' input, #' + id + ' textarea').val('');
	
	return false;
	
}
