var $j = jQuery.noConflict();

jQuery(document).ready(function($) {

	//back to top
	$('#back-to-top').click(function(e) {
		$('html, body').animate({scrollTop:0}, 'fast');
		return false;
	});
	
	//navigation
	function showNeighbors(element) {
		if(element.prev().length > 0) {
			element.prev().addClass('prev-over');
		}
		if(element.next().length > 0) {
			element.next().addClass('next-over');
		}
	}
	function hideNeighbors(element) {
		if(element.prev().length > 0) {
			element.prev().removeClass('prev-over');
		}
		if(element.next().length > 0) {
			element.next().removeClass('next-over');
		}
	}
	$('#navigation li.level-top.active').each(function(i, element){
		showNeighbors($(this));
	});
	$('#navigation li.level-top').hover(
		function () {
			if(!$(this).is('.active')) {
				showNeighbors($(this));
			}
			if($(this).is('.first')) {
				$('.childrens', this).addClass('first-over');
			}
		}, 
		function () {
			if(!$(this).is('.active')) {
				hideNeighbors($(this));
			}
			if($(this).is('.first')) {
				$('.childrens', this).removeClass('first-over');
			}
		}
	);
	$('#navigation .childrens li:nth-child(3n)').addClass('last-in-row');

	
	//products-grid
	$('.block-category-products .products-grid .item:nth-child(2n)').addClass('last-in-row');
	$('#upsell-products .products-grid .item:nth-child(3n)').addClass('last-in-row');
	$('.products-grid .item').equalHeights();
	
	//first/last-child
	$('li:first-child').addClass('first-child');
	$('li:last-child').addClass('last-child');

	
	//std
	$('.std h1:first-child, .std h2:first-child, .std h3:first-child, .std h4:first-child, .std h5:first-child, .std h6:first-child').addClass('first-child');
	
	//faq				
	$("body.cms-faq .std .faq-header").each(function(id, data) {
		$(this).attr('name','faq-container-' + id);
		$(this).click(function(e) {
			if( $("#" + $(this).attr('name')).is(':hidden') ) {
				$("#" + $(this).attr('name')).slideDown('normal');
				$(this).addClass('active');
			} else {
				$("#" + $(this).attr('name')).slideUp('normal');
				$(this).removeClass('active')
			}
			return false;
		});
	});	
	$("body.cms-faq .std .faq-container").each(function(id, data) {
		$(this).attr('id','faq-container-' + id);
	});
	$("body.cms-faq .std a.faq-question").each(function(id, data) {
		$(this).attr('name', 'faq-' + id);
		$(this).parent().next().attr('id', 'faq-' + id);
		$(this).click(function(e) {
			if( $("#" + $(this).attr('name')).is(':hidden') ) {
				$("#" + $(this).attr('name')).slideDown('normal');
				$(this).addClass('active');
			} else {
				$("#" + $(this).attr('name')).slideUp('normal');
				$(this).removeClass('active')
			}			
			return false;
		});
	});
});
