var ua = navigator.userAgent.toLowerCase();
var isStrict = document.compatMode == 'CSS1Compat',
    isOpera = ua.indexOf("opera") > -1,
    isIE = ua.indexOf('msie') > -1,
    isIE7 = ua.indexOf('msie 7') > -1,
    isBorderBox = isIE && !isStrict,
    isSafari = (/webkit|khtml/).test(ua),
    isSafari3 = isSafari && !!(document.evaluate),
    isGecko = !isSafari && ua.indexOf('gecko') > -1,
    isWindows = (ua.indexOf('windows') != -1 || ua.indexOf('win32') != -1),
    isMac = (ua.indexOf('macintosh') != -1 || ua.indexOf('mac os x') != -1),
    isLinux = (ua.indexOf('linux') != -1);

var getViewportHeight = function(){
  var height = window.innerHeight; // Safari
  var mode = document.compatMode;
  if((mode || isIE) && !isOpera){
      height = isStrict ? document.documentElement.clientHeight : document.body.clientHeight;
  }
  return height;
};

var getViewportWidth = function(){
  var width = window.innerWidth; // Safari
  var mode = document.compatMode;
  if(mode || isIE){
      width = isStrict ? document.documentElement.clientWidth : document.body.clientWidth;
  }
  return width;
};

var getDocumentHeight = function(){
  var scrollHeight = isStrict ? document.documentElement.scrollHeight : document.body.scrollHeight;
  return Math.max(scrollHeight, getViewportHeight());
};
var getDocumentWidth = function(){
  var scrollWidth = isStrict ? document.documentElement.scrollWidth : document.body.scrollWidth;
  return Math.max(scrollWidth, getViewportWidth());
};

var ChiudiLayerProdotti = function() { 
	$('#LayerProdottiContenitore').hide("blind",{direction:"vertical"},800).remove();
	$('#Overlay').fadeTo(500,0,function(){$('#Overlay').remove()});
	$('#fxWrapper').remove();
	$('object').show();
};


var initColonna1 = function () {
	$('#btnCategorieBrand').click(function(event){
		event.preventDefault();
		$('object').hide(); //NASCONDO I FLASH CHE NON VENGONO SOVRAPPOSTI CORRETTAMENTE
		$('#Fondo').after("<div id='Overlay' style='opacity:0;z-index:10;top:0;left:0;width:"+getDocumentWidth()+"px;height:"+getDocumentHeight()+"px;'></div>");
		$('#Overlay').fadeTo(500,0.6);
		$('html,body').animate({scrollTop: 0}, 500);
		$('#Overlay').after("<div id='LayerProdottiContenitore' style='height:100%'><div>");
		$('#LayerProdottiContenitore').startLoading({opend:0.6,zindex:100});
		$('#LayerProdottiContenitore').load($(this).attr('href'), function() {
			
			$('#btnChiudiLayerProdottiContenitore').click(function (event) {
				event.preventDefault();
				ChiudiLayerProdotti();
			});
			
			
			var LayerWidth = $('#LayerProdottiContenitore').width();
			var LayerHeight = $('#LayerProdottiContenitore').height();
			var width = (getViewportWidth() - LayerWidth)/2;
			var height = (getViewportHeight() - LayerHeight)/2;
			//$('#LayerProdottiContenitore').css('left',width+'px').css('top',height+'px').show("blind",{direction:"vertical"},500);
			$('#LayerProdottiContenitore').css('left',width+'px').css('height','auto');
			//$('#LayerProdottiContenitore').show("blind",{direction:"vertical"},800);
			$('#LayerProdottiContenitore').show('slow');
			$('#LayerProdottiContenitore').stopLoading();
			  //alert('Load was performed.');
			  
		});
	});
	$('#btnCategorieOrdineAlfabetico').click(function(event){
		event.preventDefault();
		$('object').hide(); //NASCONDO I FLASH CHE NON VENGONO SOVRAPPOSTI CORRETTAMENTE
		$('#Fondo').after("<div id='Overlay' style='opacity:0;z-index:10;top:0;left:0;width:"+getDocumentWidth()+"px;height:"+getDocumentHeight()+"px;'></div>");
		$('#Overlay').fadeTo(500,0.6);
		$('html,body').animate({scrollTop: 0}, 500);
		$('#Overlay').after("<div id='LayerProdottiContenitore' style='height:100%'><div>");
		$('#LayerProdottiContenitore').startLoading({opend:0.6,zindex:100});
		$('#LayerProdottiContenitore').load($(this).attr('href'), function() {
			$('#LayerProdottiContenitore').css('height','auto');
			$('#btnChiudiLayerProdottiContenitore').click(function (event) {
				event.preventDefault();
				ChiudiLayerProdotti();
			});
			
			
			var LayerWidth = $('#LayerProdottiContenitore').width();
			var LayerHeight = $('#LayerProdottiContenitore').height();
			var width = (getViewportWidth() - LayerWidth)/2;
			var height = (getViewportHeight() - LayerHeight)/2;
			//$('#LayerProdottiContenitore').css('left',width+'px').css('top',height+'px').show("blind",{direction:"vertical"},500);
			$('#LayerProdottiContenitore').css('left',width+'px').css('height','auto');
			//$('#LayerProdottiContenitore').show("blind",{direction:"vertical"},800);
			$('#LayerProdottiContenitore').show('slow');
			$('#LayerProdottiContenitore').stopLoading();
			
			  //alert('Load was performed.');
		});
	});
	
	
	//CODICI APPARI e SCOMPARI SUI MACRO LIVELLI
	$('#Colonna1 ul li h3').click(function(event){
		//event.preventDefault();
		if( event.target === this ) {
			$(this).parent().toggleClass('Attivo');
		}	
	});
	
	
}

$(document).ready(initColonna1);
