function fSubmitSearchForm() {
    document.forms["advanced-search-form"].submit();
}



(function ($) {
	$.fn.scrollable = function (opts) {
		return this.each(function () {
			var target = $(this),
				container = $(opts.container)
			var width = container.width(),
				offset = container.offset().left
		  var width2 = container.outerWidth()
			var pos = 0, speed = 0, ival
			var minPos = width - target.width()
			if (minPos > 0) {
				container.addClass("lft-edge")
				return
			}
			$('div.special-offer span.right-btn').click(function () {
				if ((pos-660) > (minPos)) {
					pos -= 660;
					$('#thumbs').css({ left: pos })
				}
				else {
					pos = minPos;
					$('#thumbs').css({ left: pos })			
				}
			})
			$('div.special-offer span.left-btn').click(function () {
				if ((pos+660) <= 0) {
					pos += 660;
					$('#thumbs').css({ left: pos })
				}
				else {
					pos = 0;
					$('#thumbs').css({ left: pos })			
				}
			})
			container
				.addClass("scrollable")
				.mouseenter(function (e) {
					ival = setInterval(function () {
						pos += speed * 7
						pos = Math.min(pos, 0)
						pos = Math.max(pos, minPos)
						target.css({ left: pos })
						if (pos == 0) {
							container.addClass("lft-edge")
						} else if (pos == minPos) {
							container.addClass("rgt-edge")
						} else {
							container.removeClass("lft-edge rgt-edge")
						}
					}, 10)
				})
				.mouseleave(function (e) {
					clearInterval(ival)
				})
				.mousemove(function (e) {
					var d = (e.pageX - offset) - width2/2	// d = odleglosc myszy od srodka
					var s = (d > 0 ? -1 : 1)				// s = znak, tj. kierunek przesuwania
					var x = Math.abs(2*d/width2)				// x = d zeskalowane do przedzialu [0,1]
					if (x < 0.8) {
						speed = 0
					} else {
						// funkcja potegowa przesunieta tak, by f(0.8) = 0, f(1) = 1
						speed = s * Math.pow(5*(x-0.8), 3)
					}
				})
				.addClass("lft-edge")
		})
	}
})(jQuery);

jQuery.fn.reduce = function (c, fn) {
	this.each(function (i) { c = fn.apply(this, [c]) })
	return c
}


jQuery(function() {
	$(document).pngFix(); 
if ($.browser.msie) {
			$("tr:first-child, td:first-child, th:first-child").addClass("first-child")
			$("tr:last-child, td:last-child, th:last-child").addClass("last-child")
			$("li:first-child").addClass("first-child")
			$("li:last-child").addClass("last-child")
			
			if (parseInt($.browser.version) <= 6) {
				$("#top h1 img").pngFixImage()
				$("a.more-btn img").pngFixImage()
				$("a.arrow-btn img").pngFixImage()
				$("span.left-btn img").pngFixImage()
				$("span.right-btn img").pngFixImage()
				$("#content div.pagination a img").pngFixImage()
				
			}
		}
		
		/*	$("div.gallery-box").each(function () {
		var big = $(this).find(".big-fotos .big-foto")
		var thumbs = $(this).find("#thumbs a")
		big.css({ position: "absolute", top: '1px', left: '1px' }).hide().eq(0).show()
		thumbs.click(function () {
			big.fadeOut().eq(thumbs.index(this)).fadeIn()
			thumbs.removeClass("active")
			$(this).addClass("active")
			return false
		})
	})*/
	
		function formatTitle(title, currentArray, currentIndex, currentOpts) {
			return '<div id="fancybox-custom-title"><span><a id="fancybox-close" style="display: inline;" href="javascript:;" onclick="$.fancybox.close();"></a></span>' + (title && title.length ? title : '&nbsp;' ) + ' ' + '</div>';
    }
		$(function() {
				$("#content div.gallery-box a").fancybox({
					transitionIn: 'elastic',
					transitionOut: 'elastic',
					showCloseButton: false,
					titlePosition: 'inside',
					titleFormat: formatTitle,
					zoomOpacity: true,
					overlayShow: true,
					overlayOpacity: 0.65,
					overlayColor: '#000',
					padding: 30,
					zoomSpeedIn: 500,
					zoomSpeedOut: 500
				});
			});
		
		
		$("#menu li ul.lvl2").parent().addClass("lvl1-parent");
		$("#menu li.lvl1-parent").hover(function(){
    	$(this).addClass("lvl1-parent-hover");
    },function(){
			$(this).removeClass("lvl1-parent-hover");
		});
		$("#menu li.lvl1").hover(function(){
			$(this).addClass("hover");
			$(this).find('a').addClass("hover");
			$('ul.lvl2',this).css('visibility', 'visible');
			},function(){
			$(this).removeClass("hover");
			$(this).find('a').removeClass("hover");
			$('ul.lvl2',this).css('visibility', 'hidden');
		});
		if ($.browser.msie) {
			$("tr:first-child, td:first-child, th:first-child").addClass("first-child")
			$("tr:last-child, td:last-child, th:last-child").addClass("last-child")
			$("li:first-child").addClass("first-child")
			
			$("li:last-child").addClass("last-child")
			if (parseInt($.browser.version) <= 6) {
				$("#menu img").pngFixImage()
			}
		}
		
		$('div.special-offer #thumbs')
		.width($("#thumbs a").reduce(0, function (r) { return r + $(this).outerWidth(true) }))
		.scrollable({ container: $("#thumbs-wrapper") })
	// poczatkowo w css jest overflow:hidden, co pozwala uniknac brzydkich efetkow w czasie ladowania strony
	$("#thumbs").css({ overflow: "visible" })
		
});


