$(document).ready(function(){
	/*
	/*
	/* prida znak # do odkazu s tridou link (aby bylo mozno klikat zpet)
	*/
	$("a.link").livequery(function(){
		var aLink = $(this).attr("href");
		var www = getWWWaddress();
		if(aLink.search(www) != -1) {
			l = www.length;
			cut = aLink.slice(l);
			$(this).attr("href", www + "#" + cut);
		} else if (aLink.search('http://') != -1) {
			
		} else {
			$(this).attr("href",  "#" + aLink);
		}
	})
	/*
	/*
	/* prida znak # do odkazu v topMenu (aby bylo mozno klikat zpet)
	*/
	$("#topMenu a").livequery(function(){
		var aLink = $(this).attr("href");
		var www = getWWWaddress();
		if(aLink.search(www) != -1) {
			l = www.length;
			cut = aLink.slice(l);
			$(this).attr("href", www + "#" + cut);
		} 
	})
	/*
	/*
	/* zjisti rel cestu k souboru
	*/
	function getPath() {
		var str=window.location.pathname;
		var ma=/(\/)([a-zA-Z0-9\-]+)/g;
		var path=str.replace(ma,"$1..");
		// pokud neni poslednim znakem lomitko, tak jej doplnim
		if ((path.lastIndexOf('/') + 1) == path.length) {
			return path;
		} else {
			return path + '/';
		}
	}
	/*
	/*
	/* zjisti www
	*/
	function getWWWaddress() {
	
		var odkaz = '' + window.location.hostname;
		var prtcl = '' + window.location.protocol;
		part = odkaz.split(".");
		return (prtcl + '//www.' + part[1] + '.' + part[2].replace("/", ""));
		
	}
	/*
	/*
	/* funkce vypise mailovou adresu vcetne html kodu
	*/
	$(".mailto").livequery(function(){
		var name = $(this).attr("rel");
		var domain = '@expedice-apalucha.com';
		$(this).empty();
		$(this).append('<a href="mailto:' + name + domain + '">' + name + domain + '</a>');
	});
	/*
	/*
	/* naloaduje stranku s obsahem
	*/
	$("#topMenu a").click( function() {
		$("#middle").empty();
		$("#middle").append("<img src='" + getWWWaddress() + "/html/img/ico/spacer.gif' width='796px' height='1px' />");
		$("#middle").append("<img src='" + getWWWaddress() + "/html/img/ico/loading.gif' />");
		var id = $(this).parent().attr("id");
		$("#topMenu li a").removeClass("active");
		$(this).addClass("active");
		// getPath()+
		$.get(getPath()+id+".php", 
			  { jquest:1, act:0, id:id },
			  function(json){
				  if(json.search("##__OK__##") != -1) {
						$("#middle").empty();
						$("#middle").append(json.replace("##__OK__##", ""));
						$('html, body').animate({scrollTop:0}, 'quick');
					} else {
						alert(json);
					}
			  }
		);
		//return false;
	} );
	/*
	/*
	/* naloaduje stranku s obsahem
	*/
	$("a.link").livequery(function(){
	$(this).click( function() {
		$("#middle").empty();
		$("#middle").append("<img src='" + getWWWaddress() + "/html/img/ico/spacer.gif' width='796px' height='1px' />");
		$("#middle").append("<img src='" + getWWWaddress() + "/html/img/ico/loading.gif' />");
		var id = $(this).attr("rel");
		$("#topMenu li a").removeClass("active");
		$("#topMenu li#"+id+" a").addClass("active");
		// getPath()+
		$.get(getPath()+id+".php", 
			  { jquest:1, act:0, id:id },
			  function(json){
				  if(json.search("##__OK__##") != -1) {
						$("#middle").empty();
						$("#middle").append(json.replace("##__OK__##", ""));
						$('html, body').animate({scrollTop:0}, 'quick');
					} else {
						alert(json);
					}
			  }
		);
		// return false;
	} );
   });
	/*
	/*
	/* slider na uvodni obrazovce
	*/
	$('ul#slides').livequery(function(){
		$(this).innerfade({
			speed: 1000,
			timeout: 5000,
			type: 'sequence',
			containerheight: '225px'
		});
	});
	/*$(".car").livequery(function(){
		$(function() {
			$(".car").jCarouselLite({
				
				visible: 1,
				auto: 3000,
				speed: 1000,
				easing: "easeinout"
			});
		});
	});*/
	/*
	/*
	/* nacteni formulare pro vlozeni vzkazu
	*/
	$(".napsat_vzkaz").livequery(function(){
		$(this).click( function() {
			var concert_id = $(this).attr("rel");
			jQuery.facebox(function() { //getPath()+
			  jQuery.post(getPath()+'vzkazy.php', 
				{ jquest:1, act:1, concert_id:concert_id},
				function(data) {
					jQuery.facebox(data)
			  })
			})
			return false;
		});
	});
	$("#vzkazForm").livequery(function(){
		$(this).submit( function() {
			$("#topMenu li a").removeClass("active");
			$("#vzkazy a").addClass("active");
			var name = $("#name").attr("value");
			var concert_id = $("#concert_id").attr("value");
			var text = $("#text").attr("value");
			jQuery.facebox(function() { //getPath()+
			  jQuery.post(getPath()+'vzkazy.php', 
				{ jquest:1, act:1, submited:1, name:name, text:text, concert_id:concert_id},
				function(data) {
					if(data.search("##__OK__##") != -1) {
						jQuery.facebox('<p class="mess">Vzkaz byl vložen.</p>');
						$("#middle").empty();
						$("#middle").append(data.replace("##__OK__##", ""));
						/*$("#facebox").remove();
						$('#facebox_overlay').remove();
						$(document).unbind('.facebox');*/
						//jQuery.facebox.facebox_close();
						//$('#facebox .close').ready(facebox_close);
						//$(document).ready(function(){jQuery.facebox(facebox_close)});
						//jQuery(document).trigger("close.facebox");
						
					} else {
						jQuery.facebox(data);
					}
					
			  })
			})
			return false;
		});
	});
	/*
	/*
	/* nacteni formulare pro pozvani na koncert
	*/
	$(".pozvat").livequery(function(){
		$(this).click( function() {
			id = $(this).attr("rel");
			jQuery.facebox(function() { //getPath()+
			  jQuery.post(getPath()+'koncerty.php', 
				{ jquest:1, act:1, id:id},
				function(data) {
					jQuery.facebox(data)
			  })
			})
			return false;
		});
	});
	/*
	/*
	/* kontrola odesilaneho formulare pozvanky
	*/
	$("#pozvanka").livequery(function(){
		$(this).submit( function() {
			id = $("#cid").attr("value");
			name = $("#name").attr("value");
			fromEmail = $("#fromEmail").attr("value");
			toEmail = $("#toEmail").attr("value");
			subject = $("#subject").attr("value");
			text = $("#text").attr("value");
			jQuery.facebox(function() { //getPath()+
			  jQuery.post(getPath()+'koncerty.php', 
				{ jquest:1, act:1, id:id, submited:1, name:name, fromEmail:fromEmail, toEmail:toEmail, subject:subject, text:text},
				function(data) {
					if(data.search("##__OK__##") != -1) {
						jQuery.facebox(data.replace("##__OK__##", ""));
					} else {
						jQuery.facebox(data);
					}
					
			  })
			})
			return false;
		});
	});
	/*
	/*
	/* kontrola odesilaneho formulare
	*/
	$("#shopForm").livequery(function(){
		$(this).submit( function() {
			$("body").removeAttr("onbeforeunload")
		});
	});
	/*
	/*
	/* nacteni textu pisne
	*/
	$(".songText").livequery(function(){
		$(this).click( function() {
			id = $(this).attr("id");
			id = id.replace("text_", "")
			jQuery.facebox(function() { //getPath()+
			  jQuery.post(getPath()+'hudba.php', 
				{ jquest:1, act:1, id:id},
				function(data) {
					jQuery.facebox(data)
			  })
			})
			return false;
		});
	});
	/*
	/*
	/* nacteni videa
	*/
	$(".video").livequery(function(){
		$(this).click( function() {
			id = $(this).attr("id");
			id = id.replace("v_", "")
			jQuery.facebox(function() { //getPath()+
			  jQuery.post(getPath()+'foto-video.php', 
				{ jquest:1, act:1, id:id, typ:"video"},
				function(data) {
					jQuery.facebox(data)
			  })
			})
			return false;
		});
	});
	/*
	/*
	/* nacteni galerie
	*/
	$(".gFoto a").livequery(function(){
		$(this).facebox();
    });
	$(".gal").livequery(function(){
		$(this).click( function() {
			id = $(this).attr("id");
			id = id.replace("f_", "") //getPath()+
			$("#gFoto_"+id).append("<img src='http://www.expedice-apalucha.com/html/img/ico/loading.gif' />");
			$.get(getPath()+"foto-video.php", 
			  { jquest:1, act:1, id:id, typ:"gal" },
			  function(json){
				  if(json.search("##__OK__##") != -1) {
					  	$(".gFoto").slideUp("quick").empty();
					  	$("#gFoto_"+id).empty();
						$("#gFoto_"+id).css({ display: "none" });
						$("#gFoto_"+id).append(json.replace("##__OK__##", ""));
						$("#gFoto_"+id).slideDown("slow");
						$('.gFoto a').facebox();
					} else {
						alert(json);
					}
			  }
			);
			return false;
		});
	});
	
});
