// page object namespace - contains global vars and functions
		var PO = {						
			webkit:true,
			FF:false,
			OO:false,
			IE:false,
			touchEnabled:false
		};	
		
		/************************************ xml for menu **************************************/
		PO.getWebkit = function(){
			PO.webkit = true;
			PO.FF = /Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent);
			PO.OO = /Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent);
			PO.IE = /MSIE[\/\s](\d+\.\d+)/.test(navigator.userAgent);
			
			if (PO.FF || PO.OO || PO.IE) {
				//test for Firefox and OPERA and IE
				PO.webkit = false;
			}
			if(PO.isTouchDevice()){
				PO.touchEnabled = true;	
			}
		}
		
		PO.resetVars = function(){
					    // whether the section has been loaded (ie the text)
		}
		
		$(window).resize(function() {
  			PO.doResize();
		});
		
		PO.adjustCSS = function(){
			$('#wrapper').css({'min-height':500});
			$('#wrapper').css({'min-height': $(document).height()});
		}
		
		// read xml and create the main menu
		PO.readMainXML = function(pName, sName){
			$.ajax({
			  type: "GET",
				 url: "content/struttura.xml",
				 dataType: "xml",
				 success: function(xml) {
					$("#mainMenu ul").empty();
					var numMenuItems = 0;
					var numSecondaryMenuItems = 0;
					
					$(xml).find('localization').each(function(){
						if($(this).attr('lang') == langObject.lang){
							numMenuItems = $(this).find('mainMenu section').length;
							$(this).find('mainMenu section').each(function(){
								var id=$(this).attr("id");
								
								if(PO.touchEnabled){
									$('#mainMenu').addClass('touchScreen');
								}
								
								$("#mainMenu ul").append('<li><a href="' + $(this).attr("page") + '"  id="' + id + '-link">' + $(this).attr("title").toLowerCase() + '</a></li>');
								
								if(pName == id){
									if(!PO.touchEnabled){
										$('#' + id + '-link').addClass('selected');
									}else{
										$('#' + id + '-link').addClass('selectedTouchScreen');
									}
									// check for secondary menu
									numSecondaryMenuItems = $(this).find('subsection').length;
									$(this).find('subsection').each(function(){
																			 
										id=$(this).attr("id");
										if( $(this).attr("page") != ''){
											$("#secondaryMenu ul").append('<li><a href="' + $(this).attr("page") + '"  id="' + $(this).attr("id") + '-link">' + $(this).attr("title").toLowerCase() + '</a></li>');
										}else{
											$("#secondaryMenu ul").append('<li class="filler">' + $(this).attr("title").toLowerCase() + '</li>');
										}
										
										if(sName == id){
											if(!PO.touchEnabled){
												$('#' + id + '-link').addClass('selected');
											}else{
												$('#' + id + '-link').addClass('selectedTouchScreen');
											}
										}
									});
									$("#secondaryMenu ul").append('<li style="width:' + (((numMenuItems - numSecondaryMenuItems)*100)-2) + 'px;" class="filler"></li>');
								}
							});
							
							
							
						}
					});
					
					  $('nav#mainMenu a').each(function() {											  
						  if($(this).attr('id') == PO.newSection+'-link' ){
							 
							  	if(!PO.touchEnabled){
									 $(this).parent().siblings().find("a").removeClass('selected');
							  		$(this).addClass('selected');
							  	}else{
									 $(this).parent().siblings().find("a").removeClass('selectedTouchScreen');
									$('#' + id + '-link').addClass('selectedTouchScreen');
								}
						  }
					  });
					
				 },
				 error:function(e){
					 //console.log(e);
				}
			}); //close $.ajax(	
			
			PO.checkIE();
		}
		
		PO.checkIE = function(){
			
			if( $.cookie("hideIE") != "yes" && PO.IE && $.browser.version < 8){
				$('#avviso').html(langObject.avviso);
				$('#avvisoLeft').html(langObject.avvisoLeft);
				$('#avvisoRight').html('<a href="javascript:PO.hideAvviso();void(0);">' + langObject.avvisoRight + '</a>');
				$('#avvisoIE').slideDown(300);
			}
		}
		
		PO.hideAvviso = function(){
			$('#avvisoIE').slideUp(300, function(){
												 
			});
			$.cookie("hideIE", "yes");
		}
		
		PO.readFooter = function(){
			$.ajax({
			  type: "GET",
				 url: "include/footer.htm",
				 dataType: "html",
				 success: function(result) {
					$("footer .content").empty();
					$("footer .content").html(result);
					if(pageURL!=''){
						if(langObject.lang == "it"){
							$("a#changeLang").html("English Version");
							$("a#changeLang").attr("href" , pageURL + "?lang=en");
							$('#az').html('Azienda:');
						}else{
							$("a#changeLang").html("Versione Italiana");
							$("a#changeLang").attr("href" , pageURL + "?lang=it");
							$('#az').html('Headquarters:');
						}
					}
					$("#datiSocietariLink").html(langObject.dati_societari_link);
					$('#datiSocietariLink').click(function(e){
						e.preventDefault();
						PO.showHideDati();						
					})
					
				 }
			});
			
			PO.readDatiSocietari();
		}
		
		PO.showHideDati = function(){
			if($('#datiSocietari').is(':hidden')){
				$('#datiSocietari').fadeIn(800, 'easeOutExpo');
			}else{
				$('#datiSocietari').fadeOut(800, 'easeOutExpo');
			}
			
		}
		
		PO.readDatiSocietari = function(){
			$.ajax({
			  type: "GET",
				 url: "include/dati_societari.htm",
				 dataType: "html",
				 success: function(result) {
					$("#datiSocietari .content").empty();
					$("#datiSocietari .content").html(result);
					$("#datiSocietari #dati_text").html(langObject.dati_text);
					$("#datiSocietari #rag_soc_text").html(langObject.rag_soc_text);
					$("#datiSocietari #sede_text").html(langObject.sede_text);
					$("#datiSocietari #cod_fisc_text").html(langObject.cod_fisc_text);
					$("#datiSocietari #cap_soc_text").html(langObject.cap_soc_text);
					$("#datiSocietari #reg_text").html(langObject.reg_text);
					$("#datiSocietari #rea_text").html(langObject.rea_text);
					
					$('#chiudi_dati').click(function(e){
						e.preventDefault();
						PO.showHideDati();						
					})
				 }
			});
		}
		
		PO.isTouchDevice = function() {
			 var el = document.createElement('div');
			 el.setAttribute('ongesturestart', 'return;');
			 if(typeof el.ongesturestart == "function"){
				return true;
			 }else {
				return false;
			 }
		  }
		  
		PO.doLangChange = function(){
			
		}
		/************************************* sections *****************************************/
		
		PO.loadNewSection = function(){
			
		}
		
		PO.loadNewSubSection = function(){
			
		}
		
		PO.animateSection = function(){
			
		}	
		
				
		/********************************* resize *****************************************/
		
		PO.doResize = function(){
			PO.adjustCSS();
			PO.resizeElement($('#wrapper'));	
			
			// prodotti 
			$('#prodThumbHolder').css('width', $(document).width() - 60);
			$('.prodThumbHolder').css('width', $(document).width() - 60);
			$('#prodScrollHolder').css('width', $(document).width() - 60);
			fleXenv.updateScrollBars();	
		}
		
	
		 PO.resizeElement = function(elem){
			var imgWidth = 1500;				// original dimensions of img
			var imgHeight = 1000;
			var minHeight = 700;			// min display dimensions
			var minWidth = 980;	
			var iw = elem.width();
			var ih = elem.height();
			var targetHeight = $(window).height() ;
			var targetWidth = $(window).width();
			var ratio = 0;
			var targetImgHeight;
			var targetImgWidth;
			
			if(targetHeight < minHeight){
				targetHeight = minHeight;	
			}
			if(targetWidth < minWidth){
				targetWidth = minWidth;
			}
			
			targetImgHeight = targetHeight;
			targetImgWidth = targetWidth;
			
			if((targetHeight > targetWidth)){		// height commands
				//alert("height commands");
				ratio = imgWidth/imgHeight;					
				targetWidth = targetHeight*ratio;
				targetImgWidth = targetWidth;
			}else{
				//alert("width commands");
				ratio = imgHeight/imgWidth;
				targetImgHeight = targetWidth*ratio;
				if(targetImgHeight <  $(window).height()){
					ratio = imgWidth/imgHeight;
					targetImgHeight = $(window).height() + 50;
					targetImgWidth = targetImgHeight*ratio;
				}
			}
			
			
			var imgMarginTop = -(targetImgHeight - targetHeight)/2
			var imgMarginLeft = -(targetImgWidth - targetWidth)/2;
			
			elem.find("img.fullscreen").css({'height' : targetImgHeight, 'width' : targetImgWidth, 'marginTop' : imgMarginTop, 'marginLeft' : imgMarginLeft}); 
			
		 }
