function createXMLHttpRequest() {
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch(e) {}
	alert("Ajax non supportato, si consiglia di aggiornare il browser e/o di abilitare i controlli ActiveX");
	return null;
}

function VisualizzaProdotto(img, level) {

	//Get the screen height and width
	var maskWidth = $(window).width();
	var maskHeight = $(document).height();
	var winW = $(window).width();
	var winH = $(window).height();
	
	var url='view.php?img='+img+'&width='+winW;	
	if (level != 0) {
    	url= '../'+url;
    } 
	var req = createXMLHttpRequest();
	req.open("GET", url, true);
    req.onreadystatechange = function() {
        if (req.readyState == 4){
            if ((req.status == 200)) {
            	document.getElementById('alert2').innerHTML = req.responseText;
            	//document.getElementById('alert').style.visibility = 'visible';
            } 
        }
    }
    req.send(null);	

    //Set height and width to mask to fill up the whole screen
	$('#alert').css({'top':0, 'left':0, 'width':maskWidth,'height':maskHeight});
	$('#alert2').css({'top':0, 'left':0, 'width':maskWidth,'height':maskHeight});
    
	//transition effect		
	$('#alert').fadeIn(1000);	
	$('#alert2').fadeIn(1000);	
	$('#alert').fadeTo("slow",0.8);	
	$('#alert2').fadeTo("slow",1);	
	
	$('#dialog').css('left', winW/2-$('#dialog').width()/2);
	$('#dialog').css('top',  winH/2-$('#dialog').height()/2);

	//transition effect
	//$('#dialog').fadeIn(2000); 
	$('#dialog').fadeTo("slow",1);
	
	$('#close').click(function (e) { e.preventDefault(); $('#alert'+', .window').hide(); $('#alert2'+', .window').hide(); });		
	$('#alert2').click(function () { $('#alert'+', .window').hide(); $('#alert2'+', .window').hide(); });		 
}

function openWindow(path){
	var theHeight = 410;
	var theWidth = 520;
	var theTop = (screen.height/2)-(theHeight/2);
	var theLeft = (screen.width/2)-(theWidth/2);
	newwindow=window.open(path, '','scrollbars=1,toolbar=0,status=0,resizable=1,height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft);
	if (window.focus) {
		newwindow.focus();
	}	
	return false;			
}

$(document).ready(function(){
	$("#foto_prodotti").carouFredSel({
		auto : true,
		height: 90,
		width: 374,
		align: "center",
		padding:[0,20],
		scroll: {items:1},
		duration: 1000,
		pauseOnHover: true,
		items: {
			visible: 3,
			height: 72,
			width: "variable"
		}
	});
});
