$(document).ready(function() {


	// Stylizé ('cause of Internet Explorer)
	$('.posts_grid .post_item:nth-child(3n+3)').css({
		'border' : 'none',
		'margin-right' : '0',
		'width' : '220px'
	});
	$('#navigation > ul > li:nth-child(odd)').css({
		'margin-left' : '70px'
	});



	// Featured slider
	$('#featured_slider').cycle({
		fx: 'scrollVert',
		prev:    '#prev',
		next:    '#next',
		speed:  2000,
		pause: true,
		after: function(currSlideElement, nextSlideElement, options, forwardFlag) {
			$('#pager').text(options.currSlide + 1 + '/' + options.slideCount);
		}
	}); 
	
	
	
	// Posts grid
	$('.post_item .more a').hover(function() {
		$(this).parent().css({ borderColor: '#ffcc33' });
	}, function() {
		$(this).parent().css({ borderColor: '#999' });
	});
	
	
	
	// Contact navigation link
	$('#kapcsolat').click(function() {
		$.scrollTo('#contact', 1000);
		return false;
	});



	// Search bar
	var $searchBar = $('#search_bar');
	$searchBar.hide();
	$('.wrapper', $searchBar).hide();
	
	$('#search_tab').click(function() {
		if ($searchBar.hasClass('closed')) {
			$searchBar.slideDown('medium', function() {
				$('.wrapper', $searchBar).fadeIn('fast');	
			});
			$searchBar.removeClass('closed');
		} else {			
			$('.wrapper', $searchBar).fadeOut('fast', function() {
				$searchBar.slideUp();
			});			
			$searchBar.addClass('closed');
		}
	});



	hideInputValue($('#search'));
	
	
	
	// Navigation
	var $mainCategory = $('.main_category');
	var $header = $('#header');
	
	if ($('ul.active', $mainCategory).length == 0) {
		$header.height(175);
	} else {
		//$('.category_description').hide();
		$header.height(221);
		$('#navigation').height(221);
	}
	
	/*$('.main_category a').click(function() {
		
		var $subcategory = $('ul', $(this).parent());
		var $categoryDescription = $('.category_description', $(this).parent());
		
		$('.category_description').hide();
		
		if ($subcategory.length > 0) {		
			
			$('.active').removeClass('active');
			if ($header.height() > 175) {
				$header.animate({ height: '175px' }, 200);
			}
			
			$('ul', $mainCategory).hide();

			$subcategory.addClass('active');
			$(this).parent().addClass('active');
			
			var newHeight = 240 + $categoryDescription.height();
			
			$header.animate({ height: newHeight + 'px' }, 700);
			$('#header .wrapper').height(newHeight);
			$('#navigation').height(newHeight - 9);
			
			$categoryDescription.fadeIn();
			$subcategory.fadeIn();
			
			return false;
			
		}	
		
	});*/
	
	
	
	// Books
	$('#books ul').jcarousel({
		scroll: 4,
		initCallback: carouselInitCallback,
		wrap: 'circular',
		buttonNextHTML: null,
		buttonPrevHTML: null
    });	

});




function carouselInitCallback(carousel) {

	$('#shelf_nav .prev').click(function() {
    	carousel.prev();
    });
    
    $('#shelf_nav .next').click(function() {
    	carousel.next();
    });

}




function hideInputValue(element, defaultValue) {

	if (defaultValue == undefined) {
		defaultValue = element.val();
	}
	
	element.focus(function() {
		if (this.value == defaultValue) {
			this.value = '';
		}
	});
	
	element.blur(function() {
		if (this.value == '' || this.value == defaultValue) {
			this.value = defaultValue;
		}
	});

}
