var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera",
			versionSearch: "Version"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

// JavaScript Document
$(document).ready(function() {
	if(BrowserDetect.OS == "Mac") {
		if(BrowserDetect.browser == 'Firefox') {
			$('.imageInput').css('margin-top','1px');
		}
		if(BrowserDetect.browser == 'Safari') {
			$('.imageInput').css('margin-top','0px !important');
		}
	}				   
	window.start = 0;
	window.siteHome = 'http://www.museodelnovecento.org';
	slide900();
	window.timer = setInterval("slide900()",5000);
						   
	$("div.slide").click(function() {
		
		if($(this).attr('rel') != '') {
			$(this).click(function(){
				window.location.href = $(this).attr('rel');
			})
		}

		$('titoloSlide, .testo').click(function(){
			if($(this).attr('rel') != '')
				window.location.href = $(this).parent().attr('rel');
		});

		clearInterval(window.timer);

		if($(this).hasClass("first")) {
			$('#primafoto').fadeIn(1000);
			$('#secondafoto').fadeOut(1000);
			$('#terzafoto').fadeOut(1000);
			$('.second *,.third *').animate({color:'#999999'},1000);
			$('.first *').animate({color:'#000000'},1000);
		}
		if($(this).hasClass("second")) {
			$('#primafoto').fadeOut(1000);
			$('#secondafoto').fadeIn(1000);
			$('#terzafoto').fadeOut(1000);
			$('.first *,.third *').animate({color:'#999999'},1000);
			$('.second *').animate({color:'#000000'},1000);
		}
		if($(this).hasClass("third")) {
			$('#primafoto').fadeOut(1000);
			$('#secondafoto').fadeOut(1000);
			$('#terzafoto').fadeIn(1000);
			$('.second *,.first *').animate({color:'#999999'},1000);
			$('.third *').animate({color:'#000000'},1000);
		}
	})
	
	$('div.slide').hover(function() {
		clearInterval(window.timer);


		if($(this).hasClass("first")) {
			$('#primafoto').fadeIn(1000);
			$('#secondafoto').fadeOut(1000);
			$('#terzafoto').fadeOut(1000);
			$('.second *,.third *').animate({color:'#999999'},1000);
			$('.first *').animate({color:'#000000'},1000);
		}
		if($(this).hasClass("second")) {
			$('#primafoto').fadeOut(1000);
			$('#secondafoto').fadeIn(1000);
			$('#terzafoto').fadeOut(1000);
			$('.first *,.third *').animate({color:'#999999'},1000);
			$('.second *').animate({color:'#000000'},1000);
		}
		if($(this).hasClass("third")) {
			$('#primafoto').fadeOut(1000);
			$('#secondafoto').fadeOut(1000);
			$('#terzafoto').fadeIn(1000);
			$('.second *,.first *').animate({color:'#999999'},1000);
			$('.third *').animate({color:'#000000'},1000);
		}





	},function() {
		window.timer = setInterval("slide900()",5000);	
	})
})

function slide900() {
	switch(window.start % 3) {
		case 0:
			$('#primafoto').fadeIn(1000);
			$('#secondafoto').fadeOut(1000);
			$('#terzafoto').fadeOut(1000);
			$('.second *,.third *').animate({color:'#999999'},1000);
			$('.first *').animate({color:'#000000'},1000);
		break;
		case 1:
			$('#primafoto').fadeOut(1000);
			$('#secondafoto').fadeIn(1000);
			$('#terzafoto').fadeOut(1000);
			$('.first *,.third *').animate({color:'#999999'},1000);
			$('.second *').animate({color:'#000000'},1000);
		break;
		case 2:
			$('#primafoto').fadeOut(1000);
			$('#secondafoto').fadeOut(1000);
			$('#terzafoto').fadeIn(1000);
			$('.second *,.first *').animate({color:'#999999'},1000);
			$('.third *').animate({color:'#000000'},1000);
		break;
	}
	$('.slideshow').css('padding-top','0px');	
	
	window.start++
}


$(document).ready(function(){

	$("#sitemap900").treeview({
		persist: "location",
		collapsed: true,
		unique: true
	});


	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	$("ul.topnav li").hover(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

	},function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).find("ul.subnav").slideUp('fast'); //Drop down the subnav on click

	});
	
	$('.logoComune').click(function(e){
		e.stopPropagation();
		window.location.href = 'http://www.comune.milano.it';
	})
	
	$('.new_header').click(function(){
		window.location.href = window.siteHome;
	});
	$('.inputSearch').click(function(e){
		e.stopPropagation();
		return false
	});

});












