$(document).ready(function() {

	$("body").delegate(".vsechny_linky_externi a","click",function(){
		window.open($(this).attr('href'));
		return false;
	});

	$("body").delegate("a.externi","click",function(){
	//$(".externi").click(function(){
		window.open($(this).attr('href'));
		return false;
	});
	
	if($("#web_id_1218 .content_o").length > 0) {
		a = $("#web_id_1218 .content_o").height();
		$("#web_id_1218 .bok_ram").css('min-height', a+'px');
	}
	
	$(".autoform_submit").css('display', 'none');
	$(".autoform_select").change(function(){
		//$(this).parents().attr('rel2'));
		$('.autoform').submit();
	});

	//polyweb.cz
	$(".hla_socialno .facebook_like_button").each(function(){
		$(this).html('<iframe src="//www.facebook.com/plugins/like.php?href='+$(this).attr('rel')+'&amp;send=false&amp;layout=button_count&amp;width=85&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" class="button_facebook" allowTransparency="true"></iframe>');
	});
	
	$(".petka_o").each(function(){
		id = $(this).attr('id');
		$("#"+id+" h2 a").each(function(){
			odkaz = $("#"+id+" h2 a").attr('href');
			if(odkaz == '' || odkaz == '#') {  } else {
				obrazek = '<a href="'+odkaz+'">'+$("<div />").append($("#"+id+" img").clone()).html()+'</a>';
				$("#"+id+" img").remove();
				$("#"+id+" .petka_i").html(obrazek+$("#"+id+" .petka_i").html());
				$("#"+id+" .petka_i p").html($("#"+id+" .petka_i p").html()+' <a href="'+odkaz+'">zde</a>.');
			}
		});
	});
	
	$(".top_Menu .li_id_1582 a span").html('<span class="sipka_home"></span>');
	$(".top_Menu .li_id_1582 a.active span").html('<span class="sipka_home2"></span>');
	
	$(".footerA_o .formular table td:first-child").each(function(){
		$(this).addClass('popis_obal');
	});
	/*
	max = 4;
	i=0;
	$(".footerA_o .formular table td+td").each(function(){
		if(i<max) {
			$(this).html('<td><div class="input_obal_o"><div class="input_obal_i">'+$(this).html()+'</div></div></td>');
			i++;
		}
	});
	*/
	
	//fitness14
		var sliderlevel = 1;
		var sliderpocet = 0;
		var sliderbeh = 0;
		var slidersirka = $("#slider-banner2 a").width();
		//vykreslime dle poctu dole ty ctverecky
		$("#slider-banner2").each(function(){
				$(this).find("a").each(function(){
					if(sliderpocet == 0) { slidertajny = $("<div />").append($(this).clone()).html(); }
					sliderpocet++;
					if(sliderpocet == 1) {
						$("#slider-banner-pod").html($("#slider-banner-pod").html()+'<span class="slider-pod-bannerem slider-pod-bannerem_aktiv slider-pod-bannerem'+sliderpocet+'"></span>');
					} else {
						$("#slider-banner-pod").html($("#slider-banner-pod").html()+'<span class="slider-pod-bannerem slider-pod-bannerem'+sliderpocet+'"></span>');
					}
				});
		});
		if(sliderpocet > 1) {
			//pridat tajny na konec
				$("#slider-banner2").html($("#slider-banner2").html()+slidertajny);
			//spustit casovac
				sliderspust();
		}
		$('#slider-sip1').mouseover(function() { clearTimeout(sliderbeh); });
		$('#slider-sip2').mouseover(function() { clearTimeout(sliderbeh); });
		$('#slider-banner2').mouseover(function() { clearTimeout(sliderbeh); });
		$('#slider-banner2').mouseout(function() { sliderspust(); });
		
		$("#slider-sip1").click(function(){ sliderdalsi(); });
		$("#slider-sip2").click(function(){ sliderpredchozi(); });
		
		function sliderdalsi() {
			nastav_pod_box(0);
			//alert(slidersirka);
			if(sliderlevel == sliderpocet) {
				//$("#slider-banner2").stop().animate({ left: '0',  }, 500, function(){ sliderlevel=1; nastav_pod_box(sliderlevel); sliderspust(); });
				$("#slider-banner2").stop().animate({ left: (sliderlevel+0)*-slidersirka,  }, 1000, function(){ sliderlevel=1; nastav_pod_box(sliderlevel); sliderspust(); $("#slider-banner2").css('left', '0px'); });
			} else {
				$("#slider-banner2").stop().animate({ left: sliderlevel*-slidersirka,  }, 1000, function(){ sliderlevel++; nastav_pod_box(sliderlevel); sliderspust(); });
			}
		}
		
		function sliderpredchozi() {
			nastav_pod_box(0);
			if(sliderlevel == 1) {
				$("#slider-banner2").css('left', (sliderpocet)*-slidersirka+'px');
				$("#slider-banner2").stop().animate({ left: (sliderpocet-1)*-slidersirka,  }, 1000, function(){ sliderlevel=4; nastav_pod_box(sliderlevel); sliderspust(); });
			} else {
				$("#slider-banner2").stop().animate({ left: (sliderlevel-2)*-slidersirka,  }, 1000, function(){ sliderlevel--; nastav_pod_box(sliderlevel); sliderspust(); });
			}
		}
		
		function sliderspust() {
			if(sliderbeh) { clearTimeout(sliderbeh); }
			sliderbeh = setTimeout(sliderdalsi, 3000);
		}
		
		function nastav_pod_box(cislo) {
			 //$('.slider-pod-bannerem').css('background', '#dcdcdc');
			 $('#slider-banner-pod span').removeClass('slider-pod-bannerem_aktiv');
			 if(cislo > 0) {
				//$('.slider-pod-bannerem'+cislo).css('background', '#b10061');
				$('.slider-pod-bannerem'+cislo).addClass('slider-pod-bannerem_aktiv');
			 }
		}
	
	//fancybox
		$(".gallery_pict a").fancybox({
			onStart: function() { $('embed, object, iframe').css('visibility', 'hidden'); },
			onClosed: function() { $('embed, object, iframe').css('visibility', 'visible'); },
			'autoScale'     	: false
		});
		$("#web_id_398 .k_typ1_obsah_o a").fancybox({
			onStart: function() { $('embed, object, iframe').css('visibility', 'hidden'); },
			onClosed: function() { $('embed, object, iframe').css('visibility', 'visible'); },
			'titlePosition': 'inside'
		});
		
		if($("#web_id_1428 .blok_o_6530 .gallery_cont").length > 0) {
			$("#web_id_1428 .blok_o_6530 .gallery_cont .gallery_pict").each(function(){
				$(this).find("a img").each(function(){
					x = $(this).attr('title');
				});
				if(x.length > 0) {
					//alert(x);
					$(this).find("a").each(function(){
						$(this).html($(this).html()+'<br />'+x);
					});
				}
			});
		}
		if($(".blok_o_6775 .formular .check_all input").length > 0) {
			$(".blok_o_6775 .formular .check_all input").attr("checked", "checked");
		}
		if($(".blok_o_6814 .formular .check_all input").length > 0) {
			$(".blok_o_6814 .formular .check_all input").attr("checked", "checked");
		}
		if($("#web_id_1428 .formular .check_all input").length > 0) {
			$("#web_id_1428 .formular .check_all input").attr("checked", "checked");
		}
		
		if($("#web_id_1193 .hp .re_box_i a").length > 0) {
			a = $("#web_id_1193 .hp .re_box_i a").html();
			$("#web_id_1193 .hp .re_box_i a").html(a+'<img src="/theme/ckreality/hp/play.png" class="hp_video_play" />');
		}

		if($("#web_id_1193 .content_o .info1_i").length > 0) {
			$("#web_id_1193 .content_o .info1_i").each(function(){
				var h;
				h = 0;
				$(this).find(".info_ico .info_video").each(function(){
					if($(this).length > 0) {
						h = 1;
					} else {
						h = 0;
					}
				});
				if(h==1) {
					$(this).find("h2 a").each(function(){
						$(this).html($(this).html()+'<img src="/theme/ckreality/hp/play2.png" class="hp_video_play2" />');
					});
				}
			});
		}

		$("table .nemovitost_devel_nahled_td a").fancybox({
			onStart: function() { $('embed, object, iframe').css('visibility', 'hidden'); },
			onClosed: function() { $('embed, object, iframe').css('visibility', 'visible'); },
			'autoScale'     	: false
		});
		//$(".nemovitost_foto_big a").fancybox();
		
		$(".foto_foto_obal a").fancybox({
			onStart: function() { $('embed, object, iframe').css('visibility', 'hidden'); },
			onClosed: function() { $('embed, object, iframe').css('visibility', 'visible'); }
		});
		$(".foto_mapa a").fancybox({
			onStart: function() { $('embed, object, iframe').css('visibility', 'hidden'); },
			onClosed: function() { $('embed, object, iframe').css('visibility', 'visible'); }
		});

		$(".blok_i table").find("tr").not(":even").addClass("sudy"); 
		$(".blok_i table").find("tr").not(":odd").addClass("lichy"); 

	if($("#mapa_google_presna").length > 0) {
		$("#mapa_google_presna").ready(function(){
			var exploded = $("#mapa_google_presna").html().split(',');
			function initialize() {
				geocoder = new google.maps.Geocoder();
				var latlng = new google.maps.LatLng(exploded[0], exploded[1]);
				var myOptions = {
					zoom: 15,
					center: latlng,
					mapTypeId: google.maps.MapTypeId.ROADMAP
				}
				map = new google.maps.Map(document.getElementById("mapa_google_presna"), myOptions);
				var marker = new google.maps.Marker({
					position: new google.maps.LatLng(exploded[0], exploded[1]),
					map: map
				});
			}
			initialize();
		});
	}
		
	if($("#mapa_google").length > 0) {
		$("#mapa_google").ready(function(){
			function codeAddress(address) {
				geocoder.geocode( { 'address': address}, function(results, status) {
					if (status == google.maps.GeocoderStatus.OK) {
						map.setCenter(results[0].geometry.location);
						var marker = new google.maps.Marker({
								map: map, 
								position: results[0].geometry.location
						});
					} else {
						alert("Geocode was not successful for the following reason: " + status);
					}
				});
			}
			function initialize() {
				geocoder = new google.maps.Geocoder();
				var latlng = new google.maps.LatLng(0, 0);
				var myOptions = {
					zoom: 15,
					center: latlng,
					mapTypeId: google.maps.MapTypeId.ROADMAP
				}
				misto = $('#mapa_google').html();
				map = new google.maps.Map(document.getElementById("mapa_google"), myOptions);
				codeAddress(misto);
			}
			initialize();
		});
	}
	//mapa - starts
		//if(typeof initialize == 'function') {
			//initialize();
		//}

	$(".spust_tisk").click(function(){
		print();
		return false;
	});

	$(".reality_box_i .nemovitost_foto_small a img").click(function(){
		$(".reality_box_i .nemovitost_foto_big a").attr('href', $(this).parents().attr('href'));
		$(".reality_box_i .nemovitost_foto_big a").attr('title', $(this).parents().attr('title'));
		$(".reality_box_i .nemovitost_foto_big a img").attr('src', $(this).parents().attr('rel'));
		$(".reality_box_i .nemovitost_foto_big a img").attr('rel', $(this).parents().attr('rel2'));
		$(".reality_box_i .nemovitost_foto_small a img").removeClass('akt');
		$(this).addClass('akt');
		return false;
	});
	$(".reality_box_i .nemovitost_foto_big a img").click(function(){
		src = $(this).attr('src');
		rel = $(this).attr('rel');
		$(this).attr('src', rel);
		$(this).attr('rel', src);
		$(".reality_box_i .nemovitost_foto_small a").each(function() {
			rel = $(this).attr('rel');
			rel2 = $(this).attr('rel2');
			$(this).attr('rel', rel2);
			$(this).attr('rel2', rel);
		});
		if($(".reality_ovladani").length > 0) {
			//alert('existuje');
			$(".reality_box_i .nemovitost_foto").removeClass('nemovitost_foto2');
			$(".reality_ovladani").remove();
		} else {
			$(".reality_box_i .nemovitost_foto").addClass('nemovitost_foto2');
			//$(".reality_box_i .nemovitost_foto_small").after('<div class="reality_ovladani"><span>X</span></div>');
			$(".reality_box_i .nemovitost_foto_small").after('<div class="reality_ovladani"> </div>');
		}
		return false;
	});

	if($("body#web_id_398 .head_o").length > 0) {
		x = Math.floor(Math.random()*2001);
		y = Math.floor(Math.random()*2001);
		x2 = Math.floor(Math.random()*11)-5;
		y2 = Math.floor(Math.random()*11)-5;
		if(x2 == 0) { x2 = -2; }
		if(y2 == 0) { y2 = -2; }
		if(posun_pozadi('body#web_id_398', x, y)) {
			window.setInterval("posun_pozadi('body#web_id_398 .head_o', "+x2+", "+y2+")", 100);
		}
		//posun_pozadi('body#web_id_398', 10, 10);
	}
	
	$(".gallery_typ_2_small a img").click(function(){
		promena = $(this).parents().attr('rel');
		$(".gallery_typ_2_"+promena+" .gallery_typ_2_big a").attr('href', $(this).parents().attr('rel2'));
		$(".gallery_typ_2_"+promena+" .gallery_typ_2_big a").attr('title', $(this).parents().attr('title'));
		$(".gallery_typ_2_"+promena+" .gallery_typ_2_big .popisek_typ_2").html($(this).parents().attr('title'));
		$(".gallery_typ_2_"+promena+" .gallery_typ_2_small a img").removeClass('akt');
		$(this).addClass('akt');
		//http://demo6.diskety.cz/img/2011/420x315/g_46_1.jpg
		$(".gallery_typ_2_"+promena+" .gallery_typ_2_big a img").attr('src', $(this).parents().attr('href'));
		return false;
	});
	
	$(".gallery_typ_2_big a").fancybox({
		onStart: function() { $('embed, object, iframe').css('visibility', 'hidden'); },
		onClosed: function() { $('embed, object, iframe').css('visibility', 'visible'); },
		'titleShow'	:	true,
		'titlePosition'	:	'inside'
	});

	$(".gallery_typ_3_big a, .gallery_typ_3_small a").fancybox({
		onStart: function() { $('embed, object, iframe').css('visibility', 'hidden'); },
		onClosed: function() { $('embed, object, iframe').css('visibility', 'visible'); },
		'titleShow'	:	true,
		'titlePosition'	:	'inside'
	});


	$('.magazin_o_urchin a').each(function() {
		var $a = $(this);
		var href = $a.attr('href');
		$a.click(function() { 
			pageTracker._trackPageview('/magazin/' + href);
		});
	});



});

	function posun_pozadi(prvek, x, y) {
		puvodni = $(prvek).css('background-position');
		puvodni = puvodni.replace('px', '');
		puvodni = puvodni.replace('px', '');
		casti = puvodni.split(' ');
		nastav_x = (casti[0]*1)+(x*1);
		nastav_y = (casti[1]*1)+(y*1);
		if(nastav_x  && nastav_y ) {
			//alert(nastav_x +'.'+ nastav_y);
			$(prvek).css('background-position', nastav_x+'px ' +nastav_y+'px');
		}
		return true;
	}
