﻿$(document).ready(function() {
 
 	$("#nav ul").hide();

	$("li.p1:has(ul)").click(function(event){
		if (this == event.target) {
			var current = this;
			$("#nav li:has(ul)").each(function() {
				if (this != current) $(this).children().slideUp(400);
			});
			$("ul:first", $(this)).slideToggle(400);
		}
	});
	
	$("a").filter(function() {
	    return this.hostname && this.hostname !== location.hostname;
	}).attr('target', '_blank');
		 
	$("#nav a").each(function(idx, item) {
		$(this).attr('rel', ('address:/' + this.pathname).replace('//','/'));
	});
	$("#nav a").address();

	$("#ekoartContentProjektSeznam a").each(function(idx, item) {
		$(this).attr('rel', ('address:/' + this.pathname).replace('//','/'));
	});
	$("#ekoartContentProjektSeznam a").address();


	$("#ekoartContentProjektImageList a").each(function(idx, item) {
		var path = location.pathname;
		$(this).attr('rel', ('address:' + path + '?img=/' + this.pathname).replace('//','/'));
	});
	$("#ekoartContentProjektImageList a").address();

});

$.address.change(function(event) {
	if	(event.value != '/') {
	    $("#AjaxHtmlContent").load(event.path + ' #NewAjaxHtmlContent', function(){
	       	if ($.address.parameterNames().length == 1) {
	    		if ($.address.parameterNames(0) == 'img') {
					$("#projekti_img").attr('src',event.parameters.img);
	    		}
	    	}
	    	
			$("#ekoartContentProjektSeznam a").each(function(idx, item) {
				$(this).attr('rel', ('address:/' + this.pathname).replace('//','/'));
			});
	
	    	$("#ekoartContentProjektImageList a").each(function(idx, item) {
	    		$(this).attr('rel', ('address:' + event.path + '?img=/' + this.pathname).replace('//','/'));
			});
	
	    	$("#ekoartContentProjektSeznam a").address();
	    	
	    	$("#ekoartContentProjektImageList a").address();
	
			$("#NewAjaxHtmlContent a").filter(function() {
			    return this.hostname && this.hostname !== location.hostname;
			}).attr('target', '_blank');
	    });
	}

	//$("ekoartContentProjektSeznam a").address();
	/*var text = (event.value == '/') ? 'Domov' : 
	event.pathNames[0].substr(0, 1).toUpperCase() + 
	event.pathNames[0].substr(1);
	$('#nav a').each(function() {
		$(this).toggleClass('selected', $(this).text() == text);
	});*/
})


