var kier = -1, num = 1,bizuteria= new Fx.Morph('bizshow', {duration: 'long', transition: Fx.Transitions.Sine.easeOut});

function moveBiz(){
bizuteria.cancel();
    bizuteria.start({
    'top': [-num*140]
    });
    num -= kier;
    if(num == 4 || num == 0){
	kier *= -1;
    }
}

var bpid;

function startbiz(){
    bpid = setInterval('moveBiz()',10000);
}
function pausebiz(){
    clearInterval(bpid);
}

startbiz();

myAccordion = new Fx.Accordion($$('.hmenu'), $$('.cmenu'));
var searchHover = new Fx.Morph('belt', {duration: 'short', transition: Fx.Transitions.Sine.easeOut}), hover = 0, scrolled = 0;
function checkPosSearch(){
    if(window.pageYOffset == 0){
    scrolled = 0;
    if (!hover){
    searchOver();
    hover = 0;
    }
    }else{
    if (!hover && !scrolled){
	scrolled = 1;
	searchOut();
    }
    
    }
   }
   function searchOver(){
    hover = 1;
    searchHover.cancel();
    searchHover.start({'opacity' : 1})  
   }
   function searchOut(){
    hover = 0;
    searchHover.cancel();
    if(window.pageYOffset > 0)
    searchHover.start({'opacity' : 0.3})  
   }
   $('belt').addEventListener('mouseover',searchOver, false);
   $('belt').addEventListener('mouseout',searchOut, false);
   window.addEventListener('scroll',checkPosSearch, false);
   
   var slider = new Fx.Scroll(window, {offset: {'x': 0,'y': -30 }});
   
   function spis(id){
	slider.toElement('item'+id);
	return false;
   }
  var micro = new Fx.Morph('micro_i', {duration: 'short', transition: Fx.Transitions.Sine.easeOut}), microCount = 1,
   microMes = new Fx.Morph('microMes', {duration: 'long', transition: Fx.Transitions.Sine.easeOut}), maxMicro = 0; 
   function addMicro(micro){
	mic = document.createElement("div");
	b = document.createElement("b");
	b.textContent = micro.when+':';
	
	mic.appendChild(b);
mic.innerHTML += micro.content;
$('micro_i').appendChild(mic);
++microCount;
microMes.cancel();
$('microMes').setStyles({'opacity':0,'visibility':'hidden'});
downMicro();
   }
   
   var getMicro = new Request.JSON({url: "/micro.php", onSuccess: function(micro){
if(micro.error == true)
microLast(micro.num);
else
    addMicro(micro);
    
}})
   
   function microLast(numm){
    maxMicro = numm;
    $('microMes').textContent = 'To jest ostatni wpis';
    microMes.cancel();
		microMes.start({'opacity':[1,0]});
   }
   function upMicro(){
	top = parseInt($('micro_i').getStyle('top'));
	if(top == 0){
	    $('microMes').textContent = 'To jest najnowszy wpis';
	    microMes.start({'opacity':[1,0]});
	   return; 
	}
	
    
    micro.start({'top':(top+40)});
   }
   
   function downMicro(){
	top = parseInt($('micro_i').getStyle('top'));
	if(top == -40*(microCount-1)){
	    numm = ((top*-1))/40 + 1;
	    if(maxMicro != 0 && numm== maxMicro){
		$('microMes').textContent = 'To jest ostatni wpis';
		microMes.start({'opacity':[1,0]});
		return;
	    }
	    $('microMes').textContent = 'Wczytuję kolejny. Proszę czekać';
	    microMes.start({'opacity':[0,1]});
	    getMicro.get({'num':numm});
	    return;
	}
	
micro.start({'top':(top-40)});
   }
   
   function codeclick(that){
    that = that.currentTarget;
	if(that.get('class')){
	    that.erase('class');
	}else{
	    that.set('class','codeclick');
	}
   }
   
   $$('.code li').each(function (el){
    el.addEventListener('click',function (e){
	codeclick(e);
	e.stopPropagation();
	}, false)
    });

   
   var comMes = new Request.JSON({onSuccess: function(com){
 $('submit').removeProperty('disabled');
showComMes(com.message, com.type);
 
}})
   
   function showComMes(mes,type){
     $('comMes').setStyle('display','block');
 $('comMes').set('class', type);
 $('comMes').innerHTML = mes;
   }
   
   function comment(url){
    if($('submit').get('disabled') != 'true'){
        $('submit').set('disabled', 'true');
    showComMes('Proszę czekać, trwa wczytywanie', 'wait')
	comMes.setOptions({'url' : url});
	if($('bot')){
	      comMes.post({'content' : ($('comment_content').value),
			    'bot' : ($('bot').value),
			    'guest' : ($('guest').value),'type' : $('type').value});  
	}else{
	    comMes.post({'content' : ($('comment_content').value),'type' : $('type').value});
	}
    }
    return false;
   }
   
   var google = new Request.JSON({'url' : 'http://ajax.googleapis.com/ajax/services/search/web', onSuccess: function(res){
alert(res.responseData.results[0].url) 
}})
   
   function search(){

    google.get({'v' : '1.0', 'q' : ($('q').value), 'key' : $('apikey').innerHTML});
    
    return false;
   }
   
   
   
   
   
   
   t = new Fx.Morph('cat', {duration: 'long', transition: Fx.Transitions.Sine.easeOut})
function cat(num){
    t.cancel();
 t.start({'top' : ((-42 * num)-5)});

}

$$('.show_code').each(function (el){
    el.addEvent('click',function (e){e.stop();
	//el.getParent().clear();
	href = el.href.replace(/code/,'ajax/code');
	el.getParent().set({'class' : '','tag' : 'div',
	       'html' : 'Proszę czekać trwa wczytywanie'}).load(href);
	//alert(href.replace(/code/,'ajax/code'));
	
	})
    });

   
   
