var hash;
function showlist() {

	var testhash = window.location.hash;
	testhash = testhash.replace("#", "");
	if (testhash != '' && hash != testhash) {
	var	i = 0;

		hash = window.location.hash;
		hash = hash.replace("#", "");
		var activeheight = 0;
		$(".faq h3").each(function() {
			if ($(this).hasClass("ui-state-active")) {
				var h = $(this);
				var p = h.parent();
				activeheight = p.children("div").height() + h.height();

			}
			if ($(this).attr('id') == hash) {
				
				$(".faq").accordion("activate", "#"+hash);

				window.scrollBy(0, -activeheight);

			}
			i++;
		});

	}
}
$(document).ready(function() {
	i = 1;
	$("#powody li").each(function() {
		$(this).prepend("<span>" + i + "</span>");
		i++;
	});

	$("ul.dropdown li").hover(function() {

		$(this).addClass("hover");
		$('ul:first', this).css('visibility', 'visible');

	}, function() {

		$(this).removeClass("hover");
		$('ul:first', this).css('visibility', 'hidden');

	});

	tmp = $(".faq").accordion({
		navigation : true,
		autoHeight : false,
		collapsible : true,
		active : false
	});

	showlist();
	if ($.browser.msie && $.browser.version.substring(1, 0) == "7") {
		console.log("ie 7")

		var RunTabs = setInterval('showlist()', 200);

	} else {
		$(window).bind('hashchange', function() {
			showlist();
		});
	}

	h = 0 - window.outerWidth;

	slideshow = {
		list : [],
		loaded : [],
		makelist : function(a) {
			var i = $(a);
			i.each(function() {
				var b = $(this);
				slideshow.list.push(b.attr("src"));
				b.remove();
			});
			slideshow.list.reverse()
			$(".slideshow").html("<div></div>");
			slideshow.run();
		},
		run : function() {
			var src = slideshow.takeone();
			if (src != false) {
				var h = $("html").outerWidth(true);
				h = h + 'px -400px'

				var s = $(".slideshow")

				s.children("div").first().fadeOut(800, function() {
					$(this).remove();
					var d = $("<div ></div>").css({
						"background-position" : h,
						"background-image" : 'url("' + src + '")',
						"background-repeat" : "no-repeat"
					}).appendTo(s);
					d.animate({
						"backgroundPosition" : '60px -80px'
					}, 800, function() {
						setTimeout("slideshow.run()", 8000);

					});

				})

			}

		},
		takeone : function() {
			if (slideshow.list.length > 0) {
				var t = slideshow.list.shift()
				slideshow.loaded.push(t);
				return t;
			} else if (slideshow.loaded.length > 0) {
				slideshow.list = slideshow.loaded;
				slideshow.loaded = [];
				return slideshow.takeone();
			}
			return false;

		}
	}

	testshow = {
		list : [],
		loaded : [],
		makelist : function(a) {
			var i = $(a);
			i.each(function() {
				var b = $(this);
				testshow.list.push(b);
				b.remove();
			});
			testshow.list.reverse()
			$("#slogan").html("<div></div>");
			testshow.run();
		},
		run : function() {
			var src = testshow.takeone();

			if (typeof (src) == "object") {

				src.show();

				var s = $("#slogan");

				src.find(".slogan-h3").css("margin-left", "-960px")
				src.find(".slogan-h4").css("margin-left", "960px")
				src.find(".slogan-h4").addClass("btm");

				d = s.find("div");
				src.appendTo(s);

				d.fadeOut(800, function() {
					d.remove();

				});
				src.find(".slogan-h4,.slogan-h3").css("width", "100%").animate({
					"margin-right" : 0,
					"margin-left" : 0
				}, 3000, function() {

				})
				setTimeout("testshow.run()", 6000);
				;

			}

		},
		takeone : function() {
			if (testshow.list.length > 0) {
				var t = testshow.list.shift()
				testshow.loaded.push(t);
				return t;
			} else if (testshow.loaded.length > 0) {
				testshow.list = testshow.loaded;
				testshow.loaded = [];
				return testshow.takeone();
			}
			return false;

		}
	}

	slideshow.makelist(".slideshow img");

	$('.slideshow img:first').css("right", h).css("top", "-400px").animate({
		right : "-100px",
		top : 0
	}, 800)

	h = 38;

	$(".cennik .car").each(function() {
		tmph = $(this).children('img').height();

		if (h > tmph) {
			roznica = (h - tmph) / 2;
			$(this).css('padding-top', roznica + 'px');
		}
	})

	$(".album li a, .fancyinfo").fancybox();
	$('a[href$=".jpg"], a[href$=".jpeg"], a[href$=".png"], a[href$=".gif"], a[href$=".JPG"], a[href$=".JPEG"], a[href$=".PNG"], a[href$=".GIF"]').fancybox();

	Cufon.CSS.ready(function() {
		testshow.makelist("#slogan div");
	});
});

Cufon.replace('#header .nagl, #slogan, .more, #sidebar #powody h2, .fakty, #porady h3, #pytania h3, .more2',
				{
					color : '-linear-gradient(#046996, #000e14)',
					textShadow : '1px 1px white'
				});

Cufon.replace('#main > h1, #allegro h3, #main #text h3, .moreinfo span, #klienci h3, #cennik h3', {
	textShadow : '1px 1px white'
});
Cufon.replace('#video h3', {
	color : '-linear-gradient(#ffffff, #f2f2f2)',
	textShadow : '1px 1px #666666'
});

Cufon.replace('.dropdown > li > a', {
	textShadow : '1px 1px #ededed'
});

