/**
 * @name:          jBTicino
 * @author:        Andrea Talon (& Andrea Bianchin)
 * @company:       Valueteam S.p.A. (TV)
 *
 * @version:       2.6
 * @description:   b0.* : Showcase
 *                 1.0  : SkinSelect & SkinRadio
 *                 1.5  : Form's controls
 *                 2.0  : Google Map API 3 & Overlay Box
 *                 2.5  : Fancybox
 *                 2.6  : ConfiguratorOverlay
 */


// preable
var isIE6,isIE7,isIE8,isIE9;
var hasFlash = DetectFlashVer(0,0,0); //major,minor,requested
document.write('<style type="text/css"> .nav-div {visibility:hidden;} </style>');


//start
$(function(){
  
  // preable
  isIE6=($.browser.msie && $.browser.version==6);
  isIE7=($.browser.msie && $.browser.version==7);
  isIE8=($.browser.msie && $.browser.version==8);
  isIE9=($.browser.msie && $.browser.version==9);
  if (!hasFlash) $('.flashsubstitute').css('display','block');
  
  // transparency
  $('.box .controls').css({
    'opacity':'.5',
    '-ms-filter':'progid:DXImageTransform.Microsoft.Alpha(Opacity=50)', /*first!*/
    'filter':'alpha(opacity=50)' /*second!*/
  });
  
  // fix pngs on M$ IE 6
  if(isIE6) $(document).pngFix();
  
  // external link management
  $('a.external').attr('target','_blank');
  
  // nav-menu
  // $('.nav-menu ul:first').append('<li class="nav-li nl-last"><span>&nbsp;</span></li>');
  $('.nav-menu ul:first li .nav-div').each(function(i,el){
    var width=20;
    for(var x=0;x<$('.nav-section',el).length;x++){
      var nsw = $('.nav-section:eq('+x+')',el).width();
      $('p',el).css('width',nsw+10+'px');
      width += nsw+20;
    }
    $(el).css('width',width+'px');
  });
  $('.nav-menu ul:first li .nav-div').hide();
  $('.nav-menu ul:first li .nav-div').css('visibility','visible');
  $('.nav-menu ul:first li').hover(
    function(){
      // $(this).closest('.nav').css('z-index','9991');
      $(this).find('.nav-div').show(); 
      $('.contSkin').css('z-index','0').find('ul').hide();
    },
    function(){
      // $(this).closest('.nav').css('z-index','0');
      $(this).find('.nav-div').hide();
      $('.contSkin').css('z-index','2');
    }
  );
  
  // initialize showcases
  $('.showcase').each(function(i,val){initShowcase(i,val);});
  
  // configurator button
  if($('.nav-link').length>0){
  var nltemp = ($('.nav-link img').attr('src').split('.jpg')[0]).split('-active');
  if (nltemp.length<2){
    $('.nav-link').hover(
      function(){$('img',this).attr('src',nltemp[0]+'-active.jpg');},
      function(){$('img',this).attr('src',nltemp[0]+'.jpg');}
    );
  }}
  
  // sys-height box-step
  $('.box-step').each(function(ind,el){
    var brNumber=0;
    var myHeight=$(el).height();
    var bss=$(el).siblings('.box-step');
    for(var i=0;i<bss.length;i++)
      if (myHeight<$(bss[i]).height())
        myHeight=$(bss[i]).height();
    for(var i=0;i<bss.length;i++)
      if(myHeight==$(bss[i]).height());
        brNumber=$('br',bss[i]).length;
    if(myHeight==$(el).height());
      brNumber=$('br',el).length;
    if($.browser.webkit) myHeight-=(10*brNumber);
    if($.browser.msie) myHeight+=5;
    for(var i=0;i<bss.length;i++)
      $(bss[i]).css('height',myHeight+'px');
    $(el).css('height',myHeight+'px');
  });
  
  // result-pager hack for IE6 e IE7
  if(isIE6||isIE7) $('.result-pager .pager').each(function(i,el){
    var rpwidth=($(el).parent().width()-$(el).width())/2;
    $(el).css('padding-left',rpwidth+'px');
  });
  
  // skin select
	$('select').each(function(ind,el){
    if($(el).hasClass('links'))$(el).attr('onchange','window.location.href=this.options[this.selectedIndex].value');
    if(!($(el).hasClass('noskin'))){skinSelect(ind,el);}
  });
  
  // skin radio
	$('input[type=radio]').each(function(ind,el){if(!($(el).hasClass('noskin'))){skinRadio(ind,el);}});
  
  // form control
  $('form').each(function(ind,el){if(!($(el).hasClass('nocontrol'))){controlForm(ind,el);}});
  
  // height button
  if($('.btn-download-maxi label').height()<25) $('.btn-download-maxi label').css('padding-top','17px');
  
  // google map
  $('.address').each(function(ind,element){
    var ad = String($(this).attr('rel'));
    ad = (/^([#.])+$/.test(ad.substr(0,1))) ? ad.substring(1,ad.length) : ad;
    var address = {
      id      : ad
    , value   : $(element).text()
    }
    mapper(address);
  });
  
  // overlay
  $('.overlay-button[rel]').each(function(i,el){
    var ref = this;
    var ov = $(this).attr('rel');
    $(this).overlay({
      onBeforeLoad  : function() {
        $(ov).find('input#hidden_email').val($(ref).parent().find('.hidden_email').text());
      },
      mask          : {
        color         : '#ebebeb',
        loadSpeed     : 100,
        opacity       : .6
      },
      effect        : 'apple',
      closeOnClick  : false
    });
  });
  
  // zoom
  $('.zoom').each(function(ind,element){
    var rel = ($('.items a:first',element).attr('rel') != undefined) ? '[rel='+$('.item a:first',element).attr('rel')+']' : '';
    $('.items a'+rel+'',element).fancybox({
      overlayColor    : '#ebebeb',
      transitionIn		: 'elastic',
      transitionOut		: 'elastic',
      titlePosition 	: 'over',
      titleFormat		  : function(title, currentArray, currentIndex, currentOpts) {
        //return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				return '<span id="fancybox-title-over">' + (title.length ? ' &nbsp; ' + title : '') + '</span>';
      }
    });
  });
  
  // video
  $('.player').each(function(ind,element){
    $f(element,{
      src           : $(element).attr('rev'),
      version       : [9,115],
      wmode         : 'opaque', //transparent
      onFail        : function() { }
    },{
      onMouseOver   : function() {
        if(!((isIE6 || isIE7) && $(element).closest('.case').length>0)) $(element).expose({color:'#ebebeb',opacity:.6,api:true}).load();
      },
      onMouseOut    : function() {
        if(!((isIE6 || isIE7) && $(element).closest('.case').length>0)) $.mask.close();
      },
      clip          : {
        url           : $(element).attr('rel'),
        autoPlay      : true
      }
    });
  });
	
});


/* initShowcase */
/****
  STRUCTURE:
  
  +-div.showcase
    +-ul.shows
      +-li
        +-a
    +-div.show
      +-div.case
        +-a.prev
        +-a.next
        +-ul.navi
          +-li
            +-a
        +-scrollable
          +-items
            +-item
              +-...whatDoYouWant
    +-div.controls
*/
function initShowcase(i,val){
  $('.navi a,a.prev,a.next').click(function(e){e.preventDefault();});
  $('.navi a,a.prev,a.next',val).text('');
  if($('.shows',val).length>0)$('.show').hide();
  if($('.acts',val).length>0)$('.act').hide();
  $('.case',val).each(function(m,el){ // html manipulation
    if($('.scrollable',el).length>0){
      var size=1;
      if($(el).hasClass('due')) size=2;
      if($(el).hasClass('tre')) size=3;
      if($(el).hasClass('quattro')) size=4;
      if($(el).hasClass('cinque')) size=5;
      if($(el).hasClass('sei')) size=6;
      $('.navi',el).html('');var insert='';
      $('.item',el).each(function(n,ne){
        if((n%size)==0){
          $('.navi',el).append('<li><a href="javascript:void(0)" title="">'+m+'</a></li>');
          insert+='<div class="item">';
        }
        insert+='<div class="itm">'+$(ne).html()+'</div>';
        if((n%size)==(size-1)){insert+='</div>';}
      });
      $('.items',el).html(insert);
    }
  });
  setTimeout(function(){ // important trick: initialize after html manipulation
  $('.shows',val).tabs('.show',{rotate:'true'});
  $('.show',val).each(function(n,obj){
    $('.acts .itm',obj).each(function(i,el){
  	  if(i==0){$('.act:first',obj).show(); $('a',el).addClass('current')}
  	  $(el).click(function(e){
  	    $('.acts .itm a',obj).removeClass('current');
  	    $('a',el).addClass('current');
  	    $('.act',obj).hide();
  	    $('.act:eq('+i+')',obj).show();
  	    e.preventDefault();
  	  });
    }); // personal tabs
  });
  $('.case',val).each(function(m,el){
    if($('.scrollable',el).length>0){
      var prev = $('.prev',el);
      var next = $('.next',el);
      if((isIE6||isIE7)&&$(el).closest('.showcase').parent().hasClass('box')&&$('.itm:eq(0) a.item-link').length>0){
        var _blank = ($('.itm:eq(0) a.item-link').hasClass('external')) ? 'target="_blank"' : '';
        $(el).append('<a class="item-link" '+_blank+' href="'+ $('.itm:eq(0) a.item-link').attr('href') +'" title="">'+ $('.itm:eq(0) a.item-link').html() +'</a>');
      }
      if($(el).closest('.models').length>0 && $(el).closest('.models').hasClass('gallery')){
        var maxWidth=$('.scrollable',el).width();
        var maxHeight=$('.scrollable',el).height();
        $('.model').each(function(v,l){
          var limg = $('img',l).attr('src');
          $(l).html('<table style="width:'+maxWidth+'px;height:'+maxHeight+'px;border-collapse:collapse;border:0;margin:0; padding:0;"><tr><td style="vertical-align:middle;text-align:center;background:url('+limg+') 50% 50% no-repeat;"></td></tr></table>');
        });
      }
      $(el).scrollable({
        onSeek: function(){if (isIE6||isIE7){
          var itemLinkOwned=$('.itm:eq('+(this.getIndex())+') a.item-link',el)[0]
          var itemLinkDisplay=$(el).children('a.item-link')[0]
          $(itemLinkDisplay).html($(itemLinkOwned).html());
          $(itemLinkDisplay).attr('href',$(itemLinkOwned).attr('href'));
        }},
        keyboard:true,
        // circular:true,
        // mousewheel:true,
        prev:prev,
        next:next
      }).navigator({
        navi:'.navi',
        activeClass:'active'
      })/*.autoscroll({
        interval:3000,
        autoplay:true,
        autopause:false
      })*/.find('.navi li:first').addClass('active');
      $('.prev',el).addClass('disabled');
      if ( $('.item',el).length<2) $('.next,.prev',el).css('visibility','hidden');
      $('.navi',el).each(function(n,ne){ // position of navi's bullets
        var x=($('li',obj).length/2)*15;
        $(ne).css('margin-left','-'+x+'px');
      });
    }
  });
  },0);
}


/* skinSelect */
function skinSelect(ind,element){
  var maxWidth  = 200; //px
  var maxHeight = 200; //px
	var wSelect = Math.min($(element).width()+16 , maxWidth);
	var rowToShow = 12;
	var myId = $(element).attr('id');
	var myName = $(element).attr('name');
  var classSelect = ($(element).attr('class')) ? ' '+$(element).attr('class') : '';
  var array=$(element).children();
  try {var locref = (((location.href.split(myName+'=')[1]).split('&')[0]).split('#')[0]).replace(/\+/g,' ');}catch(e){};
  for(var i=0;i<array.length;i++)
    if ( locref && locref == $(array[i]).val() ) $(array[i]).attr('selected','selected');
    else if( locref && locref != $(array[i]).val() ) $(array[i]).removeAttr('selected');
    else if( !locref && $(array[i]).attr('selected') ) $(array[i]).attr('selected','selected');
  var contSkinned = $('<div class="contSkin'+classSelect+'" style="width:'+wSelect+'px;"></div>');
	var skinned = $('<div id="'+myId+'_btn" class="selectSkinned"></div>');
	var dx = $('<div class="dx"></div>');
	var cc = $('<div id="'+myId+'_text" class="cc" style="width:'+(wSelect-26)+'px;"></div>');
	var input = $('<input type="hidden" id="'+myId+'" name="'+myName+'" value="" />');
	var ul = $('<ul id="'+myId+'_option" class="dropDown"></ul>');
	var textSelected = $("#"+myId+" option:selected").text();
	var selectedClass='';
  $(element).children().each(function(){
    var _blank = ($(this).hasClass('external')) ? 'target="_blank"' : '';
		var htmlOption = ($(element).hasClass('links')) ? '<a '+_blank+' href="'+$(this).val()+'" title="">'+$(this).html()+'</a>' : $(this).html();
    var thisClassName = (this.className) ? this.className : 'genericClassName';
		var selected = ($(this).attr('selected')) ? 'selected="selected"' : '';	
		var li = $('<li id="'+this.id+'" class="'+thisClassName+'" '+selected+' title="'+this.value+'">'+htmlOption+'</li>');
		$(ul).append(li);
    $(li).each(function(i,el){
      if($(this).attr('selected')=='selected'){
        selectedClass=$(this).attr('class');
        $(input).val($(this).attr("title"));
      };
		});
    $(li).click(function(){
      if (thisClassName!='genericClassName'){
        var cn='.'+thisClassName.split(' ')[0];
        var tcn = $(this).parent().parent().nextAll().find(cn);
        var tcp = $(this).parent().parent().prevAll().find(cn);
      }
      var tcl = $(this).parent().parent().next().find('li');
      $(tcl).each(function(m,obj){$(obj).show();});
      $(tcn).each(function(m,obj){
        if (thisClassName!='genericClassName') $(obj).siblings().not(cn).hide();
        if (m==0){
          $(obj).parent().prev().find('.cc').html($(obj).html());
          $(obj).parent().prev().find('input').attr('value',$(obj).attr('title'));
        }
      });
      $(tcp).each(function(m,obj){
        if (thisClassName!='genericClassName') $(obj).click();
      });
      $('#'+myId+'').val($(this).attr("title"));
      $('#'+myId+'_text').html($(this).text());
      $('#'+myId+'_link').attr('href',$(this).attr("title"));
      if($(this).hasClass('external')) $('#'+myId+'_link').attr('target','_blank');
      else $('#'+myId+'_link').attr('target','_self');
			setTimeout(function(){$('#'+myId+'_option').css('display','none');},100);
		});
		$(li).hover(function(){
			$(this).attr('class',$(this).attr('class')+' hover');
		});
		$(li).mouseout(function(){
			$(this).attr('class', $(this).attr('class').split(' hover')[0]);
		});
	});
	$(cc).append(textSelected);
	$(dx).append(cc);
	$(skinned).append(dx);
	$(skinned).append(input);
	$(contSkinned).append(skinned);			
	$(contSkinned).append(ul);
  // if($(element).hasClass('invert')) $(ul).css({'top':'auto','bottom':'34px'});
  $(element).wrap(contSkinned); /* inserisco la nuova select */
	$(element).remove(); /* rimuovo la vecchia select */
	newW = $('#'+myId+'_btn').width();
	$('#'+myId+'_option').css('width',newW-3+'px');
	if(isIE8) $('#'+myId+'_option').css('width',newW-2+'px');
	$('#'+myId+'_btn').click(function(e){
		$(this).closest('.contSkin').css('z-index','3000');
		if($('#'+myId+'_option').css('display')=='none'){					
			$('.dropDown').each(function(){$(this).hide();});
			$('#'+myId+'_option').show();
		}else{
      $('#'+myId+'_option').hide();
    }
		var hli=0;
    for(var x=0;x<$('#'+myId+'_option li').length;x++)
      if( String($('#'+myId+'_option li:eq('+x+')').attr('style')).indexOf('none')>0 ){}
      else hli+=($('#'+myId+'_option li:eq('+x+')').height()+4);
    $('#'+myId+'_option').css('height',Math.min(hli,maxHeight));
	});
  setTimeout(function(){
	$('#'+myId+'_option li').each(function(){
    var tcn = $(this).parent().parent().nextAll();
    if($(this).hasClass(selectedClass) && $(tcn).length>0){
      $(tcn).find('li').not('.'+selectedClass).hide();
    };
  });
  },0);
  $(document).click(function(){$('#'+myId+'_option').hide();});
	$('.contSkin').click(function(e){e.stopPropagation();});
  
  $(document).click();
};


/* skinRadio */
function skinRadio(ind,element){
  $(element).css({'visibility':'hidden','position':'absolute','z-index':'-1','margin-left':'-10px'});
  $(element).after('<a class="radioSkinned" href="#" title=""></a>');
  var radioSkinned=$(element).next();
  var label=$('body').find('label[for='+$(element).attr('id')+']');
  var array=new Array();
  if($(element).attr('name')!='')array=$('input[type=radio][name='+$(element).attr('name')+']');
  /*
  try {var locref = (((location.href.split(name+'=')[1]).split('&')[0]).split('#')[0]).replace(/\+/g,' ')}catch(e){};
  for(var i=0;i<array.length;i++)
    if ( locref && locref == $(array[i]).attr('id')){
      $(array[i]).attr('checked','checked');
      $(array[i]).addClass('radio-active');
      radioFocus(array[i]);
    }else if( locref && locref != $(array[i]).attr('id') ){
      $(array[i]).removeAttr('checked');
      radioBlur(array[i]);
    }else if( !locref && $(array[i]).attr('checked') ){
      $(array[i]).addClass('radio-active');
      radioFocus(array[i]);
    }
  */
  for(var i=0;i<array.length;i++) {
    if( $(array[i]).attr('checked') ){
      $(array[i]).addClass('radio-active');
      radioFocus(array[i]);
    }
  }
  $(radioSkinned).click(function(e){radioClick();$(element).click();});
  $(label).click(function(e){radioClick();$(element).click();});
  $(radioSkinned).hover(function(){radioFocus(element);},function(){radioBlur(element);});
  $(label).hover(function(){radioFocus(element);},function(){radioBlur(element);});
  function radioClick(){
    for(var i=0;i<array.length;i++){
      // $(array[i]).removeAttr('checked');
      $(array[i]).removeClass('radio-active');
      $(array[i]).next().removeClass('rs-active');
      $('body').find('label[for='+$(array[i]).attr('id')+']').removeClass('fl-active');
    }
    $(element).attr('checked','checked');
    $(element).addClass('radio-active');
    radioFocus(element);
  }
  function radioFocus(el){
    var radioSkinned=$(el).next();
    var label=$('body').find('label[for='+$(el).attr('id')+']');
    $(radioSkinned).addClass('rs-active');
    $(label).addClass('fl-active');
  }
  function radioBlur(el){if(!($(el).hasClass('radio-active'))){
    var radioSkinned=$(el).next();
    var label=$('body').find('label[for='+$(el).attr('id')+']');
    $(radioSkinned).removeClass('rs-active');
    $(label).removeClass('fl-active');
  }}
}


/* controlForm */
function controlForm(ind,element){
	$('input[type=text],textarea',element).not('*[readonly]').each(function(){$(this).val($(this).attr('title'));});
	$('input[type=text],textarea',element).not('*[readonly]').focus(function(e){if($(this).val()==$(this).attr('title')){$(this).val('')}});
	$('input[type=text],textarea',element).not('*[readonly]').blur(function(e){if($(this).val()==''){$(this).val($(this).attr('title'))}});
	$('.errors,.error',element).hide();
	$('*[type=submit]',element).each(function(i,el){
    $(el).after('<a id="submit_'+ind+'" class="'+$(el).attr('class')+'" title="'+$(el).attr('title')+'">'+$(el).html()+'</a>');
    $(el).remove();
    $('#submit_'+ind).click(function(e){e.preventDefault(); controlCell(element);});
  });
  function controlCell(form){
    var errori=0;
    $('.errors,.error',form).hide();
    $('*[required]',form).not('*[readonly]').each(function(i,el){
        if ( $(el).is('input[name=name]') && ( $(el).val()==$(el).attr('title') || $(el).val()==''
              || !(/^([a-zA-Z\ ])+$/.test($(el).val())) ) )
          { $('.errors .error.name',form).show(); errori++; }
        if ( $(el).is('input[name=surname]') && ( $(el).val()==$(el).attr('title') || $(el).val()==''
              || !(/^([a-zA-Z\ ])+$/.test($(el).val())) ) )
          { $('.errors .error.surname',form).show(); errori++; }
        if ( $(el).is('input[name=email]') && ( $(el).val()==$(el).attr('title') || $(el).val()==''
              || !(/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/.test($(el).val())) ) )
          { $('.errors .error.email',form).show(); errori++; }
        if ( $(el).is('input[name=telephone]') && ( $(el).val()==$(el).attr('title') || $(el).val()==''
              || !(/^([0-9\ ])+$/.test($(el).val())) )  )
          { $('.errors .error.telephone',form).show(); errori++; }
        if( $(el).is('textarea') && ( $(el).val()==$(el).attr('title') || $(el).val()=='' 
              || false ) )
          { $('.errors .error.message',form).show(); errori++; }
        if( $(el).is('input[type="checkbox"]') && ( $(el).attr('checked') == false
              || false ) )
          { $('.errors .error.checkbox',form).show(); errori++; }
        if( $(el).is('.choices') && ( $(el).children('input[type="checkbox"][checked]').length == 0
              || false ) )
          { $('.errors .error.choices',form).show(); errori++; }
    })
    if(errori>0) $('.errors',form).show();
    else {
      $('input,textarea',form).not('*[readonly]').each(function(i,el){
        if(!$(el).attr('required') && ( $(el).val()==$(el).attr('title') || $(el).val()=='' ) )
          { $(el).val(''); }
      });
      $(form).submit();
    }
  }
}


/* mapper */
function mapper(address){try{
  var map,infowindow,geocoder,marker;
  map = new google.maps.Map(document.getElementById(address.id),{
    center:new google.maps.LatLng(0,0),
    mapTypeId:google.maps.MapTypeId.ROADMAP,
    zoom:13
  });
  // infowindow = new google.maps.InfoWindow({content:address.value,maxWidth:100});
  geocoder = new google.maps.Geocoder();
  geocoder.geocode({'address':address.value},function(results,status){
    if (status == google.maps.GeocoderStatus.OK){
      marker = new google.maps.Marker({
        map:map,
        title:address.value,
        position:results[0].geometry.location
      });
      marker.setMap(map);
      map.setCenter(results[0].geometry.location);
      // google.maps.event.addListener(marker,'click',function(){infowindow.open(map,marker);});
    }
  });
}catch(e){/*alert(e);*/}}


/* configuratorPopupGroup */
function configuratorOverlay(_url,_type,_xmlProgetto){
  // $('body').append('<form style="display:none;" id="form_popup" action="'+_url+'" target="BTicino_popup" method="post" onsubmit="openPopupForm(this);"><input type="hidden" name="type" id="type" value="'+_type+'" /><textarea cols="" rows="" name="xmlProgetto" id="xmlProgetto">'+_xmlProgetto+'</textarea></form>');
  $('body').append('<form style="display:none;" id="form_popup" action="'+_url+'" target="BTicino_popup" method="post" onsubmit="openPopupForm(this);"><input type="hidden" name="type" id="type" value="'+_type+'" /><textarea cols="" rows="" name="xmlProgetto" id="xmlProgetto">'+_xmlProgetto+'</textarea></form><a class="configuratorOverlayBtn" id="configuratorOverlayBtn" href="#" rel="#configuratorOverlay" style="visibility:hidden; position:absolute; z-index:-1; display:block; left:50%; top:50%;">&nbsp;</a><div class="overlay ov-configurator" id="configuratorOverlay"><div class="close">X</div><iframe id="configuratorContentOverlay" name="configuratorContentOverlay" frameborder="0" style="border:0; margin:0; padding:0; width:690px; height:500px;" width="690" height="500" src="#"></iframe><div class="cl"></div></div>');
	$('.configuratorOverlayBtn[rel]').each(function(i,el){
		var ref = this;
		var ov = $(this).attr('rel');
		$(this).overlay({
			mask          : {
				color         : '#ebebeb',
				loadSpeed     : 100,
				opacity       : .6
			},
			effect        : 'apple',
			closeOnClick  : false
		});
	});
	$('#configuratorOverlayBtn').click();
	$('#form_popup').submit();
}
function openPopupForm(form){
  // window.open("","BTicino_popup","width=690,height=500,location=0,status=0,titlebar=0,toolbar=0,menubar=0,directories=0");
  // form.target='BTicino_popup';
  form.target='configuratorContentOverlay';
}


/* facebookShare */
function facebookShare(str) {
  var baseURL = window.location.href;
  var urlToShare = encodeURIComponent(baseURL + "?progetto="+str);
  var fbUrl = "http://www.facebook.com/sharer.php?u="+ urlToShare +"&amp;t="+encodeURIComponent("CONFIGURATORE BTicino");
  var popUpFb = window.open(fbUrl,'sharer','toolbar=0,status=0,width=626,height=436');
}
