	$(document).ready(function(){	
		$('.cpicker-noactive-top').hide();
		$('.cpicker-top .cpicker-noactive').hide();
	
		$('.cpicker-top').mouseenter(function(){ schovejVrchni(this); });		
		$('.cpicker-big-glider-top').mouseenter(function(){ schovejVrchni(this); });
		$('.cpicker-noactive-top').mouseenter(function(){ schovejVrchni(this); });				


		$('.cpicker-bottom').mouseenter(function(){ schovejSpodni(this); });			
		$('.cpicker-big-glider-bottom').mouseenter(function(){ schovejSpodni(this);});
		$('.cpicker-noactive-bottom').mouseenter(function(){ schovejSpodni(this); });	
	
	
	});
	
	
	function schovejSpodni(obj) {
		$('.cpicker-top .cpicker-noactive').show();
		$('.cpicker-bottom .cpicker-noactive').hide();
		$('.cpicker-noactive-top').show();
		$('.cpicker-noactive-bottom').hide();		
	}
	
	function schovejVrchni(obj) {
		$('.cpicker-top .cpicker-noactive').hide();
		$('.cpicker-bottom .cpicker-noactive').show();
		$('.cpicker-noactive-top').hide();
		$('.cpicker-noactive-bottom').show();	
	}
        
         function vybraneBarvyRadek(){
        
        //*Vybrané barvy: <strong>Green / Grey / Red Dragon / Deep Blue</strong>

        d.getElementById("p_vybrane_barvy_top").innerHTML = 'PICKED COLORS: <strong>'+pOznTop.join(' / ')+'</strong>';
        d.getElementById("p_vybrane_barvy_bottom").innerHTML = 'PICKED COLORS: <strong>'+pOznTop.join(' / ')+'</strong>';
        
    }
    
    function kontrPole(){
        
                
        if (kontPole.length > 0){
            //*s-top-2-white
            
            for (var ii = 0; ii < kontPole.length; ii++) {

                for (var i = 0; i < poleBarvy.length; i++) {
                    //*alert('s-top-'+kontPole+'-'+poleBarvy[i])
                    d.getElementById('s-top-'+kontPole[ii]+'-'+poleBarvy[i]).className = '';
                    d.getElementById('s-bottom-'+kontPole[ii]+'-'+poleBarvy[i]).className = '';
                }
                for (var i = 0; i < pOznTop.length; i++) {
                    d.getElementById('s-top-'+kontPole[ii]+'-'+pOznTop[i]).className = 'noactive';
                    d.getElementById('s-bottom-'+kontPole[ii]+'-'+pOznTop[i]).className = 'noactive';
                }
            }            
        }
    }
    
    function vybraneBarvyBoxy(){
        
        for (var i = 0; i < pOznTop.length; i++) {
                d.getElementById("vybB-top-"+i).className = 'cpicker-selected-item cpicker-selected-'+pOznTop[i];
                d.getElementById("vybB-top-numb-"+i).innerHTML = (i+1)+'. ';
                d.getElementById("vybB-top-txt-"+i).innerHTML = pOznTop[i];

                d.getElementById("vybB-bottom-"+i).className = 'cpicker-selected-item cpicker-selected-'+pOznTop[i];
                d.getElementById("vybB-bottom-numb-"+i).innerHTML = (i+1)+'. ';
                d.getElementById("vybB-bottom-txt-"+i).innerHTML = pOznTop[i];


        }
        
        
        
    }
    
    
    var pOznTop = Array();
    var pOznBottom = Array();
    var d = document;
    
    function odstranVolby(id, barva, typ){
        
        var sekTyp = (typ == 'top') ? 'bottom' : 'top';
        
        
        
        if (pOznTop[id]){
            for (i = 0; i < pTopClikBColor.length; i++)
                {
                    
                    if (pClickColorConf[i] == 'obe')
                        {
                            d.getElementById('s-bottom-'+i+'-'+pOznTop[id]).className = '';
                            d.getElementById('s-top-'+i+'-'+pOznTop[id]).className = '';
                        }
                      else {
                          if (d.getElementById('s-'+typ+'-'+i+'-'+pOznTop[id])) d.getElementById('s-'+typ+'-'+i+'-'+pOznTop[id]).className = '';
                            else d.getElementById('s-'+sekTyp+'-'+i+'-'+pOznTop[id]).className = '';
                      }
                }
        }
        
        
        
        pOznTop[id] = barva;

      //*  alert(pOznTop)

        var str = pTopClikBColor[id];
        var pStr = str.split('|');
        
        for (i = 0; i < pStr.length; i++) {
             if (pClickColorConf[i] == 'obe')
                        {
                            d.getElementById('s-top-'+pStr[i]+'-'+barva).className = 'noactive';    
                            d.getElementById('s-bottom-'+pStr[i]+'-'+barva).className = 'noactive';    
                        }
                        else
                            {
                                if (d.getElementById('s-'+typ+'-'+pStr[i]+'-'+barva) )d.getElementById('s-'+typ+'-'+pStr[i]+'-'+barva).className = 'noactive';
                                  else d.getElementById('s-'+sekTyp+'-'+pStr[i]+'-'+barva).className = 'noactive';

                                if (pClickColorVyj[i] == 1){
                                   if (d.getElementById('s-'+sekTyp+'-'+pStr[i]+'-'+barva)) d.getElementById('s-'+sekTyp+'-'+pStr[i]+'-'+barva).className = 'noactive';
                                }
                            }
        }
        
        kontrPole();
       
      //* alert(pOznTop)
        
    }
    
    function clickChangetop(cis, barva){
        
        
        if (!d.getElementById('s-top-'+cis+'-'+barva)) return;
            if (d.getElementById('s-top-'+cis+'-'+barva).className == 'noactive') return;
        
        var prvky = poleClickHorni[cis];
        var polePrvky = prvky.split("|");
        
        if (poleClickHorniSpodek[cis]){
            var prvkySpodek = poleClickHorniSpodek[cis];
            var polePrvkySpodek = prvkySpodek.split("|");
        }

        if (poleClikSmallHorni[cis]){
            var prvkySmallHorni = poleClikSmallHorni[cis];
            var polePrvkySmallHorni = prvkySmallHorni.split("|");

            for (i = 0; i < polePrvkySmallHorni.length; i++) {

                var classCast = poleCasti[polePrvkySmallHorni[i]];

                if (typPadaku == 'ANAKIS-2'){
                    if (classCast == 'cpicker-left-bottom') classCast = 'cpicker-left-es-bottom';
                    if (classCast == 'cpicker-right-bottom') classCast = 'cpicker-right-es-bottom';
                    
                }
                
                d.getElementById('small-top-cast-'+polePrvkySmallHorni[i]).className = poleCasti[polePrvkySmallHorni[i]]+' '+classCast+'-'+barva;
                d.getElementById('small-bottom-cast-'+polePrvkySmallHorni[i]).className = poleCasti[polePrvkySmallHorni[i]]+' '+classCast+'-'+barva;

            }
        }        
        if (zahSpodek == 1){
            if (poleClikSmallSpodek[cis]){
                var prvkySmallSpodek = poleClikSmallSpodek[cis];
                var polePrvkySmallSpodek = prvkySmallSpodek.split("|");

                for (i = 0; i < polePrvkySmallSpodek.length; i++) {
                    
                    var classCast = poleCasti[polePrvkySmallSpodek[i]];

                    if (typPadaku == 'ANAKIS-2'){
                        if (classCast == 'cpicker-left-bottom') classCast = 'cpicker-left-es-bottom';
                        if (classCast == 'cpicker-right-bottom') classCast = 'cpicker-right-es-bottom';
                    }

//*                    alert(poleCasti[polePrvkySmallSpodek[i]]+' '+classCast+'-'+barva)                    
                    
                    d.getElementById('small-top-cast-'+polePrvkySmallSpodek[i]).className = poleCasti[polePrvkySmallSpodek[i]]+' '+classCast+'-'+barva;
                    d.getElementById('small-bottom-cast-'+polePrvkySmallSpodek[i]).className = poleCasti[polePrvkySmallSpodek[i]]+' '+classCast+'-'+barva;
                }        
            }
        }
        
        for (i = 0; i<(polePrvky.length); i++) {
            
            var classCast = poleCasti[polePrvky[i]];

            if (typPadaku == 'ANAKIS-2'){
                if (classCast == 'cpicker-left-bottom') classCast = 'cpicker-left-es-bottom';
                if (classCast == 'cpicker-right-bottom') classCast = 'cpicker-right-es-bottom';
            }
            
            if (polePrvky[i]== 7 || polePrvky[i] == 6 || polePrvky[i] == 4 || polePrvky[i] == 5) {
                
                d.getElementById('small-bottom-cast-'+polePrvky[i]).className = poleCasti[polePrvky[i]]+' '+classCast+'-'+barva;
                
            }
            if (d.getElementById('small-bottom-big-cast-'+polePrvky[i])) d.getElementById('small-bottom-big-cast-'+polePrvky[i]).className = poleCasti[polePrvky[i]]+' '+classCast+'-'+barva;
            if (poleClickSpodekHorni[cis]){
                if (d.getElementById('small-top-big-cast-'+polePrvkySpodek[i])) d.getElementById('small-top-big-cast-'+polePrvkySpodek[i]).className = poleCasti[polePrvkySpodek[i]]+' '+classCast+'-'+barva;
            }
        }
        
        odstranVolby(cis, barva, 'top');
        
        vybraneBarvyRadek();
        vybraneBarvyBoxy();
    }

function clickChangebottom(cis, barva){
    if (!d.getElementById('s-bottom-'+cis+'-'+barva)) return;
        if (d.getElementById('s-bottom-'+cis+'-'+barva).className == 'noactive') return;
        
        var prvky = poleClickSpodek[cis];
        var polePrvky = prvky.split("|");
        
        if (poleClickSpodekHorni[cis]){
            var prvkySpodek = poleClickSpodekHorni[cis];
            var polePrvkySpodek = prvkySpodek.split("|");
        }

        if (zahHorni == 1){
            if (poleClikSmallHorni[cis]){
                var prvkySmallHorni = poleClikSmallHorni[cis];
                var polePrvkySmallHorni = prvkySmallHorni.split("|");

                for (i = 0; i < polePrvkySmallHorni.length; i++) {
                    
                    var classCast = poleCasti[polePrvkySmallHorni[i]];

                    if (typPadaku == 'ANAKIS-2'){
                        if (classCast == 'cpicker-left-bottom') classCast = 'cpicker-left-es-bottom';
                        if (classCast == 'cpicker-right-bottom') classCast = 'cpicker-right-es-bottom';

                    }
                    
                    d.getElementById('small-top-cast-'+polePrvkySmallHorni[i]).className = poleCasti[polePrvkySmallHorni[i]]+' '+classCast+'-'+barva;
                    d.getElementById('small-bottom-cast-'+polePrvkySmallHorni[i]).className = poleCasti[polePrvkySmallHorni[i]]+' '+classCast+'-'+barva;
                }
            }
        }

        if (poleClikSmallSpodek[cis]){
            var prvkySmallSpodek = poleClikSmallSpodek[cis];
            var polePrvkySmallSpodek = prvkySmallSpodek.split("|");
            for (i = 0; i < polePrvkySmallSpodek.length; i++) {
                
                var classCast = poleCasti[polePrvkySmallSpodek[i]];

                    if (typPadaku == 'ANAKIS-2'){
                        if (classCast == 'cpicker-left-bottom') classCast = 'cpicker-left-es-bottom';
                        if (classCast == 'cpicker-right-bottom') classCast = 'cpicker-right-es-bottom';

                    }
                
                d.getElementById('small-top-cast-'+polePrvkySmallSpodek[i]).className = poleCasti[polePrvkySmallSpodek[i]]+' '+classCast+'-'+barva;
                d.getElementById('small-bottom-cast-'+polePrvkySmallSpodek[i]).className = poleCasti[polePrvkySmallSpodek[i]]+' '+classCast+'-'+barva;
            }        
        }        

        for (i = 0; i<(polePrvky.length); i++) {
            
            var classCast = poleCasti[polePrvky[i]];

                    if (typPadaku == 'ANAKIS-2'){
                        if (classCast == 'cpicker-left-bottom') classCast = 'cpicker-left-es-bottom';
                        if (classCast == 'cpicker-right-bottom') classCast = 'cpicker-right-es-bottom';

                    }
            
            if (polePrvky[i]== 7 || polePrvky[i] == 6 || polePrvky[i] == 4 || polePrvky[i] == 5){
                d.getElementById('small-top-cast-'+polePrvky[i]).className = poleCasti[polePrvky[i]]+' '+classCast+'-'+barva;
            }
            if (d.getElementById('small-top-big-cast-'+polePrvky[i])) d.getElementById('small-top-big-cast-'+polePrvky[i]).className = poleCasti[polePrvky[i]]+' '+classCast+'-'+barva;
            if (poleClickSpodekHorni[cis]){
                if (d.getElementById('small-bottom-big-cast-'+polePrvkySpodek[i])) d.getElementById('small-bottom-big-cast-'+polePrvkySpodek[i]).className = poleCasti[polePrvkySpodek[i]]+' '+classCast+'-'+barva;
            }
        }
        
         odstranVolby(cis, barva, 'bottom');
         vybraneBarvyRadek();
         vybraneBarvyBoxy();
    }
    
