$(document).ready(function()
	  {
	   myWindowAddDiv = function(id,titolo,contenuto,idElementoDaIncludere,w,h,elm,openUp,canale) 
	    {
		 //alert(canale);
		 if($('#'+id).size() > 0)
	      $('#'+id).remove();
		 
		 //alert('1');
		  
		  var content = '';
		  if(contenuto)
		   content = content + contenuto;
		   
		  if(idElementoDaIncludere)
		   content = content + $('#'+idElementoDaIncludere).html();
		  		 
		 $('body').append('<div id=\''+id+'\' class=\'myWindowCornice\' onmousedown="myWindowGoLayerUp(\''+id+'\')"><div onmousedown="myWindowGoLayerUp(\''+id+'\')" class=\'myWindowHandle\'><span alt=\''+titolo+'\' title=\''+titolo+'\' class=\'myWindowTitolo\'></span><div alt=\'chiudi la finestra\' title=\'chiudi la finestra\' onclick="myWindowCloseDiv(\''+id+'\')" class=\'closeOff\'  onmouseover="this.className=\'closeOn\'" onmouseout="this.className=\'closeOff\'"></div><div alt=\'minimizza la finestra\' title=\'minimizza la finestra\' onclick="myWindowMinMaxDiv(\''+id+'\',this)" class=\'minOff\' onmouseover="this.className=\'minOn\'" onmouseout="this.className=\'minOff\'"></div></div><div class=\'myWindowCnt\'>'+content+'</div>');
		 
		 $('#'+id).hide();
		 $('#'+id).draggable({ handle: 'div.myWindowHandle' });

		 if(!w || w<150)
		  w = 150;
		 
		 var spanW = w-45;
		 var titleW = titolo.length*7;
		 if(titleW>spanW)
		  {
		   varMaxCar = Math.floor(spanW/7)-3;
		   titolo = titolo.slice(0,varMaxCar)
		   titolo = titolo+"...";
		  }
		 
		 $('#'+id+' div.myWindowHandle .myWindowTitolo').text(titolo);
		 
		 $('#'+id).css('width',w+'px');
		 
		 if(h&&h>0)
		  {
		   if(h<150)
		    h = 150;
		   //$('#'+id).css('height',h+'px');
		   $('#'+id+' .myWindowCnt').css('overflow','auto').css('height',h-33+'px');
		  }
		 
		 //alert('2');
		 
		 
		 var screenW = self.screen.width; 
		 var screenH = self.screen.height;
		 var partialW =  Math.floor((w*75)/100);
		 var partialH =  Math.floor((h*75)/100);
		 
		 
		 		 
		 if(elm)
		  {
		   //alert(elm.attr('id'));
		   var y = $('#'+elm.id).offset().top;
		   var x = $('#'+elm.id).offset().left;
		   var xOffset = $('#'+elm.id).width();
		   
		   
		   if((x+partialW+xOffset+25)>screenW)
		    {
			 x = x-w-25;
			}
		   else
		    {
			 x = x+xOffset+25;
			}
		  		  
		   //var y = $('#'+elm.id).offset().top;
		   //var x = $('#'+elm.id).offset().left;		 
		   //var xOffset = $('#'+elm.id).width();
		   //x = x+xOffset+25;		
		   if(openUp)
		    y = y-($('#'+id).height());
		   $('#'+id).css('top',y+'px');
		   $('#'+id).css('left',x+'px'); 
		  }
		 
		 
		  
		 myWindowGoLayerUp(id);	  
		 //$('#'+id).show('normal');
		 //$('div.myWindowHandle span').css('color','#FFF');
		 if(canale=='ristoranti')
		  $('div.myWindowCornice').css('background-image','url(/css/imgMyWindow/bkgRistoranti.gif)');
		 else if(canale=='hotel')
		  $('div.myWindowCornice').css('background-image','url(/css/imgMyWindow/bkgHotel.gif)');
		 else if(canale=='artigianato')
		  $('div.myWindowCornice').css('background-image','url(/css/imgMyWindow/bkgArtigianato.gif)');
		 else if(canale=='prodotti')
		  $('div.myWindowCornice').css('background-image','url(/css/imgMyWindow/bkgProdotti.gif)');
		  else if(canale=='raspelli')
		  $('div.myWindowCornice').css('background-image','url(/css/imgMyWindow/bkgRaspelli.gif)');
		 else
		  $('div.myWindowCornice').css('background-image','url(/css/imgMyWindow/bkg.png)');
		  
		 $('#'+id).slideDown('normal');
		};
	 
	  
	 
	   myWindowCloseDiv = function(id) 
	    {
		 //$('#'+id).hide("normal",function(){$('#'+id).remove()});
		 $('#'+id).slideUp("normal",function(){$('#'+id).remove()});
	    }
	    
	   myWindowGoLayerUp = function(id)
		{
		 $('div.myWindowCornice').css('z-index','10');
		 $('#'+id).css('z-index','11');
		}
		
	   myWindowMinMaxDiv = function(id,elm) 
	    {
		 if($('#'+id+' .myWindowCnt').css('display')=='block')
		  {
		   //$('#'+id+' .myWindowCnt').hide();
		   $('#'+id+' .myWindowCnt').slideUp();
		   elm.className = 'maxOff';
		   elm.setAttribute('alt','espandi la finestra');
		   elm.setAttribute('title','espandi la finestra');
		   elm.onmouseover = function() {this.className='maxOn'};
		   elm.onmouseout = function() {this.className='maxOff'};
		  }
		 else
		  {
		   //$('#'+id+' .myWindowCnt').show();
		   $('#'+id+' .myWindowCnt').slideDown();
		   elm.className = 'minOff';
		   elm.setAttribute('alt','minimizza la finestra');
		   elm.setAttribute('title','minimizza la finestra');
		   elm.onmouseover = function() {this.className='minOn'};
		   elm.onmouseout = function() {this.className='minOff'};
		  }
	    }	
      });