//document.write('<script type="text/javascript" src="js/jquery.address-1.3.2.min.js?tracker=track"></script>');
document.write('<script type="text/javascript" src="js/jquery.livequery.js"></script>');
document.write('<script type="text/javascript" src="js/jquery.form.js"></script>');

$(function() {

	$('#coin-slider').show();
	$('#coin-slider').coinslider( {
		width : 900,
		height : 300
	});

	$(".show_logo").livequery(function() {
		var room = $(this).attr('id').split("_");
		$(this).html($("#pozycja_" + room[1]).html());
	});
	
	$(".tooltip_div").livequery(function() {
		var room = $(this).attr('id').split("_");
		$(this).html($("#logo_" + room[1]).html());
	});

	$(".plan_show").livequery(function() {
		
		var room = $(this).attr("room");
		
		$(this).mouseover(function() {
			$(".tooltip_div").hide();
			$("#tooltip_" + room).show();
		});

		$(this).mouseout(function() {
			$(".tooltip_div").hide();
		});
	});
	
	$(".choose_floor").livequery(function (){
		$(this).click(function (){
			$(".choose_floor").removeClass('bolder');
			$(this).addClass("bolder");
		});
	});
	/*
	$('a.lm[href^="#"]').livequery(function() {
		$(this).click(function() {

			var obj = $("a.subtitle");
			obj.removeClass("subtitle");
			obj.addClass("left_menu");
			$(this).removeClass("left_menu");
			$(this).addClass("subtitle");

			var title = $(this).attr('title');
			$('#napis').fadeOut('fast', function() {
				$('#napis').html(title);
				$('#napis').fadeIn();
			});

			$('.reload').fadeIn();
			$('#container').html($($(this).attr('href') + '').html());
			$('.reload').fadeOut();
			return false;
		});
	});*/

	$("a.tooltip").livequery(function() {
		var link = $(this).attr("href");
		$(this).attr("pid", $(link).attr("pid"));
		$(this).tooltip( {
			bodyHandler : function() {
				return ($(link) != null) ? $(link).html() : "wolne";
			},
			showURL : false
		});
	});

	Shadowbox.init({
		overlayOpacity: 0.2
	});
	
	$("a.show_on_plan").live('click',function(){
		//alert("tira rira!");
		$(this).unbind('click');

			
			Shadowbox.close();
			
			$('.reload').fadeIn();
			var title = "PLAN";
			$('#napis').fadeOut('fast', function() {
				$('#napis').html(title);
				$('#napis').fadeIn();
			});
			$.ajax( {
				url : $(this).attr('href'),
				success : function(data) {
					$('#container').html(data);
					$('.reload').fadeOut();
					return false;
				}
			});
			
			return false;

	});

	$("a.tooltip").livequery(function() {
		$(this).unbind('click');
		var open = $(this).attr("rel");
		var pid = $(this).attr("pid");
		$(this).click(function() {
			$('.reload').fadeIn();
			$.ajax( {
				url : "index.php?mode=wystawcy&ajax=1&pid=" + pid,
				success : function(data) {
					// $("#empty").html(data);
				$('.reload').fadeOut();
				Shadowbox.open( {
					content : data,
					player : "html",
					title : "",
					height : 380,
					width : 600
				});

			}
			});
			return false;
		});
		return false;
	});

	$("a.oferta").livequery(
			function() {
				$(this).unbind('click');
				var open = $(this).attr("href");
				$(this).click(
						function() {
							$('.reload').fadeIn();
							$.ajax( {
								url : open,
								success : function(data) {
									$("#oferta_loaded").html(
											"Lista firm w danej kategorii:<br><br>"
													+ data);
									$('.reload').fadeOut();
									return false;
								}
							});
							return false;
						});
				return false;
			});

	$("a.rotator").live('click',function() {

			var open = $(this).attr("href");
			$('.reload').fadeIn();
			$.ajax( {
				url : open,
				success : function(data) {
					// $("#empty").html(data);
				$('.reload').fadeOut();
				Shadowbox.open( {
					content : data,
					player : "html",
					title : "",
					height : 380,
					width : 600
				});
				return false;
			}
			});
			return false;
	});

	$('.choose_floor').livequery(function() {
		$(this).click(function() {

			var idArr = $(this).attr('id').split("_");
			// alert(idArr[1]);
				$(".floor").hide();
				$("#floor_" + idArr[1]).show();

			});
	});

	/*
	var title = document.title;

	$.address.init().change(
			function(event) {
				var names = $.map(event.pathNames, function(n) {
					return n.substr(0, 1).toUpperCase() + n.substr(1);
				}).concat(
						event.parameters.id ? event.parameters.id.split('.')
								: []);
				var links = names.slice();
				var match = links.length ? links.shift() + ' '
						+ links.join('.') : 'Home';
				$('a.lm').each(function() {
					$(this).toggleClass('selected', $(this).text() == match);
				});
				$.address.title( [ title ].concat(names).join(' | '));
			});*/

	/*
	$('a.lm[href*=".php"],a.lm[href*=".html"]').not(".tooltip").not(".rotator")
			.not(".oferta").not(".show_on_plan").livequery(function() {

				$(this).click(function() {

					var obj = $("a.subtitle");
					obj.removeClass("subtitle");
					obj.addClass("left_menu");
					$(this).removeClass("left_menu");
					$(this).addClass("subtitle");

					$('.reload').fadeIn();
					var title = $(this).attr('title');
					$('#napis').fadeOut('fast', function() {
						$('#napis').html(title);

						$('#napis').fadeIn();
					});
					$.ajax( {
						url : $(this).attr('href'),
						success : function(data) {
							$('#container').html(data);
							$('.reload').fadeOut();
						}
					});
					return false;

				});
			});*/

	/*
	if (window.location.hash == "") {
		$('a.lm[href^="#ogalerii"]').trigger('click');
	} else {
		var newhash = window.location.hash.replace("#", "address:");
		newhash = newhash.replace("/", "");
		// alert(newhash);
		if ($('a.lm[rel^="' + newhash + '"]').length > 0)
			$('a.lm[rel^="' + newhash + '"]').trigger('click');
		else {
			var attrs = newhash.split("/");

			if (attrs.length > 2) {

				var pars = "index.php?session=0";

				for ( var i = 1; i < attrs.length - 1; i++) {
					pars += "&p" + i + "=" + attrs[i];
				}

				$('.reload').fadeIn();
				$.ajax( {
					url : pars,
					success : function(data) {
						$('#container').html(data);
						$('.reload').fadeOut();
					}
				});
				return false;

			}

		}
	}

	$('form').livequery(function() {
		$(this).ajaxForm( {
			beforeSubmit : function() {
				$('.reload').fadeIn();
			},
			success : function(data) {
				$('#container').html(data);
				$('.reload').fadeOut();
			}
		});
	});*/

});

