		var next=0;
		var setInt;
		var current=0;
		var maxcurrent=6;
			function moveAnimate(no) {
//				return true;
	            if (current>no) {
	            	$(".articleinmm2").animate({left: "+="+((current-no)*438)}, 150, "", function () {   }); 
	            }
	            if (current<no) $(".articleinmm2").animate({left: "-="+((no-current)*438)}, 150, "", function () {   }); 

				current=no;
				next=no;
				$(".button_mm_active_top").removeClass("button_mm_active_top");
				$(".button_mm_active_middle").removeClass("button_mm_active_middle");
				$(".button_mm_active_bottom").removeClass("button_mm_active_bottom");
				if ($("#mainmod_s_"+current).children('div').attr("class")=="button_mm_inactive_top")  {
					$("#mainmod_s_"+current).children('div').addClass("button_mm_active_top");
				}
				if ($("#mainmod_s_"+current).children('div').attr("class")=="button_mm_inactive_middle")  {
					$("#mainmod_s_"+current).children('div').addClass("button_mm_active_middle");
				}
				if ($("#mainmod_s_"+current).children('div').attr("class")=="button_mm_inactive_bottom")  {
					$("#mainmod_s_"+current).children('div').addClass("button_mm_active_bottom");
				}

			}


		
		function startInterval() {
			if (next>maxcurrent) { next=0;}
			moveAnimate(next);
			next++;
		}




		this.tooltip = function(){	
			/* CONFIG */		
				xOffset = 10;
				yOffset = 170;		
				// these 2 variable determine popup's distance from the cursor
				// you might want to adjust to get the right result		
			/* END CONFIG */		
			$(".showcalendar").click(function(e){											  
				  
				$("#tooltip")
					.css("top",(e.pageY - xOffset) + "px")
					.css("left",(e.pageX - yOffset) + "px")
					.fadeIn("fast");	
		    });	
		};

		function eventTabCategory(category_id) {
			id=$("#mod").val();
			$("#modM"+id).val(category_id);
			$(".mod_a"+id).hide();
			$("#mod_a"+id+"_"+category_id).show();
			
			$(".button_down_active_left").addClass("button_down_inactive_left");
			$(".button_down_active_left").removeClass("button_down_active_left");
			$("#buttonM"+category_id).children("div.button_down_inactive_left").addClass("button_down_active_left");
			$("#buttonM"+category_id).children("div.button_down_inactive_left").removeClass("button_down_inactive_left");
			
			$(".name_button_down_active").addClass("name_button_down_inactive");
			$(".name_button_down_active").removeClass("name_button_down_active");
			$("#buttonM"+category_id).children("div.name_button_down_inactive").addClass("name_button_down_active");
			$("#buttonM"+category_id).children("div.name_button_down_inactive").removeClass("name_button_down_inactive");
			
			$(".button_down_active_right").addClass("button_down_inactive_right");
			$(".button_down_active_right").removeClass("button_down_active_right");
			$("#buttonM"+category_id).children("div.button_down_inactive_right").addClass("button_down_active_right");
			$("#buttonM"+category_id).children("div.button_down_inactive_right").removeClass("button_down_inactive_right");
		}
		
		function eventTab(id) {
			$("#mod").val(id);
			id=$("#mod").val();

			eventTabCategory($("#modM"+id).val());
				
			$('#mod_a1_').hide();		
			if (id==1) {
				$('#mod_a2').hide();
				$('#mod_a1').show(); 
				
				$('#event_a1').addClass('button_active_left');
				$('#event_a1').removeClass('button_inactive_left');
				$('#event_a2').addClass('name_button_active');
				$('#event_a2').removeClass('name_button_inactive');
				$('#event_a3').addClass('button_active_right');
				$('#event_a3').removeClass('button_inactive_right');
				
				$('#event_b1').addClass('button_inactive_left');
				$('#event_b1').removeClass('button_active_left');
				$('#event_b2').addClass('name_button_inactive');
				$('#event_b2').removeClass('name_button_active');
				$('#event_b3').addClass('button_inactive_right');
				$('#event_b3').removeClass('button_active_right');
			} 
			if (id==2) {
				$('#mod_a1').hide();
				$('#mod_a2').show();

				$('#event_a1').addClass('button_inactive_left');
				$('#event_a1').removeClass('button_active_left');
				$('#event_a2').addClass('name_button_inactive');
				$('#event_a2').removeClass('name_button_active');
				$('#event_a3').addClass('button_inactive_right');
				$('#event_a3').removeClass('button_active_right');				
				
				$('#event_b1').addClass('button_active_left');
				$('#event_b1').removeClass('button_inactive_left');
				$('#event_b2').addClass('name_button_active');
				$('#event_b2').removeClass('name_button_inactive');
				$('#event_b3').addClass('button_active_right');
				$('#event_b3').removeClass('button_inactive_right');				
			}
		}

		/* 
			updown
			0 - up
			1 - down
		
			Id:
			0 wiadomosci 
			1 sport
			2 kultura
			3 finanse
			4 czas wolny		
		*/	
			var boxMP = new Array(
				getsetcookie("hejgrupabox_0","0",0),
				getsetcookie("hejgrupabox_1","1",0),
				getsetcookie("hejgrupabox_2","2",0),
				getsetcookie("hejgrupabox_3","3",0),
				getsetcookie("hejgrupabox_4","4",0)
			);
			var boxMP2 = new Array(
				getsetcookie("hejgrupaboxb_0","0",0),
				getsetcookie("hejgrupaboxb_1","1",0),
				getsetcookie("hejgrupaboxb_2","2",0),
				getsetcookie("hejgrupaboxb_3","3",0),
				getsetcookie("hejgrupaboxb_4","4",0)
			);
			var boxMP3 = new Array(
				getsetcookie("hejgrupaboxc_0","0",0),
				getsetcookie("hejgrupaboxc_1","1",0),
				getsetcookie("hejgrupaboxc_2","2",0),
				getsetcookie("hejgrupaboxc_3","3",0)
			);	
				
			var boxMP_html = new Array(5);
			var boxMP_html2 = new Array(5);
			var boxMP_html3 = new Array(4);
			var boxMP_movemod;
			var temp1;
			var temp2;
			var temp3;
			var number;	
					
		$(document).ready(function() {
		
			// przypisanie do tablicy aktualnych boksów
			for (var n = 0; n < boxMP.length; n++) {
				boxMP_html[n]=$("#movemod"+n).html();
				boxMP_html2[n]=$("#movemodb"+n).html();
				if (n<4) { boxMP_html3[n]=$("#movemodc"+n).html(); }
			}	
			// nasz układ strony głównej pamietany w cookies
			for (var n = 0; n < boxMP_html.length; n++) {
				boxMP_html[boxMP[n]]=replaceArrow(boxMP_html[boxMP[n]],n,(boxMP.length-1),"");
				$("#movemod"+n).html(boxMP_html[boxMP[n]]);
				
				
				boxMP_html2[boxMP2[n]]=replaceArrow(boxMP_html2[boxMP2[n]],n,(boxMP2.length-1),"");
				$("#movemodb"+n).html(boxMP_html2[boxMP2[n]]);
				
				
				if (n<4) { 
					if ((n==0 && boxMP3[n]==0) || (n==(boxMP3.length-1) && boxMP3[n]==0)) { prefix="c"; } else { prefix=""; }	
					boxMP_html3[boxMP3[n]]=replaceArrow(boxMP_html3[boxMP3[n]],n,(boxMP3.length-1),prefix);
					$("#movemodc"+n).html(boxMP_html3[boxMP3[n]]); 				
				}
			}
		});
			
		
		
		// środek
		function moveMainBox(id,updown) {
			
			// szukamy indeksu
			for (var n = 0; n < boxMP.length; n++) {
				if (boxMP[n]==id) {
					number=n; 
					break;
				}
			}			
			if ((number==4 && updown==1) || (number==0 && updown==0)) {return'';}
			if (updown==0) { $("#movemod"+number).fadeTo("fast", 0.3);$("#movemod"+(number-1)).fadeTo("fast", 0.3); }
			if (updown==1) { $("#movemod"+number).fadeTo("fast", 0.3);$("#movemod"+(number+1)).fadeTo("fast", 0.3); }
			
			
			// update tablicy
			temp1=boxMP[number];
			if (updown==0) {
				temp2=boxMP[number-1];
				boxMP[number-1]=temp1;
			} else if (updown==1) {
				temp2=boxMP[number+1];
				boxMP[number+1]=temp1;
			}
			boxMP[number]=temp2;

			if (updown==0) {
				boxMP_html[boxMP[number]]=replaceArrow(boxMP_html[boxMP[number]],number,(boxMP.length-1),"");
				$("#movemod"+number).html(boxMP_html[boxMP[number]]);
				$("#movemod"+number).fadeTo("slow", 1);
				
				boxMP_html[boxMP[number-1]]=replaceArrow(boxMP_html[boxMP[number-1]],(number-1),(boxMP.length-1),"");
				$("#movemod"+(number-1)).html(boxMP_html[boxMP[number-1]]);
				$("#movemod"+(number-1)).fadeTo("slow", 1); 

				getsetcookie("hejgrupabox_"+(number-1), boxMP[number-1], 1);
				getsetcookie("hejgrupabox_"+number, boxMP[number], 1);				
			}
			if (updown==1) { 
				boxMP_html[boxMP[number]]=replaceArrow(boxMP_html[boxMP[number]],number,(boxMP.length-1),"");
				$("#movemod"+number).html(boxMP_html[boxMP[number]]);
				$("#movemod"+number).fadeTo("slow", 1);
		
				boxMP_html[boxMP[number+1]]=replaceArrow(boxMP_html[boxMP[number+1]],(number+1),(boxMP.length-1),"");
				$("#movemod"+(number+1)).html(boxMP_html[boxMP[number+1]]);
				$("#movemod"+(number+1)).fadeTo("slow", 1); 
				
				getsetcookie("hejgrupabox_"+(number+1), boxMP[number+1], 1);
				getsetcookie("hejgrupabox_"+number, boxMP[number], 1);				
			}
			

			return true;
			// replace box
//			for (var n = 0; n < boxMP.length; n++) {
//				boxMP_html[boxMP[n]]=replaceArrow(boxMP_html[boxMP[n]],n,(boxMP.length-1),"");
//				$("#movemod"+n).html(boxMP_html[boxMP[n]]);
//				getsetcookie("hejgrupabox_"+n, boxMP[n], 1);
//			}
			
			return true;
		}
		
		// prawa strona
		function moveMainBox2(id,updown) {
		
			// szukamy indeksu
			for (var n = 0; n < boxMP2.length; n++) {
				if (boxMP2[n]==id) {
					number=n; 
					break;
				}
			}			
			if ((number==4 && updown==1) || (number==0 && updown==0)) {return'';}
			if (updown==0) { $("#movemodb"+number).fadeTo("fast", 0.3);$("#movemodb"+(number-1)).fadeTo("fast", 0.3); }
			if (updown==1) { $("#movemodb"+number).fadeTo("fast", 0.3);$("#movemodb"+(number+1)).fadeTo("fast", 0.3); }
			
			
			// update tablicy
			temp1=boxMP2[number];
			if (updown==0) {
				temp2=boxMP2[number-1];
				boxMP2[number-1]=temp1;
			} else if (updown==1) {
				temp2=boxMP2[number+1];
				boxMP2[number+1]=temp1;
			}
			boxMP2[number]=temp2;
			
			if (updown==0) { 
				boxMP_html2[boxMP2[number]]=replaceArrow(boxMP_html2[boxMP2[number]],number,(boxMP2.length-1),"");
				$("#movemodb"+number).html(boxMP_html2[boxMP2[number]]);
				$("#movemodb"+number).fadeTo("slow", 1);
				
				boxMP_html2[boxMP2[number-1]]=replaceArrow(boxMP_html2[boxMP2[number-1]],(number-1),(boxMP2.length-1),"");
				$("#movemodb"+(number-1)).html(boxMP_html2[boxMP2[number-1]]);
				$("#movemodb"+(number-1)).fadeTo("slow", 1); 
				getsetcookie("hejgrupaboxb_"+(number-1), boxMP2[number-1], 1);
				getsetcookie("hejgrupaboxb_"+number, boxMP2[number], 1);				
			}
			if (updown==1) { 
				boxMP_html2[boxMP2[number]]=replaceArrow(boxMP_html2[boxMP2[number]],number,(boxMP2.length-1),"");
				$("#movemodb"+number).html(boxMP_html2[boxMP2[number]]);
				$("#movemodb"+number).fadeTo("slow", 1);
				
				boxMP_html2[boxMP2[number+1]]=replaceArrow(boxMP_html2[boxMP2[number+1]],(number+1),(boxMP2.length-1),"");
				$("#movemodb"+(number+1)).html(boxMP_html2[boxMP2[number+1]]);
				$("#movemodb"+(number+1)).fadeTo("slow", 1); 
				getsetcookie("hejgrupaboxb_"+(number+1), boxMP2[number+1], 1);
				getsetcookie("hejgrupaboxb_"+number, boxMP2[number], 1);				
			}

	
			return true;		
			// replace box
//			for (var n = 0; n < boxMP2.length; n++) {
//				boxMP_html2[boxMP2[n]]=replaceArrow(boxMP_html2[boxMP2[n]],n,(boxMP2.length-1),"");
//				$("#movemodb"+n).html(boxMP_html2[boxMP2[n]]);
//				getsetcookie("hejgrupaboxb_"+n, boxMP2[n], 1);
//			}
//
//			return true;
		}
		
		// lewa strona
		function moveMainBox3(id,updown) {
			
			// szukamy indeksu
			for (var n = 0; n < boxMP3.length; n++) {
				if (boxMP3[n]==id) {
					number=n; 
					break;
				}
			}	

			if ((number==3 && updown==1) || (number==0 && updown==0)) {return'';}
			if (updown==0) { $("#movemodc"+number).fadeTo("fast", 0.3);$("#movemodc"+(number-1)).fadeTo("fast", 0.3); }
			if (updown==1) { $("#movemodc"+number).fadeTo("fast", 0.3);$("#movemodc"+(number+1)).fadeTo("fast", 0.3); }
			
			
			// update tablicy
			temp1=boxMP3[number]; //boxMP3[1]=1 
			if (updown==0) {
				temp2=boxMP3[number-1];
				boxMP3[number-1]=temp1;
			} else if (updown==1) {
				temp2=boxMP3[number+1];
				boxMP3[number+1]=temp1;
			}
			boxMP3[number]=temp2;

			var prefix="";
			
			
			if (updown==0) { 
//				alert(number);
				if (((number-1)==0 && boxMP3[number-1]==0) || (number==(boxMP3.length-1) && boxMP3[number]==0)) { 
					prefix="c"; 
				} else { 
					prefix=""; 
				}
				boxMP_html3[boxMP3[number]]=replaceArrow(boxMP_html3[boxMP3[number]],number,(boxMP3.length-1),prefix);
				$("#movemodc"+number).html(boxMP_html3[boxMP3[number]]);
				$("#movemodc"+number).fadeTo("slow", 1);
				
				boxMP_html3[boxMP3[number-1]]=replaceArrow(boxMP_html3[boxMP3[number-1]],(number-1),(boxMP3.length-1),prefix);
				$("#movemodc"+(number-1)).html(boxMP_html3[boxMP3[number-1]]);
				$("#movemodc"+(number-1)).fadeTo("slow", 1); 
				getsetcookie("hejgrupaboxc_"+(number-1), boxMP3[number-1], 1);
				getsetcookie("hejgrupaboxc_"+number, boxMP3[number], 1);	
							
			}
			if (updown==1) { 

				if ((boxMP3[number+1]==0 && (number+1)==(boxMP3.length-1)) || (boxMP3[number]==0 && number==0)) {
					prefix="c"; 
				} else { 
					prefix=""; 
				}				
//				boxMP3[number]=1 boxMP3[number-1]=2 number=2
				boxMP_html3[boxMP3[number]]=replaceArrow(boxMP_html3[boxMP3[number]],number,(boxMP3.length-1),prefix);
				$("#movemodc"+number).html(boxMP_html3[boxMP3[number]]);
				$("#movemodc"+number).fadeTo("slow", 1);
				
				boxMP_html3[boxMP3[number+1]]=replaceArrow(boxMP_html3[boxMP3[number+1]],(number+1),(boxMP3.length-1),prefix);
				$("#movemodc"+(number+1)).html(boxMP_html3[boxMP3[number+1]]);
				$("#movemodc"+(number+1)).fadeTo("slow", 1); 
				getsetcookie("hejgrupaboxc_"+(number+1), boxMP3[number+1], 1);
				getsetcookie("hejgrupaboxc_"+number, boxMP3[number], 1);
						
			}
			

			return true;			
			// replace box
			var prefix="";
			for (var n = 0; n < boxMP3.length; n++) {
				if ((n==0 && boxMP3[0]==0) || (n==(boxMP3.length-1) && boxMP3[n]==0)) { prefix="c"; } else { prefix=""; }
				boxMP_html3[boxMP3[n]]=replaceArrow(boxMP_html3[boxMP3[n]],n,(boxMP3.length-1),prefix);
				$("#movemodc"+n).html(boxMP_html3[boxMP3[n]]);
				getsetcookie("hejgrupaboxc_"+n, boxMP3[n], 1);
			}

			return true;
		}
		
		function replaceArrow(html,n,max,prefix) {
		
			html=html.replace('header_arrow_down2.gif','header_arrow_down.gif');
			html=html.replace('header_arrow_up2.gif','header_arrow_up.gif');
			html=html.replace('header_arrow_downc2.gif','header_arrow_down.gif');
			html=html.replace('header_arrow_upc2.gif','header_arrow_up.gif');			
			if ((n==0)) {
				html=html.replace('header_arrow_up.gif','header_arrow_up'+prefix+'2.gif');
			} else if (n==max) {
				html=html.replace('header_arrow_down.gif','header_arrow_down'+prefix+'2.gif');
			}
			return html;
		}
		
		var cookie_val;
		function getsetcookie(c_name,value,what) {
			if (what==1) {
				$.cookie(c_name, null);
				return getsetcookie(c_name,value,0);				
			}
			cookie_val=$.cookie(c_name);
			if (cookie_val!=null && cookie_val!="") {
				return cookie_val;
			} else {
				$.cookie(c_name, value, { expires: 365 });
				cookie_val=value;
			}
			return cookie_val;
		}
		
		function setValuInp(id,where) {
			if (where==0) {
				temp=$(id).val();
				$(id).val("");
			} else {
				if ($(id).val()=="") {
					$(id).val(temp);
				}				
			}
		}		
		
		