
var banner = 0;
var pag_ico = 0;
var pag_img = 0;


var i = 1; //indice array sfondo collezioni
var arr_collezioni = new Array();


var arr_articoli = new Array();  //array degli id degli articoli da aggiungere al carrello


/* disabilitazione tasto destro */
function nrcIE(){if (document.all){return false;}}
function nrcNS(e){
if(document.layers||(document.getElementById&&!document.all)){ 
if (e.which==2||e.which==3){return false;}}} 
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=nrcNS;
}else{document.onmouseup=nrcNS;document.oncontextmenu=nrcIE;}
document.oncontextmenu=new Function("return false");
/* fine cattura tasto destro */



//funzioni di gestione dei cookie

    function Get_Cookie(name) {
	   var start = document.cookie.indexOf(name+"=");
	   var len = start+name.length+1;
	   if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
	   if (start == -1) return null;
	   var end = document.cookie.indexOf(";",len);
	   if (end == -1) end = document.cookie.length;
	   return unescape(document.cookie.substring(len,end));
	 }

    function Set_Cookie(name,value,expires,path,domain,secure){
    	var cookieString = name + "=" +escape(value) +
	       ( (expires) ? ";expires=" + expires.toGMTString() : "") +
	       ( (path) ? ";path=" + path : "") +
	       ( (domain) ? ";domain=" + domain : "") +
	       ( (secure) ? ";secure" : "");
	    document.cookie = cookieString;
    }
    
    function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
	    document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
    }


    function set_img_index(index){
	   /*if (!Get_Cookie('img_index')){
	       Set_Cookie('img_index',index,'','/');       
	   }
	   else {
		deleteCookie('img_index');
		Set_Cookie('img_index',index,'','/');
	   }*/
	   Set_Cookie('img_index',index,'','/');
    }	   


//sfondo home
function set_bg(){
	if (document.getElementById("sub_home") != null){
		if (Get_Cookie('img_index')){		
			pic = new Image();
			pic.src = Get_Cookie('img_index');
			document.getElementById("sub_home").style.backgroundImage = 'url('+pic.src+')';
		}		else {					sfondoprincipale = '/var/ezwebin_site/storage/images/media/images/032/3983-1-ita-IT/03.jpg';						document.getElementById("sub_home").style.backgroundImage = 'url('+sfondoprincipale+')';
        }	}	
}

//sfondo collezioni
function switch_img(img){
        arr_collezioni = img;
        setTimeout("img_collezioni('"+img[i]+"')", 5000);        
}

function img_collezioni(path){
        pic = new Image();
        pic.src = "/"+path;
	document.getElementById("tb_collezioni").style.backgroundImage = 'url('+pic.src+')';
        if(i == (arr_collezioni.length-1))
                i = 0;
           else     
                i++; 
        switch_img(arr_collezioni);
}

function show_col(path){
	if (document.getElementById("tb_collezione") != null){
                        if(path != ''){
                                pic = new Image();
                                pic.src = path;
                                document.getElementById("tb_collezione").style.backgroundImage = 'url('+pic.src+')';
                        }
                        setTimeout("hide_all()", 1000);
        }	
}

function hide_all(){
        new Effect.Fade(document.getElementById('col_trucco'),{duration: 0.6});
        
        var date = new Date();
        var curDate = null;

        do { curDate = new Date(); }
        while(curDate-date < 650);
        
        new Effect.Fade(document.getElementById('view_img'),{duration: 0.5});
        new Effect.Fade(document.getElementById('content_td1'),{duration: 1});
        setTimeout("show_back()", 2000);
        //setTimeout("hide_view()",2000);
}

function show_back(){
        new Effect.Appear(document.getElementById('content_td2'),{duration: 1});
        new Effect.Appear(document.getElementById('flukso_mini'),{duration: 1});
}

function hide_view(){
        new Effect.Fade(document.getElementById('view_img'),{duration: 0.5});
}

function show_view(){
        new Effect.Appear(document.getElementById('view_img'),{duration: 1});
}

function back_all(path){
        new Effect.Fade(document.getElementById('content_td2'),{duration: 0.5});
        new Effect.Fade(document.getElementById('flukso_mini'),{duration: 0.5});
        setTimeout("show_content_td1('"+path+"')", 600);
}

function show_content_td1(path){
        new Effect.Appear(document.getElementById('content_td1'),{duration: 1});
        pic = new Image();
	pic.src = path;
        setTimeout("show_col_trucco('"+path+"')", 1);
        setTimeout("show_view()", 1);
}

function show_col_trucco(path){
        new Effect.Appear(document.getElementById('col_trucco'),{duration: 0.5});
        setTimeout("restore_sfondo('"+path+"')", 1000);
}

function restore_sfondo(path){
        document.getElementById("tb_collezione").style.backgroundImage = 'url('+pic.src+')';
}

//scritta index
function banner_start(){
	setTimeout("manage_banner()", 500);    
}

function manage_banner(){
	if(banner == 0){		
		banner = 1;
		new Effect.Appear(document.getElementById('banner'),{duration: 0.6});
		setTimeout("manage_banner()", 3000);		
	}
	else{
		banner = 0;
		new Effect.Fade(document.getElementById('banner'),{duration: 1});
		setTimeout("manage_banner()", 3000);
	}	
}


//pagine icone
function next_ico(){            
        var tab_current = eval('document.getElementById(\'ico_'+pag_ico+'\')');
	var tab_next = eval('document.getElementById(\'ico_'+(pag_ico+1)+'\')');        
        
		if(tab_next != null){
			pag_ico = (pag_ico + 1);			
			tab_current.className = 'hide';
			tab_next.className = '';		
		}
        
        //mosse future        
        var tab_next = eval('document.getElementById(\'ico_'+(pag_ico+1)+'\')');
        var tab_prev = eval('document.getElementById(\'ico_'+(pag_ico-1)+'\')');
        if(tab_prev != null)
                document.getElementById('prev').innerHTML = '<a href="#" onclick="javascript:prev_ico();"><img src="/design/ezwebin/images/p.png" border="0" />';                        
        else
                document.getElementById('prev').innerHTML = '';
        if(tab_next != null)
                document.getElementById('next').innerHTML = '<a href="#" onclick="javascript:next_ico();"><img src="/design/ezwebin/images/n.png" border="0" />';                        
        else
                document.getElementById('next').innerHTML = ''; 
}

function prev_ico(){            
        var tab_current = eval('document.getElementById(\'ico_'+pag_ico+'\')');
	var tab_next = eval('document.getElementById(\'ico_'+(pag_ico-1)+'\')');       
		
                if(tab_prev != null)
                        document.getElementById('prev').innerHTML = '<a href="#" onclick="javascript:prev_ico();"><img src="/design/ezwebin/images/p.png" border="0" />';                        
                else
                        document.getElementById('prev').innerHTML = '';
                
		if(tab_next != null){
			pag_ico = (pag_ico - 1);			
			tab_current.className = 'hide';
			tab_next.className = '';		
		}
                
        //mosse future        
        var tab_next = eval('document.getElementById(\'ico_'+(pag_ico+1)+'\')');
        var tab_prev = eval('document.getElementById(\'ico_'+(pag_ico-1)+'\')');
        if(tab_prev != null)
                document.getElementById('prev').innerHTML = '<a href="#" onclick="javascript:prev_ico();"><img src="/design/ezwebin/images/p.png" border="0" />';                        
        else
                document.getElementById('prev').innerHTML = '';
        if(tab_next != null)
                document.getElementById('next').innerHTML = '<a href="#" onclick="javascript:next_ico();"><img src="/design/ezwebin/images/n.png" border="0" />';                        
        else
                document.getElementById('next').innerHTML = '';        
}

//pagina precedente immagini
function prev_img(){
	if(pag_img != 0){	
		var tab_current = eval('document.getElementById(\'img_'+pag_img+'\')');
		var tab_next = eval('document.getElementById(\'img_'+(pag_img-1)+'\')');		
		
		pag_img = (pag_img - 1);
		
		tab_current.className = 'hide';
		tab_next.className = '';
	}
}

//pagina successiva immagini
function next_img(){
		var tab_current = eval('document.getElementById(\'img_'+pag_img+'\')');
		var tab_next = eval('document.getElementById(\'img_'+(pag_img+1)+'\')');			
		
		if(tab_next != null){
			pag_img = (pag_img + 1);			
			tab_current.className = 'hide';
			tab_next.className = '';		
		}		
}



function download(path,name){		

	var req = Math.floor(Math.random()*1000);

	/*var myConn = new XHConn();
	  if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	    var fnWhenDone = function (oXML) {
	    var response = oXML.responseText;			
	  };
	  
	 myConn.connect("/download.php", "GET","file="+encode64(path)+"&nome="+name+"&req="+req, fnWhenDone);	*/
	
	location.href="/download.php?file="+encode64(path)+"&nome="+name+"&req="+req;
	
}

//aggiunta rimozione articoli
function articolo_carrello(chk){
        var str = '';
        var i = 0;
        
            
        if(chk.checked == true){
             arr_articoli.push(chk.value);             
        }        
        else{         
             arr_new = new Array();
             while(i<arr_articoli.length) {
                if(arr_articoli[i] != chk.value)
                      arr_new.push(arr_articoli[i]);
                i++;      
             }
             arr_articoli = arr_new
        }
        
        
        /*i = 0;
        while(i<arr_articoli.length) { str = str+" "+arr_articoli[i];i++;}
        alert(str);*/
}


function add(lan){
        var obj = arr_articoli.pop();
        if(obj != null)
                aggiungi_carrello(obj,lan);
        else{
              if(lan == 'ita'){  
                if (confirm("Nessun prodotto da aggiungere, vuoi visualizzare il carrello?"))
                {
                location.href="/index.php/shop/basket";
                }
              }
              else{  
                if (confirm("You have no products selected, do you wanto to go to the basket?"))
                {
                location.href="/index.php/eng/shop/basket";
                }
              }
        }        
}

function aggiungi_carrello(obj,lan){		

        if(lan == 'ita')  
                document.getElementById('link_add').innerHTML = '<a href="#">AGGIORNAMENTO ('+arr_articoli.length+')</a>';
        else
                document.getElementById('link_add').innerHTML = '<a href="#">ADDING ITEM ('+arr_articoli.length+')</a>';

	var req = Math.floor(Math.random()*1000);

	var myConn = new XHConn();
	  if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	    var fnWhenDone = function (oXML) {	    
            var next = arr_articoli.pop();
            if(next != null)
                aggiungi_carrello(next,lan);
            else{
                if(lan == 'ita')
                        location.href="/index.php/shop/basket";
                else
                        location.href="/index.php/eng/shop/basket";
            }
	  };
	  
	 myConn.connect("/index.php/ita/content/action", "POST","ActionAddToBasket=Aggiungialcarrello&ContentNodeID="+obj+"&ContentObjectID="+obj+"&ViewMode=full", fnWhenDone);     
}



