window.addEvent('domready',function(){

if ($('change_view') != null) {
    ch_w = 0;
    $('change_view').addEvent('click', function(e){
       if (ch_w == 0) {
           $('space2').fade('out').hide();
           $('spaceManHolder').fade('in').show();
           ch_w = 1;
       }else {
           $('spaceManHolder').fade('out').hide();
           $('space2').fade('in').show();
           ch_w = 0;
       } 
    });
}

	
if($('tindex') != null && $("spaceMan") == null) {

    new NivooSlider($('tindex'), {
        animSpeed: 750,
        effect: 'fade',
        interval: 5000,
        orientation: 'horizontal',
        slices: 20,
        directionNav: false
    }).addEvents({
        'onFinish': function(){
        
        },
        'onStart': function(){
          
        }
    });
}
if ($("spaceMan") != null) {
loadS();

makeTable();

}

});


function dostosuj(){
    $('dostosuj').show().fade('in');
}

var spacers = "";
 
		function loadS(){
			spacers = $("spaceMan").getElements(".spaceOB");
			intSpace(); 
		}
		
		  function intSpace(){
  			
    
			spacers.addEvents({
				'mouseover': function(){
					if(this.getStyle("z-index") != 20){
						this.setStyle("top", parseInt(this.getStyle("top"))-2);
					}
				},
				'mouseout': function(){
					if(this.getStyle("z-index") != 20){
						this.setStyle("top", parseInt(this.getStyle("top"))+2);
					}
				},
				'click': function(){
				 
					doSpace(this);
				}
			});
 
 
  			spacers.each(function(item, index){
	 
					var color = [index*40, 230, 230].hsbToRgb();
				 
					spacers[index].setStyles({
				 
						"z-index": 20-index,
						"background-color": "#efefef"
 
					});
					
					spacers[index].set('morph', {duration: 1000-(index*100), transition: 'Sine:out', onComplete: function(){
     	 				 			
     	 				 	   }});
	 				spacers[index].morph({opacity: [0, (100-(index*10))/100], width: 523-(index*32.3), height: 453-(index*20.3), left: 60+((index*23.5)/1.5), top: 80-(index*(15-(index)))});
	 			
 
				 
				
			}); 
				 setTimeout(function(){$("spaceHelp").fade([0,1]);}, 1000);
			
 	
  }
  
  
  function doSpace(el){	
  		
  		var positionOfClicked = 20 - el.getStyle("z-index"); 
 
  		var topPos = 0; 
  		
  		spacers.each(function(item, index){
  			var zIndexi = parseInt(spacers[index].getStyle("z-index"));
  			
	 			if(zIndexi == 20){
	 					spacers[index].setStyle("z-index", 20-(spacers.length-1));   
	 					spacers[index].set('morph', {duration: '500', transition: 'Sine:out', onComplete: function(){
     	 				 		
     	 				 				spacers[index].set('morph', {duration: '500', transition: 'Sine:out', onComplete: function(){
     	 				 				
     	 				 				 }});
     	 				 				
     	 				 				spacers[index].morph({opacity: [0, 0.5], width: [700,429.5], height: [50, 102.5], left: [170, 105], top: [40, 40]});
     	 				 			
     	 				 	   }});
	 					spacers[index].morph({opacity: 0, width: 600, height: 420, left: 25, top: 110});
 
	 			}
	 			else{
	 			 
	 					var thisPos = 20-(zIndexi+1);
	 					  spacers[index].setStyle("z-index", zIndexi+1);
	 					spacers[index].set('morph', {duration: '500', transition: 'Sine:out', onComplete: function(){
     	 				 			
     	 				 	   }});
	 					spacers[index].morph({opacity: (100-(thisPos*10))/100, width: 523-(thisPos*32.3), height: 453-(thisPos*20.3), left: 60+((thisPos*23.5)/1.5), top: 80-(thisPos*(15-(thisPos)))});
                                               
	 			
	 			}
			}); 
			
			if(positionOfClicked == 0){
				return false;
			}
			if(positionOfClicked != 1){
  			  
  			// setTimeout("doSpace(el);", 100);
  	 		 setTimeout(function(){doSpace(el)}, 125);
  			}
  			 makeTable();
  }
  
  function makeTable() {
      
     $$('.highlight-table').each(function(el) { 
         
      var table = el;
var rows = table.getElements('tr');
      rows.each(function(tr,trCount){
  
  if(tr.getParent().get('tag') == 'thead') {return false;}
 
  tr.addClass('row-' + trCount);
  
  tr.addEvents({
    'mouseenter': function(){
      tr.addClass('row-hover');
    },
    'mouseleave': function(){
      tr.removeClass('row-hover');
    }
  });
 
  tr.getElements('td').each(function(td,tdCount) {
   
    var column = 'col-' + tdCount;
    var friends = 'td.' + column;

    td.addClass(column);
 
    td.addEvents({
      'mouseenter': function(){
        $$(friends).erase(td).addClass('column-hover');
        td.addClass('cell-hover');
      },
      'mouseleave': function() {
        $$(friends).erase(td).removeClass('column-hover');
        td.removeClass('cell-hover');
      }
    });
  });
});
});
  }

function formularz_onchange() {
if($('time').get('value') == 12) {
$('gratis').show();
}else{
$('gratis').hide();
}
}

