/*
	ARS REGIA - JavaScripts
	Grzegorz Kaliciak, grzegorz@kaliciak.net / etrust.pl
	v1.0.0, 04.08.2007
*/

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function inputLabelFromLabel(input_id,label_id) {
	if (!document.getElementById) return false;
	if (!document.getElementById(input_id)) return false;
	if (!document.getElementById(label_id)) return false;
	var textInput = document.getElementById(input_id);
	var label = document.getElementById(label_id);
	var text = label.innerHTML;
	if (!textInput.value) textInput.value = text;
	textInput.onfocus = function() {
		if (this.value == text) {
			this.value = '';
		}
	}
	textInput.onblur = function() {
		if (this.value == '') {
			this.value = text;
		}
	}
}

addLoadEvent(function(){
	inputLabelFromLabel("search","search_l");
});


var handle_page_nav = function(){
	if ($j('#strona-nav').length > 0 ){
		var links_size = 0;
		$j('#strona-nav .x2 a').each(function(){
			links_size = links_size + $j(this).outerWidth(true);
		});
		if ( links_size  > 900){
			$j('#strona-nav').addClass('second-line');	
		}
	}
	
}

var handle_img_rot = function(){
	var imgs = $j('.img-box img');

	if(imgs.length > 1){
		imgs.css('opacity',0);
		imgs.eq(0).css('opacity',1);	
		
		var change = function(idx){
			var next = (idx + 1) % imgs.length;
			imgs.eq(idx).animate({'opacity': 0},{duration: 1200});
			imgs.eq(next).animate({'opacity': 1},{duration: 1200, queue: false});
			setTimeout(function() { change(next) }, 6000);
		}
		setTimeout(function() { change(0); }, 6000);
	}
}


$j(function(){
	handle_page_nav();
	handle_img_rot();
});




