function poradna (moreText) {
	$("#form-window").css('display','none');
	$("#form-window").css('position','absolute');

	$(".poradna").each(function (i) {
		var answer = $(this).children(".answer");
		var question = $(this).children(".question");
		answer.css('display','none');
		question.css('cursor','pointer');
		question.click( function () { slideIt(answer); });
		question.append('<p class="more"><a href="#">'+moreText+'</a></p>');
	});
}
function slideIt (element) {
	if (element.is(":hidden")) {
		element.slideDown("normal");
	}
	else {
		element.slideUp("normal");
	}
}

function clicker(button,hidden) {
	$(button).hide();
	$('#'+hidden).slideDown();
	return false;
}

function closeWindow(window,remove) {
	$('#'+window).slideUp("slow", function() {
		if (remove) $('#'+window).remove();
	});
	return false;
}

function parnersHover () {
	var e = true;
	$("#logo-parners td a").each(function (i) {
		var img = $(this).children("img");
		var imgBlack = img.attr('src');
		var ext = imgBlack.lastIndexOf('.');
		var imgColor = imgBlack.substr(0,imgBlack.lastIndexOf('_cb')) + imgBlack.substr(ext, imgBlack.length - ext);
		$(this).mouseover(function () { $(img).attr('src',imgColor); });
		$(this).mouseout(function () { $(img).attr('src',imgBlack); });
	});
}

function shopLoad () {
	
}

function buyProd(id,price,num,max) {
	if ($("#total-price").length != 0) {
		var count = 0;
		var cookieName = "productList["+id+"]";
		var theCookie = ""+document.cookie;
		var ind = theCookie.indexOf(cookieName);
		if (ind != -1 && cookieName != "") {
			var ind1 = theCookie.indexOf(';',ind);
			if (ind1 == -1) ind1 = theCookie.length;
			count = parseFloat(theCookie.substring(ind+cookieName.length+1,ind1));
		}
		if ((count + num) > max) alert("Za sezónu můžete nakoupit jen "+max+" kusů.");
		else {
			document.cookie = "productList["+id+"] ="+(count + num);
			var total = $("#total-price").text();
			if (total != "") total = parseFloat(total) + price;
			else total = price;
			$("#total-price").text(total);
		}
		return false;
	}
	return true;
}

function divToLink(parent,element) {
	var links = $('#'+parent).children("."+element).each(function(i) {
		var block = this;
		$(block).find('a').each(function(i) {
			var link = this;
			$(block).click(function() { window.location = $(link).attr("href"); });
			$(block).css("cursor","pointer");
		});
	});
}

// galerie
var galleryList= {
	element: "",
	links: Array(),
	texts: Array(),
	imgCount: 0,
	imgShow: 0,
	imgMargin: 80,
	txtPrev: 'Preview',
	txtNext: 'Next',
	txtClose: 'Close',

	create: function (elementId) {
		var count = 0;
		galleryList.appendGallery();
		galleryList.element = "#"+elementId;
		$(galleryList.element).find("a").each(function(i) {
			galleryList.links[i] = $(this).attr("href");
			galleryList.texts[i] = $(this).children("img").attr("alt");
			$(this).click(function() { galleryList.showGallery(i); return false; });
			count++;
		});
		galleryList.imgCount = count;
		$("#jgallery-left").click(function() { galleryList.scrollit(true); return false; });
		$("#jgallery-right").click(function() { galleryList.scrollit(false); return false; });
		$("#jgallery-close").click(function() { $("#jgallery").fadeOut(500); return false; });
		$("#jgallery-image").click(function() { $("#jgallery").fadeOut(500); return false; });
	},

	setImage: function (href,note) {
		var text = $("#jgallery-image p");
		var img = $("#jgallery-image img");
		$(text).text(note);
		$(img).fadeOut(200, function () {
			$(img).load(function () {
				$("#jgallery-image").width($(img).attr('width'));
				/*$("#jgallery-image").height($(img).attr('height'));
				$("#jgallery-image").empty();
				$("#jgallery-image").append(this);*/
				if (note == "") $(text).css('display','none');
				else $(text).css('display','block');
				$(img).fadeIn(200);
			}).attr('src', href);
		});
	},

	scrollit: function (left) {
		if (left) {
			if (this.imgShow > 0) this.showGallery(this.imgShow-1);
		}
		else {
			if (this.imgShow < this.imgCount-1) this.showGallery(this.imgShow+1);
		}
		return false;
	},

	showGallery: function (number) {
		this.imgShow = number;
		var scrollTop = $(window).scrollTop();
		if (this.imgShow == 0) $("#jgallery-left").css('display','none');
		else $("#jgallery-left").css('display','block');
		if (this.imgShow == this.imgCount-1) $("#jgallery-right").css('display','none');
		else $("#jgallery-right").css('display','block');

		$("#jgallery").fadeIn(500);
		$("#jgallery-image").css("top",scrollTop+this.imgMargin+"px");
		$("#jgallery-position").text((number+1)+" / "+this.imgCount);
		this.setImage(this.links[number],this.texts[number]);
		if ($("body").height() > document.documentElement.clientHeight) {
			if ((scrollTop+$("#jgallery-image").height()+this.imgMargin) > $("body").height()) $("#jgallery-black").height(scrollTop+$("#jgallery-image").height()+this.imgMargin+document.documentElement.clientHeight);
			else $("#jgallery-black").height($("body").height());
		}
		else {
			if ((scrollTop+$("#jgallery-image").height()+this.imgMargin) > document.documentElement.clientHeight) $("#jgallery-black").height(scrollTop+$("#jgallery-image").height()+this.imgMargin+document.documentElement.clientHeight);
			else $("#jgallery-black").height(document.documentElement.clientHeight);
		}
	},

	appendGallery: function () {
		$("body").append('<div id="jgallery"><div id="jgallery-black"></div><div id="jgallery-lister"><a href="#" id="jgallery-close" title="'+this.txtClose+'"><span>'+this.txtClose+'</span></a><div id="jgallery-status">'+
		'<a href="#" id="jgallery-left" title="'+this.txtPrev+'"><span>'+this.txtPrev+'</span></a><a href="#" id="jgallery-right" title="'+this.txtNext+'"><span>'+this.txtNext+'</span></a><span id="jgallery-position">0 / 0</span>'+
		'</div></div><div id="jgallery-image"><img src="" /><p></p></div>');
	}
}