$(document)
		.ready(
				function() {
					$(function() {
						var flowImages = new ImageFlow();
						flowImages.init({
							ImageFlowID : 'flowImages',
							// imagesM: 0.8,
							xStep : 43,
							// percentLandscape: 166,
							percentOther : 30,
							circular : true,
							imageFocusM : 1.5,
							imageFocusMax : 6,
							captions : true,
							slider : false,
							imageScaling : true,
							reflectionGET : '&bgc=F2F2F2&fade_start=20%', // &height=35%
							reflectPath : HTTP_PATH + "resources/imageFlow/",
							imageCursor : 'pointer',
							buttons : false,
							sliderCursor : 'pointer',
							slideshow : true,
							slideshowAutoplay : true,
							slideshowSpeed : 5000
						});
					});
					$("#guidepostTabs").tabs();

					var closeTimer = false;
					var zobrazitZa = 5000;
					$("#eonspot").css({
						display : "block"
					});
					var topSideTimer = setTimeout(function() {
						$("#eonspot").animate({
							bottom : 55
						}, 500);
						return true;
					}, zobrazitZa);

					$("a#closeTopSide").click(function() {
						$(this).parent().animate({
							bottom : '-=' + ($(this).parent().height() + 10)
						}, 500)
						clearTimeout(topSideTimer);
						return false;
					});
					$(".pozvanka").click(
							function() {
								window.location = $(this).find(
										"input[name=href]").val();
							})

					// var myself = new nickyslideshow(".slideshow", 10000,
					// '.slideshowControl');
					// myself.run();
					$
							.getScript(
									HTTP_PATH
											+ "resources/jQuery/billy.carousel.jquery.js",
									function() {
										$('#fader').billy({
											// transition: 'fade',
											transition : 'scroll',
											slidePause : 10000000,
											// We need custom next/prev buttons
											// for this example. If
											// we used the defaults
											// (#billy_next/#billy_prev), every
											// carousel instance on the page
											// would scroll when
											// they're clicked...
											nextLink : $('#fader_next'),
											prevLink : $('#fader_prev')
										// ,
										// indicators: $('#fade_indicators')
										});
										center = $("#fader_control").width()
												/ 2
												- $("div#fader_prev_shadow")
														.width();
										sizeSmall = $("div#fader_next_shadow")
												.css("font-size");
										sizeBig = $(
												"#fader_control h3.mainHeading")
												.css("font-size");
										s_width = $("div#fader_prev_shadow")
												.width();
										$('#fader_next, #fader_prev')
												.click(
														function() {
															/*
															 * var prev =
															 * currentslide - 1;
															 * if(prev < 0) prev =
															 * fader_labels.length -
															 * 1; var next =
															 * currentslide + 1;
															 * if(next >=
															 * fader_labels.length)
															 * next = 0;
															 * $("div#fader_prev_shadow").text(fader_labels[prev]);
															 * $("#fader_control
															 * h3.mainHeading").text(fader_labels[currentslide]);
															 * $("div#fader_next_shadow").text(fader_labels[next]);
															 */
															if (cooling) {
																$(
																		"div#fader_prev_shadow")
																		.text(
																				fader_labels[prev]);
																$(
																		"#fader_control h3.mainHeading")
																		.text(
																				fader_labels[currentslide]);
																$(
																		"div#fader_next_shadow")
																		.text(
																				fader_labels[next]);
															} else
																vycoolovat();
															return false;
														});
									});
					/*
					 * $(function(){ //$("#facebookMain").html('');
					 * //FB.init("c14c86f026c3bf8cad4269f2f037a0ef"); //<script
					 * src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
					 * 
					 * //$.getScript('http://connect.facebook.net/cs_CZ/all.js#xfbml=1',
					 * function(){ //$("#facebookMain").html('<fb:fan
					 * profile_id="135047516526618" show_faces="false"
					 * stream="false" header="false" width="458" height="110"
					 * css="' + HTTP_PATH +
					 * 'templates/erf2011/css/facebook.css?1.0"></fb:fan>');
					 * //FB.init("c14c86f026c3bf8cad4269f2f037a0ef"); //
					 * $("#facebookMain").html('<fb:like-box
					 * href="http://www.facebook.com/eonrodinnyfotbalek"
					 * width="458" show_faces="false" stream="false"
					 * header="false"></fb:like-box>'); //});
					 * 
					 * });
					 */
					coolSlideGlide();
					calendarToolTip();
					changeEuro();
				});
var fader_labels = [ 'Aktuáln\u011b', 'E.ON Rodinné turnaje',
		'E.ON Fotbalová rodina', 'Petr \u010cech', 'E.ON Junior Cup',
		'E.ON Vybavení klub\u016f' ];
var lastslide = 0;
var timeVC = 500;
var posLeft = 0;
var posRight = 0;
var center;
var sizeSmall;
var sizeBig;
var s_width;
var cooling = false;

function vycoolovat() {
	cooling = true;
	var prev = currentslide - 1;
	if (prev < 0)
		prev = fader_labels.length - 1;
	var next = currentslide + 1;
	if (next >= fader_labels.length)
		next = 0;

	moveLeft2Right = false;
	if ((!(currentslide == fader_labels.length - 1 && lastslide == 0) && currentslide > lastslide)
			|| (currentslide == 0 && lastslide == fader_labels.length - 1))
		moveLeft2Right = true;

	if (moveLeft2Right) {
		$("#fader_control h3.mainHeading").css({
			textAlign : 'right',
			opacity : 0.0,
			fontSize : sizeSmall
		}).text(fader_labels[next]).animate({
			opacity : 0.0
		}, timeVC, function() {
			$(this).text(fader_labels[currentslide]).css({
				textAlign : 'center',
				fontWeight : 'bold',
				fontSize : sizeBig,
				opacity : 1.0
			});
			cooling = false;
		});

		$("div#fader_prev_shadow").text(fader_labels[lastslide]).css({
			left : center,
			width : s_width * 2,
			fontSize : sizeBig
		}).animate({
			left : 0,
			width : s_width,
			fontSize : sizeSmall
		}, timeVC, function() {
			$(this).text(fader_labels[prev]).css("opacity", 1.0);
		});

		$("div#fader_next_shadow").text(fader_labels[currentslide]).animate({
			right : "+=" + center,
			width : s_width * 2,
			fontSize : sizeBig
		}, timeVC, function() {
			$("div#fader_next_shadow").css({
				right : posRight,
				fontSize : sizeSmall,
				width : s_width + "px"
			}).text(fader_labels[next]);
		});
	} else {
		$("#fader_control h3.mainHeading").css({
			textAlign : 'left',
			opacity : 0.0,
			fontSize : sizeSmall
		}).text(fader_labels[prev]).animate({
			opacity : 0.0
		}, timeVC, function() {
			$(this).text(fader_labels[currentslide]).css({
				textAlign : 'center',
				fontWeight : 'bold',
				fontSize : sizeBig,
				opacity : 1.0
			});
			cooling = false;
		});

		$("div#fader_prev_shadow").animate({
			left : '+=' + center,
			width : s_width * 2,
			fontSize : sizeBig
		}, timeVC, function() {
			$("div#fader_prev_shadow").css({
				left : posLeft,
				fontSize : sizeSmall,
				width : s_width + "px"
			}).text(fader_labels[prev]);
			// $("#fader_control
			// h3.mainHeading").text(fader_labels[currentslide]);
		});
		$("div#fader_next_shadow").text(fader_labels[currentslide]).css({
			right : center,
			width : s_width * 2,
			fontSize : sizeBig
		}).animate({
			right : 0,
			fontSize : sizeSmall,
			width : s_width
		}, timeVC, function() {
			$(this).text(fader_labels[next]).css("opacity", 1.0);
		});
		$("div#fader_next_shadow").text(fader_labels[next]);
	}

	// $("#fader_control h3.mainHeading").text(fader_labels[currentslide]);
	//
	lastslide = currentslide;
}

/**
 * Vycooluje superglide na obrázky
 */
function coolSlideGlide() {

	var activeClass = "sliderCenter";
	var $body = $("#sliderTapeBody");
	var $tape = $body.children("#sliderTape");
	var $images = $tape.find("a.sliderImage");
	var $activeImage = $tape.find("a.sliderImage." + activeClass);
	var height = $tape.find("a.sliderImage").height();
	var $sipka1 = $("#sliderDefault a.sliderArrow.topArrow");
	var $sipka2 = $("#sliderDefault a.sliderArrow.bottomArrow");
	var $mainImage = $("#mainFoto img");
	var bodyHeight = $body.height();
	var visibleImages = bodyHeight / height;
	var center = bodyHeight / visibleImages;
	var offset = 10;
	var animationTime = 250;
	var playTime = 10000; // ms == 1/1000s
	var pauseTime = 3 * playTime; // ms == 1/1000s
	// srovnání o délku playTIme
	pauseTime -= playTime;
	var timer;
	var playing = false;
	var onpause = false;
	$mainImage.parent().css("position", "relative");
	$mainImage.css({
		position : "absolute",
		top : 0,
		left : 0,
		zIndex : 100
	});
	jumpTo = function($image) {
		$activeImage.removeClass(activeClass);
		$activeImage = $image;
		$activeImage.addClass(activeClass);
		slideToImage($activeImage);
		changeMainImage();
	}

	jumpToPrev = function() {
		var $image = $activeImage.prev();
		if ($image.length > 0)
			jumpTo($image);
	}

	jumpToNext = function() {
		var $image = $activeImage.next();
		if ($image.length > 0) {
			jumpTo($image);
			return true;
		}
		return false
	}

	slideToImage = function($image) {
		var top = $image.position()['top'];
		var position = 0;

		if ($image.next().length == 0) {
			top = $image.prev().position()['top'];
		}
		position = center - top;
		/*
		 * if (position < -center) position = -center - offset; else position +=
		 * offset;
		 */
		if (position > 0)
			position = 0;
		$tape.animate({
			top : position
		}, animationTime);

	}

	changeMainImage = function() {
		var img = new Image();
		img.src = $activeImage.attr("rel") + "#"
				+ Math.round(Math.random() * 999);
		img.onload = function() {
			var $tempImage = $mainImage.clone();
			$tempImage.css({
				zIndex : 110
			});
			$mainImage.parent().append($tempImage);
			$mainImage.attr({
				"src" : img.src,
				"alt" : $activeImage.attr("title"),
				"title" : $activeImage.attr('title')
			});
			$mainImage.parent().attr({
				"href" : $activeImage.attr('href'),
				"title" : $activeImage.attr('title')
			});
			$tempImage.animate({
				opacity : 0.0
			}, animationTime, function() {
				$tempImage.remove();
			});

		};
		// img.onLoad();
	}

	$sipka1.click(function() {
		jumpToPrev();
		return false;
	});

	$sipka2.click(function() {
		jumpToNext();
		return false;
	});

	$images.click(function() {
		pause();
		jumpTo($(this));
		return false;
	});

	play = function() {
		if (!playing) {
			timer = setInterval(function() {
				if (!jumpToNext())
					jumpTo($images.first());
			}, playTime);
			playing = true;
		}
	}

	stop = function() {
		if (playing) {
			clearInterval(timer);
			playing = false;
		}
	}

	pause = function() {
		if (!onpause) {
			stop();
			setTimeout(function() {
				play();
				onpause = false
			}, pauseTime);
		}
		onpause = true;
	}

	jumpTo($activeImage);
	play();
}

function calendarToolTip() {
	$("#main_kalendar td a.showTooltip, .temlplateHalf a.showTooltip").tooltip(
			{
				effect : 'fade',
				relative : true,
				position : 'top center',
				offset : [ 0, 0 ]
			// offset: [-100, 0]
			});
}

function changeEuro() {
	var counter = 1;
	var counter2 = 0;
	var $visible = $("div.euro").first();
	// $("div.euro").parent().children('h4').hide();
	// $("div.euro").parent().children('h4').first().show();

	$visible.show();
	if ($visible.length > 0) {
		var $hidden = $('div.euro:eq(1)');

		$("div.euro").parent().height(208);

		$("div.euro").css({
			'position' : 'absolute',
			'opacity' : 0,
			'display' : 'block'
		}).hide();

		$visible.css('opacity', '1').show();

		timer = setInterval(function() {

			swap();

		}, 10000);

		swap = function() {

			$visible.animate({
				opacity : 0
			}).hide();
			$hidden.show().animate({
				opacity : 1
			});
			$visible = $hidden;
			if ($hidden.next("div.euro").length == 0) {
				$hidden = $visible.prev("div.euro");
			} else {
				$hidden = $visible.next("div.euro");
			}
			// $hidden = $('div.euro:eq(' + counter2 + ')');
			// if(counter2 >= 2) counter2 = 0;
			// counter2++;
			// if(counter >= 2)
			// {
			// counter = 1;
			// $("div.euro").parent().children('h4:visible').hide().siblings('h4').show();
			// }
			// else
			// {
			// counter++;
			// }

			// alert(counter + ': '+$visible.text());
		};
	}

}
