

$(document).ready(function() {

	var ie = false;
	if ($.browser.msie) ie = true;

	$("header #logo a").bind("mouseenter focus", function() {
		if (ie) {
			$("header .strip").css({left:"-470px"});
			$("header #logo span").show();
			$("header #logo a").addClass("over");
		} else {
			$("header .strip").animate({left:"-470px"}, {duration: 300, queue: false, easing: "easeOutExpo"});
			$("header #logo span").fadeIn(50, function() {
				$("header #logo a").addClass("over");
			});
		}
	}).bind("mouseleave blur", function() {
		if (ie) {
			$("header .strip").css({left:"-1500px"});
			$("header #logo span").hide();
			$("header #logo a").removeClass("over");
		} else {
			$("header .strip").animate({left:"-1500px"}, {duration: 300, queue: false, easing: "easeInExpo"});
			$("header #logo span").fadeOut(150, function() {
				$("header #logo a").removeClass("over");
			});
		}
	});


	$("#strip div div").mouseenter(function() {
		var id = $(this).parent().attr("id");
		if (ie) {
			if (id == "stripGreen") {
				$("#stripRed").css({top:"257px"});
				$("#stripBlue").css({top:"307px"});
				$("#stripPurple").css({top:"357px"});
			} else if (id == "stripRed") {
				$("#stripBlue").css({top:"307px"});
				$("#stripPurple").css({top:"357px"});
			} else if (id == "stripBlue") {
				$("#stripPurple").css({top:"357px"});
			} else if (id == "stripPurple") {
			}
			$(this).find(">div").show();
		} else {
			if (id == "stripGreen") {
				$("#stripRed").animate({top:"257px"}, { queue: false, duration: 200 });
				$("#stripBlue").animate({top:"307px"}, { queue: false, duration: 200 });
				$("#stripPurple").animate({top:"357px"}, { queue: false, duration: 200 });
			} else if (id == "stripRed") {
				$("#stripBlue").animate({top:"307px"}, { queue: false, duration: 200 });
				$("#stripPurple").animate({top:"357px"}, { queue: false, duration: 200 });
			} else if (id == "stripBlue") {
				$("#stripPurple").animate({top:"357px"}, { queue: false, duration: 200 });
			} else if (id == "stripPurple") {
			}
			$(this).find(">div").slideDown(200);
		}
	})
	$("#strip div div").mouseleave(function() {
		var id = $(this).parent().attr("id");
		if (ie) {
			if (id == "stripGreen") {
				$("#stripRed").css({top:"100px"});
				$("#stripBlue").css({top:"150px"});
				$("#stripPurple").css({top:"200px"});
			} else if (id == "stripRed") {
				$("#stripBlue").css({top:"150px"});
				$("#stripPurple").css({top:"200px"});
			} else if (id == "stripBlue") {
				$("#stripPurple").css({top:"200px"});
			} else if (id == "stripPurple") {
			}
			$(this).find(">div").hide();
		} else {
			if (id == "stripGreen") {
				$("#stripRed").animate({top:"100px"}, { queue: false, duration: 200 });
				$("#stripBlue").animate({top:"150px"}, { queue: false, duration: 200 });
				$("#stripPurple").animate({top:"200px"}, { queue: false, duration: 200 });
			} else if (id == "stripRed") {
				$("#stripBlue").animate({top:"150px"}, { queue: false, duration: 200 });
				$("#stripPurple").animate({top:"200px"}, { queue: false, duration: 200 });
			} else if (id == "stripBlue") {
				$("#stripPurple").animate({top:"200px"}, { queue: false, duration: 200 });
			} else if (id == "stripPurple") {
			}
			$(this).find(">div").slideUp(200);
		}
	});


	$("nav ul > li").mouseenter(function() {
		if ($(this).find("ul").length) {
			$(this).addClass("over").next().addClass("overNext");
		}
	}).mouseleave(function() {
		if ($(this).find("ul").length) {
			$(this).removeClass("over").next().removeClass("overNext");
		}
	});


	$("#partners").mouseenter(function() {
		if (ie) {
			$(this).css({bottom:"0"});
		} else {
			$(this).animate({bottom:"0"}, {duration: 300, queue: false, easing: "easeOutExpo"});
		}
	}).mouseleave(function() {
		if (ie) {
			$(this).css({bottom:"-281px"});
		} else {
			$(this).animate({bottom:"-281px"}, {duration: 300, queue: false, easing: "easeInExpo"});
		}
	});


	$("#telephone div").mouseenter(function() {
		if (ie) {
			$(this).css({left:"0"});
		} else {
			$(this).animate({left:"0"}, {duration: 300, queue: false, easing: "easeOutExpo"});
		}
	}).mouseleave(function() {
		if (ie) {
			$(this).css({left:"-215px"});
		} else {
			$(this).animate({left:"-215px"}, {duration: 300, queue: false, easing: "easeInExpo"});
		}
	});

	$("#banner1 div").mouseenter(function() {
		if (ie) {
			$(this).css({left:"0"}).next().addClass("minus");
		} else {
			$(this).animate({left:"0"}, {duration: 300, queue: false, easing: "easeOutExpo"}).next().addClass("minus");
			
		}
	}).mouseleave(function() {
		if (ie) {
			$(this).css({left:"364px"}).next().removeClass("minus");
		} else {
			$(this).animate({left:"364px"}, {duration: 300, queue: false, easing: "easeInExpo"}).next().removeClass("minus");
		}
	});

	$("#galleryEntry a").mouseenter(function() {
		if (ie) {
			$(this).css({left:"0"}).next().addClass("minus");
		} else {
			$(this).animate({left:"0"}, {duration: 300, queue: false, easing: "easeOutExpo"}).next().addClass("minus");
		}
	}).mouseleave(function() {
		if (ie) {
			$(this).css({left:"280px"}).next().removeClass("minus");
		} else {
			$(this).animate({left:"280px"}, {duration: 300, queue: false, easing: "easeInExpo"}).next().removeClass("minus");
		}
	});


	$("a.btn, a.btn2").mouseenter(function() {
		if (ie) {
			$(this).css({paddingRight: "35px"});
		} else {
			$(this).animate({paddingRight: "35px"}, {duration: 100, queue: false, easing: "easeOutExpo"});
		}
	}).mouseleave(function() {
		if (ie) {
			$(this).css({paddingRight: "20px"});
		} else {
			$(this).animate({paddingRight: "20px"}, {duration: 200, queue: false, easing: "easeInExpo"});
		}
	});


	if ($(".cv").length) {
		$(".cv").each(function(i,e) {
			$(this).delegate('.plus', 'click', function(event) {
				event.preventDefault();
				if ($(this).hasClass("minus")) {
					if (ie) {
						$(this).removeClass("minus").next().hide();
					} else {
						$(this).removeClass("minus").next().slideUp(200);
					}
				} else {
					if (ie) {
						$(this).addClass("minus").next().show();
					} else {
						$(this).addClass("minus").next().slideDown(300);
					}
				}
			});	
		});
	}


	if($("#newsBox").length) {
		var glider = $("#newsBox");
		var gliderStatus = $(".status strong", glider);

		$(".nav a:first", glider).click(function(e) {
			$(this).blur();
			e.preventDefault();
			stopAnimation();
			navigate("back");
		});

		$(".nav a.next", glider).click(function(e) {
			$(this).blur();
			e.preventDefault();
			stopAnimation();
			navigate("next");
		});

		var newsContainer = $("#newsBox .news");
	
		var interval;
		$("a[href=#slideshow]").toggle(function() {
			$(this).html("Zastavit slideshow");
			navigate("next");
			interval = setInterval(function() {
				navigate("next");
			}, slideshowSpeed);
		}, function() {
			$(this).html("Spustit slideshow");
			stopAnimation();
		});
	
		var activeContainer = 1;
		var currentImg = 0;
		var animating = false;
		var navigate = function(direction) {
			if(animating) {
				return;
			}

			if(direction == "next") {
				currentImg++;
				if(currentImg == photos.length + 1) {
					currentImg = 1;
				}
			} else {
				currentImg--;
				if(currentImg == 0) {
					currentImg = photos.length;
				}
			}

			var currentContainer = activeContainer;
			if(activeContainer == 1) {
				activeContainer = 2;
			} else {
				activeContainer = 1;
			}

			showImage(photos[currentImg - 1], currentContainer, activeContainer);
		};
	
		var currentZindex = -1;
		var showImage = function(photoObject, currentContainer, activeContainer) {
			animating = true;
		
			// Make sure the new container is always on the background
			currentZindex--;

			// Set the background image of the new active container
			$("#bg" + activeContainer)
				.attr("src", photoObject.image)
				.css({
					"display" : "block",
					"z-index" : currentZindex
				});

			// Hide the header text
			newsContainer.fadeOut(300, function() {
				// Set the new header text
				$("h3 a", newsContainer)
					.html(photoObject.title)
					.attr("href", photoObject.url);
				//$("h3 small a", newsContainer)
				//	.html(photoObject.category)
				//	.attr("href", photoObject.categoryUrl);
				$("p span", newsContainer)
					.html(photoObject.description);
				$("p em", newsContainer)
					.html(photoObject.date);
			});
		
			// Fade out the current container
			$("#bg" + currentContainer).fadeOut(function() {
				setTimeout(function() {
					newsContainer.fadeIn(300);
					gliderStatus.html(currentImg);
					Cufon.refresh();
					animating = false;
				}, 100);
			});
		};

		var stopAnimation = function() {
			clearInterval(interval);
		};

		navigate("next");

		//interval = setInterval(function() {
		//	navigate("next");
		//}, slideshowSpeed);
	}


	$(".listFiles li").mouseenter(function() {
		$(this).addClass("over");
	}).mouseleave(function() {
		$(this).removeClass("over");
	});


	if ($("input[type=radio]").length) {
		$("input[type=radio]").uniform();
	}


	if ($("#thumbs").length) {
		$("#thumbs li a").smoothScroll({
			easing: "easeInOutExpo",
			speed: 1000
		});
	}


	if ($("a[rel=expandStudy],a[rel=collapseStudy]").length) {
		$("a[rel=expandStudy]").click(function(e) {
			e.preventDefault();
			$(this).hide().parent().next().slideDown(200, function() {
				setStripeHeight();
			});
		});
		$("a[rel=collapseStudy]").click(function(e) {
			e.preventDefault();
			$(this).closest(".hidden").slideUp(200, function() {
				setStripeHeight();
			});
			$("a[rel=expandStudy]").show();
		});
	}


	if ($(".boxInGreen").length) {
		$(".boxInGreen, .boxInRed, .boxInBlue, .boxInMagenta").mouseenter(function() {
			$(this).find("span").css({opacity: 1});
		}).mouseleave(function() {
			$(this).find("span").css({opacity: 0.6});
		}).find("span").css({opacity: 0.6});
	}

	if ($(".tabs").length) {
		var tabs = $(".tabs");
		var tabsNav = $(".calendarNav ul", tabs);
		var tabsDiv = $(".tableCalendar", tabs);

		tabsDiv.filter(":not(:first)").hide();
		$("a:first", tabsNav).addClass("active");
		Cufon.replace(".calendarNav a", {hover: true, fontFamily: "DINPro-Bold"});

		$("a", tabsNav).bind("click", function(e) {
			e.preventDefault();
			$("a", tabsNav).removeClass("active");
			$(this).blur().addClass("active");
			tabsDiv.hide();
			$($(this).attr("href")).show();
			Cufon.replace(".calendarNav a", {hover: true, fontFamily: "DINPro-Bold"});
			$.smoothScroll({
				scrollTarget: ".tabs",
				easing: "easeInOutExpo",
				speed: 1000
			});
		});
		

	}

	if ($("a[rel=showLoginForm]").length) {
		$("a[rel=showLoginForm]").click(function(e) {
			e.preventDefault();
			$(this).hide();
			$(this).parent().next().show();
			$(this).closest(".boxInGreen, .boxInRed").height(340);
		});
	}


	if ($(".gallery-item a").length) {
		$(".gallery-item a").colorbox({
			rel: "group",
			opacity: 0.8,
			maxHeight: "90%"
		});
	}

	if ($("a[rel=colorbox]").length) {
		$("a[rel=colorbox]").colorbox({
			opacity: 0.8,
			maxHeight: "90%"
		});
	}


	if ($(".stripLeft").length) {
		window.setTimeout(setStripeHeight, 400);
	}


});

function setStripeHeight() {
	var bodyHeight = $(document).height();
	$(".stripLeft").each(function(i, e){
		var stripTop = Math.round($(e).offset().top);
		$(e).height(bodyHeight - stripTop);
	});
}
