$(document).ready(function() {

	$(".iframe").fancybox({
		'width': 760,
		'height': '100%',
		'type': 'iframe',
		'scrolling':'no',
		'padding': 0
	 });

	$(".menu").find("li").each(function() {
		if ($(this).attr("id")) {
			var link = $(this).find("a")[0];
			
			if ($(link).attr("href") == "#") {
				$(link).attr("href", "");
				$(link).click(function() {
					return false;
				});
			}
			
			var childsId = "#" + $(this).attr("id") + "-childs";
			
			if ($(childsId)) {
				$(childsId).hide();
				
				$(this).hover(
					function() {
						$(childsId).show();
					},
					function() {
						$(childsId).hide();
					}
				);
			}
		}
	});

	$("#search-query").focus(function() {
		if ($(this).val() == "Поиск по сайту" || $(this).val() == "Search") {
			$(this).val("");
		}
		
	}).blur(function() {
		if ($(this).val() == "") {
			var en = window.location.href.indexOf('piterra.ru/en');
			if (en == '-1')	{
				$(this).val("Поиск по сайту");
			} else {
				$(this).val("Search");
			}
			
		}
	});
	
	$("a.fancy-iframe").fancybox({
		"width" : "75%",
		"height" : "75%",
		"autoScale" : false,
		"transitionIn" : "none",
		"transitionOut" : "none",
		"type" : "iframe"
	});

	$("a.fancy-images").fancybox({
		"zoomOpacity" : true,
		"overlayShow" : true,
		"zoomSpeedIn" : 500,
		"zoomSpeedOut" : 500,
		"hideOnContentClick" : true
	});

	$('.empty_link').click(function(){
		return false;
	});

	$('.brands ul li a').click(function(e){
		var dif = e.pageX - $(this).offset().left;
		var sub = $(this).parent().find('ul');
		if (dif < 20){
			$(this).toggleClass('active');
			if (sub.size() > 0)	{
				sub.toggle();
			}
			
			return false;
		}
	});
});

function toggleMenu(el){
	if ($(el).hasClass('active')){
		$(el).removeClass('active');
		
	} else {
		$(el).addClass('active');
	}
	
	$(el).parent().children('ul').toggle();
	
}

