function changeLetterSize(lt){
  size1="11px";
  size2="13px";
  size3="14px";
  coltochange = document.getElementById("midcol");
  for(a=1;a<4;a++){
    ltbutton = document.getElementById("lt"+a);
    if(a==lt){
      ltbutton.className="curSize";
      if(coltochange){
        coltochange.style.fontSize=eval("size"+lt);
      }
    }else{
      ltbutton.className="";
    }
  }
}

function showLVO(lvo){
  for(a=1;a<4;a++){
    elem1 = document.getElementById("lvo"+a);
    elem2 = document.getElementById("lvo_b"+a);
    if(a!=lvo){
      elem1.style.display="none";
      elem2.className="";
    }else{
      elem1.style.display="";
      elem2.className="current_lvo";
    }
  }
}

function showHide(id) {
	obj = document.getElementById(id);
	obj.style.display == 'none' ? obj.style.display = '' : obj.style.display = 'none';
}

function checkStrLength(strng,num){
  if(strng.length>=num)
    return true;
  return false;
}

jQuery.fn.briefcasemenu = function(){
  var current       = 0;
  var items         = this.find('.briefcase-body .briefcase-body-tab');
  var buttons       = this.find('.briefcase-menu li a');
  
  $(buttons[current]).addClass('selected');
  $(items[current]).addClass('selected-tab');
  
  var onClickBtn = function() { 
    var id = jQuery.inArray(this,buttons);
    $(buttons[current]).removeClass('selected');
    $(items[current]).removeClass('selected-tab');
    $(buttons[id]).addClass('selected');
    $(items[id]).addClass('selected-tab');
    current = id;
  };
  
  buttons.each(function(i) {
    $(buttons[i]).bind('click', onClickBtn);
  });
}

jQuery.fn.briefcasevideomenu = function(){
  var items         = this.find('.video-container .video-item');
  var prev          = this.find('.video-container .video-navigation a.prev');
  var next          = this.find('.video-container .video-navigation a.next');
  var timeOut	    = 10000;
  var timeOutFn     = null;
  var current       = null;
  var animStat      = false;

  var rotateElement = function(direction) { 
    direction = direction || 'next';
    if(animStat){
	    animStat = false;
		$(current).fadeOut("slow", function(){
		  changeElement(direction);
		  $(current).fadeIn("slow", function(){
			timeOutFn = setTimeout(rotateElement, timeOut);
	        animStat = true;
		  });
		});
	}
  }
  
  var changeElement = function(direction) {
    var currNo = jQuery.inArray(current, items);
	if(direction == 'next'){
	  currNo = currNo + 1;
	  if(currNo > items.length-1)
        currNo = 0; 
	}else{
	  currNo = currNo - 1;
	  if(currNo < 0)
        currNo = items.length - 1;	
	}
	current = items[currNo];
  }
  
  var startRotator = function() {
    current = (current != null) ? current : items[0];
	$(current).fadeIn("slow", function(){
	  timeOutFn = setTimeout(rotateElement, timeOut);
	  animStat = true;
	});
  }
  
  $(prev[0]).bind('click', function(){ clearTimeout(timeOutFn); rotateElement('prev'); });
  $(next[0]).bind('click', function(){ clearTimeout(timeOutFn); rotateElement('next'); });

  startRotator();
}

jQuery.fn.calendar = function(desturl){
	var curD = new Date();
	var curM = curD.getMonth();
	var curY = curD.getFullYear();
	var head = this.find('.calendar-header .current-month');
	var prev = this.find('.calendar-header .prev-month');
	var next = this.find('.calendar-header .next-month');
	var body = this.find('.calendar-items');
	var months = ["Styczeń", "Luty", "Marzec", "Kwiecień", "Maj", "Czerwiec", "Lipiec", "Sierpień", "Wrzesień", "Październik", "Listopad", "Grudzień"];

	var prevMonth = function(){
		curM --;
		if(curM < 0){
			curM = 11;
			curY--;
		}
		generateCalendar();
	};

	var nextMonth = function(){
		curM ++;
		if(curM > 11){
			curM = 0;
			curY++;
		}
		generateCalendar();
	};

	var getMonthDays = function(month, year){
		var DaysInMonth=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
		if(isLeapYear(year)){
			DaysInMonth[1]=29;
		}	
		return DaysInMonth[month];	
	};

	var isLeapYear = function(year){
		if((year%4) == 0){
			if ((year%100) == 0 && (year%400) != 0)
				return false;
			return true;
		}
		return false;
	};

	var generateCalendar = function(){
		$(head[0]).html(months[curM] + ' ' + curY);
		var dtToday = new Date();
		var counter = 0;
		var items = '';
		var monthDays = getMonthDays(curM, curY);

		var firstDayDate = new Date(curY, curM, 0);
		var firstDay = firstDayDate.getDay();
		if(firstDay < 0) firstDay = 7;
		for(i = 1; i <= firstDay; i++){
			items += '<div class="calendar-item-blank">&nbsp;</div>';
			counter++;
		}

		for(i = 1; i <= monthDays; i++){
			counter++;
			items += '<div';
			if((counter%7) == 0)
				items += ' style="width:32px;"';
			if ((i == dtToday.getDate()) && (curM == dtToday.getMonth()) && (curY == dtToday.getFullYear()))
				items += ' class="current"';
			items += '><a href="' + desturl + '/(newsdate)/' + curY + '-' + (curM + 1) + '-' + i + '">' + i + '</a></div>';
		}

		var lastDayDate = new Date(curY, curM, monthDays-1);
		var lastDay = lastDayDate.getDay();
		if(lastDay < 0) lastDay = 7;
		while(counter%7 != 0){
			counter++;
			items += '<div class="calendar-item-blank" ';
			if((counter%7) == 0)
				items += ' style="width:32px;"';
			items += '>&nbsp;</div>';
		}

		$(body[0]).html(items);
	};

	$(prev[0]).bind('click', prevMonth);
	$(next[0]).bind('click', nextMonth);
	generateCalendar();

}

