//nascondo le news e la galleria immagini solo a chi ha javascript abilitato
if (document.getElementById) {
  document.write('<style type="text/css">.hidden{position:absolute;left:-10000px;top:-10000px;width:1px;height:1px;overflow:hidden} ul.gallery{visibility:hidden; height:411px; overflow:hidden}  ul.galleria{visibility:visible; height:auto;}<\/style>');
}
/*javascript method: "pxToEm", JQuery Plugin: "EqualHeights" by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
Copyright (c) 2008 Filament Group Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.*/
Number.prototype.pxToEm = String.prototype.pxToEm = function(settings){
	//set defaults
	settings = jQuery.extend({
		scope: 'body',
		reverse: false
	}, settings);
	
	var pxVal = (this == '') ? 0 : parseFloat(this);
	var scopeVal;
	var getWindowWidth = function(){
		var de = document.documentElement;
		return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
	};	
	if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
		var calcFontSize = function(){		
			return (parseFloat($('body').css('font-size'))/getWindowWidth()).toFixed(3) * 16;
		};
		scopeVal = calcFontSize();
	}
	else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); };
			
	var result = (settings.reverse == true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
	return result;
};
$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};
// If Operas 1.0 Author Francesco Terenzani http://www.terenzani.it licence http://creativecommons.org/licenses/by-nc-sa/2.5/
function if_opera(url){
    if(is_opera()){
        AddCss(url)
    }
}
/*-link esterni-*/
function link_ext(){
if(!document.getElementsByTagName) return;
l=document.getElementsByTagName("a");
for(i=0;i<l.length;i++){
  if(l[i].className.indexOf("ext")!=-1){
    l[i].title+=" (link esterno, si apre in una nuova finestra)";
    l[i].onclick=function(){window.open(this.href);return(false)};
    }
  }
}
/*-inizializzazione jquery.pagination-*/
var items_per_page = 6;

function pageselectCallback(page_index, jq){
	var max_elem = Math.min((page_index+1) * items_per_page, $('#hiddenresult li.result').length);
	$('#searchresult').empty();
	$('#searchresult').hide();
	for(var i=page_index*items_per_page;i<max_elem;i++)
                {
                    var new_content = $('#hiddenresult li.result:eq('+i+')').clone();
                	$('#searchresult').append(new_content);
                }
	
	$('#searchresult').fadeIn("slow");
	initFancybox();
	return false;
}
function initPagination() {
	var num_entries = $('#hiddenresult li.result').length;
	$("#pagination").pagination(num_entries, {
		num_edge_entries: 1,
		num_display_entries: 3,
		items_per_page:items_per_page,
		callback: pageselectCallback
	});
 }
function initFancybox() {
  //se esistono link alle news
  if ($("a.iframe").length){
	  $("a.iframe").fancybox({
	   'hideOnContentClick': false,
	   'frameWidth': 485,
	   'frameHeight': 580,
	   'padding': 0,
	   'centerOnScroll': false
	  });
  }
 }
jQuery(document).ready(function(){ 
  link_ext();
  $(function(){ $('.prodotti').equalHeights(); })
  //se esiste contenuto da paginare
  if ($('#hiddenresult').length){
	  $("#hiddenresult").before("<ul id='searchresult'></ul>");
	initPagination();
  }
  initFancybox()
}); 
