function getData() {

    var blockDiv = $("<div></div>");
    var blockA = $("<a href=\"\"></a>");
    var blockImg = $("<img src=\"\">");
	var blockDescription = $("<span></span>");

	blockA.append(blockImg).append(blockDescription);
	blockDiv.append(blockA);

	$.ajax({
	    url: "db.xml",
	    dataType: "xml",
	    success: function (xml) {
	        xml = $(xml).find("fotogallery");
//            $.each($(xml).find("home"), function (i, item) {
//            
//                var temp = blockDiv.clone();

//	            temp.find("a").attr("class", $(item).find("id").text());
//                temp.find("a").attr("href", "javascript:filterHome();");
//                temp.find("span").append($(item).find("categoria").text());
//	            temp.find("img").attr("src", $(item).find("img").text());

//	            $("div.ctn-home").append(temp);

//            });
            
	        $.each($(xml).find("foto"), function (i, item) {

	            var temp = blockDiv.clone();

	            temp.find("a").attr("href", $(item).find("img").text()).addClass($(item).find("id").text());
                temp.find("a").attr("rel",$(item).find("id").text());
	            temp.find("img").attr("src", $(item).find("img").attr("thumb")).attr("alt", $(item).find("description").text());

	            $("div.ctn-foto").append(temp);

	            $("div.ctn-foto div a").fancybox({
	                'titleShow': false,
	               
	            });

	        });
	    }
	});

};

function faderFocus() {

    $("ul.nav li.focus a").click(function () {

        var classItem = $(this).attr("id");
        
        if(classItem == "home"){
            $("div.ctn-foto").hide();
            $("div#slider").show();
            return
        }else{
            $("div#slider").hide();
            $("div.ctn-foto").show();
            $("div.ctn-foto a").hide();
            $("div.ctn-foto a." + classItem + "").show();
            return
        }
    })
}

function showContact() {

    $("a.opencontact").click(function () {

        $("div.contatti").slideToggle("1000");
    });

    $("a.close").click(function () {

        $("div.contatti").slideUp("1000");
    });

}

function filterHome(){
    
    $("div#slider a.nivo-imageLink").live('click',function () {
        var classItem = $(this).attr("id");

        $("div#slider").hide();
        $("div.ctn-foto").show();
        $("div.ctn-foto a").hide();
        $("div.ctn-foto a." + classItem + "").show();
            
    })

}


function initialize() {

    showContact();

    getData();

    faderFocus();

    filterHome();
}


