$(window).load(function() {
	if (!$('body').hasClass('h')) {
		$('.nivo', '#slider').nivoSlider({
			controlNav: false,
			directionNav: false,
			effect: 'boxRainGrow',
			pauseOnHover: false
		});
	}
});
$(document).ready(function(){

$('html').removeClass('no-js');
$('input[placeholder]').placeholderLabel();


$(".fb").each(function(i,e){
	var el;
	
	if ($(this).find("a").size())
		el = $(this).find("a");
	else 
		el = $(this);
		
	el.attr('rel', 'gallery'+i).fancybox({
		titlePosition: 'inside',
		overlayColor: '#000',
		overlayOpacity: 0.2
	});
});

//$("#gallery").preloader();

$("form").validator({ 
	lang: 'pl',
	message: '<div><i/><em/></div>'
}).attr('novalidate', 'novalidate');


if (!$('body').hasClass('h')) {
	$('#menu .oferta a').click((function() {
		var tog = true, sub = $('#sub'), ap = {queue: false};
		return function() {
			if (tog) {
				sub.animate({left: 213}, ap)
			} else {
				sub.animate({left: 19}, ap)
			}
			tog = !tog;
			return false;
		}
	})());
} else {
	$('#menu .oferta, #sub').bind('mouseenter mouseleave click', (function() {
		var sub = $('#sub'), ap = {queue: false, duration: 200}, height;
		height = sub.show().height();
		sub.height(0).css('overflow', 'hidden');
		return function(e) {
			if (e.type === 'mouseleave') {
				sub.animate({height: 0}, ap)
			} else {
				sub.animate({height: height}, ap)
			}
		}
	})());
}


$('[data-image]').tooltip({ 
    delay: 300,
    extraClass: "image",
    showURL: false,
    track: true,
    bodyHandler: function() { 
        return $("<img/>").attr("src", $(this).data('image')); 
    } 
});
$('[data-text]').tooltip({ 
    delay: 300,
    extraClass: "text",
    showURL: false,
    track: true,
    bodyHandler: function() { 
        return $("<h6/>").html($(this).data('text')); 
    } 
});



$('img.captcha').click(function() {
	$(this).attr('src', 'image.php?'+Math.random());
});


$('.products > div').bind('mouseenter mouseleave click', (function() {
	var off = {opacity: 0, width: 130, marginLeft: -75,  top: -10},
		on  = {opacity: 1, width: 212, marginLeft: -106, top: -60},
		af = {queue: false, duration: 200, complete: function() {$(this).css('display', 'none')}},
		an = {queue: false, duration: 200};
	$('.products > div div').css(off);
	return function(e) {
		var sub = $(this).find('div');
		if (e.type === 'mouseleave') {
			sub.animate(off, af)
			$(this).css('z-index', 100);
		} else {
			sub.stop().css('display', 'block').animate(on, an);
			$(this).css('z-index', 190);
		}
		return false;
	}
})());


$(".products > div div a").attr('rel', 'products').fancybox({
	titlePosition: 'inside',
	overlayColor: '#000',
	overlayOpacity: 0.2,
	titleFormat: function(title, currentArray, currentIndex, currentOpts) {
		$('.products > div').trigger('mouseleave');
		var el = $(currentArray[currentIndex]);
		return '<h5>' + el.data('h') + '</h5>';
	}
});

$('.col4 article div').equalHeight();


// end ready()
});
