$(window).scroll(function(){
	for( var i = 1; i < 5; i++ ) {
		try {
			$("#button_right_"+ i).css("top", $(window).scrollTop()+130+ (200 * (i-1)) +"px");
		}
		catch(e) {}
	}
	for( var i = 1; i < 5; i++ ) {
		try {
			$("#button_left_"+ i).css("top", $(window).scrollTop()+130+ (200 * (i-1)) +"px");
		}
		catch(e) {}
	}	
});
$(window).load(function() {

	//button right
	var visible = new Array();
	var date = new Date();
	date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000));
	
	for( var i = 1; i < 5; i++ ) {
		if( $.cookie("cookie_button_right_state_"+ i) != "hide" ) {
			visible[i] = true;
			$("#button_right_"+ i).animate( { width: "122px" }, 500 );			//pokaż button right
		} else {
			visible[i] = false;
			$("#button_right_"+ i +" .button_right_show").show();				//pokaż przycisk "show"
			$("#button_right_"+ i).fadeTo("fast", .5);
		}
	}
		
	$(".button_right").hover(function() {
		$(this).fadeTo("fast", 1);
	}, function() {
		var id = $(this).attr("id");
		var i = id.substring(id.length - 1);		
		if (!visible[i]) {
			$(this).fadeTo("fast", .5);
		}
	});
	
	$(".button_right_hide").click(function() { 
		$(this).parent().find(".button_right_show").show();
		$(this).parent().animate( { width: "60px" }, 500 );

		var id = $(this).parent().attr("id");
		var i = id.substring(id.length - 1);		
		$.cookie("cookie_button_right_state_"+ i, "hide", {expires: date});			//zapamiętanie w cookies stanu	
		visible[i] = false;
	});

	$(".button_right_show").click(function() { 
		$(this).parent().find(".button_right_show").hide();
		$(this).parent().animate( { width: "122px" }, 500 );
		
		var id = $(this).parent().attr("id");
		var i = id.substring(id.length - 1);		
		$.cookie("cookie_button_right_state_"+ i, "show", {expires: date});			//zapamiętanie w cookies stanu	
		visible[i] = true;
	});

	
	
	
	//button left
	var visible = new Array();
	var date = new Date();
	date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000));
	
	for( var i = 1; i < 5; i++ ) {
		if( $.cookie("cookie_button_left_state_"+ i) != "hide" ) {
			visible[i] = true;
			$("#button_left_"+ i).animate( { left: "0px" }, 500 );					//pokaż button left
			$("#button_left_"+ i +" .button_left_hide").show();
		} else {
			visible[i] = false;
			$("#button_left_"+ i +" .button_left_show").show();						//pokaż przycisk "show"
			$("#button_left_"+ i).fadeTo("fast", .5);
		}
	}
		
	$(".button_left").hover(function() {
		$(this).fadeTo("fast", 1);
	}, function() {
		var id = $(this).attr("id");
		var i = id.substring(id.length - 1);		
		if (!visible[i]) {
			$(this).fadeTo("fast", .5);
		}
	});
	
	$(".button_left_hide").click(function() { 
		$(this).parent().find(".button_left_hide").hide();
		$(this).parent().find(".button_left_show").show();
		$(this).parent().animate( { left: "-60px" }, 500 );
		
		var id = $(this).parent().attr("id");
		var i = id.substring(id.length - 1);		
		$.cookie("cookie_button_left_state_"+ i, "hide", {expires: date});			//zapamiętanie w cookies stanu	
		visible[i] = false;
	});	
		
	$(".button_left_show").click(function() { 
		$(this).parent().find(".button_left_hide").show();
		$(this).parent().find(".button_left_show").hide();
		$(this).parent().animate( { left: "0px" }, 500 );
		
		var id = $(this).parent().attr("id");
		var i = id.substring(id.length - 1);		
		$.cookie("cookie_button_left_state_"+ i, "show", {expires: date});			//zapamiętanie w cookies stanu	
		visible[i] = true;
	});
	
});


$(window).load(function() {

	//leftSide
	$("#leftSide div.box_news_more div.zawartoscl").eq(0).css({display:'block'});
	$("#leftSide div.box_news_more").eq(0).addClass('selected');   	
	$("#leftSide div.box_news_more div.naglowekl").live('click',function() {
		$("#leftSide div.box_news_more div.zawartoscl").css({display:'none'});
		$("#leftSide div.box_news_more").removeClass('selected');
		
		$(this).parent().find("div.zawartoscl").css({display:'block'});
		$(this).parent().addClass('selected');
	});	  

	//rightSide
	$("#rightSide div.box_news_more div.naglowekl .tytull").eq(0).css({display:'none'});
	$("#rightSide div.box_news_more div.zawartoscl").eq(0).css({display:'block'});	
	$("#rightSide div.box_news_more div.naglowekl").live('click',function() {
		$("#rightSide div.box_news_more div.naglowekl .tytull").css({display:'block'});
		$("#rightSide div.box_news_more div.zawartoscl").css({display:'none'});
		$("#rightSide div.box_news_more").removeClass('selected');

		$(this).parent().find("div.naglowekl .tytull").css({display:'none'});
		$(this).parent().find("div.zawartoscl").css({display:'block'});
		$(this).parent().addClass('selected');
	});
   
	$("div.box_news_more div.zawartoscl").live('click',function() {
		document.location.href = $(this).children('div').children('.more').children('a').attr('href');
	});
	
	archiwum.putMore();
});



var archiwum = new Object();
archiwum.ajaxPage = 656;

archiwum.putMore = function(contenerId) {
	if( contenerId == undefined) contenerId = "";
	else contenerId = "#"+ contenerId;
	$( contenerId +" div.box_news a").append('<span class="more">mehr&nbsp;»</span>');
}

archiwum.getPrev = function(contenerId, listId){
	var page = archiwum.incPage(contenerId);
	$.ajax({
		type: "GET",
		url: "strona.php?p="+archiwum.ajaxPage+'&page='+page+'&list='+listId,
		success: function(data) {
			$('#'+contenerId).children('div :not(.archiveLink)').remove();
			$('#'+contenerId).prepend(data);
			archiwum.putMore(contenerId);
			if (data.length < 50) archiwum.decPage(contenerId);
		}
	});
}
 
archiwum.getNext = function(contenerId, listId){
	var page = archiwum.decPage(contenerId);
	$.ajax({
		type: "GET",
		url: "strona.php?p="+archiwum.ajaxPage+'&page='+page+'&list='+listId,
		success: function(data) {
			$('#'+contenerId).children('div :not(.archiveLink)').remove();
			$('#'+contenerId).prepend(data);
			archiwum.putMore(contenerId);			
		}
	});
}

archiwum.incPage = function(contenerId){
	var tid = archiwum.getPage(contenerId);
	tid = tid*1 + 1;
	$('#'+contenerId).children('div.archiveLink').attr('id', contenerId+'_'+tid);
	return tid;
}

archiwum.decPage = function(contenerId){
	var tid = archiwum.getPage(contenerId);
	if (tid >= 1) tid = tid*1 - 1;
	$('#'+contenerId).children('div.archiveLink').attr('id', contenerId+'_'+tid);
	return tid;
}

archiwum.getPage = function(contenerId){
	var tid = $('#'+contenerId).children('div.archiveLink').attr('id').split('_');
	return tid[ tid.length - 1 ];
}



$(document).ready(function(){
    $('div.strzalka span img.prevLink').click(function(){
		var sh = $(this).parent().parent().parent().children('div.kursLinkDiv:hidden:last');
		var hid = $(this).parent().parent().parent().children('div.kursLinkDiv:visible:last');
		hid.hide();
		sh.show();
		});
	$('div.strzalka span img.nextLink').click(function(){
		wykres_link_next($(this))
	});
	
	
	$('div.divek').each(function(){
		$(this).children('div.kursLinkDiv:gt(3)').hide();
		$(this).children('div.strzalka').hide();
		if ($(this).children('div.kursLinkDiv').length <= 1){
			$(this).children('div.strzalka').hide();
		}
	});
 
	
});

$().ready(function() {

	/*header.language_list - slide down / slide up*/
	$('ul#language_list').hover(
		function() {
			$('ul#language_list li').show();
		},
		function() {
			$('ul#language_list li:not(:first)').hide();
		}
	)

	/*header.blackbox - slide down / slide up*/
	$("#right_side_buttons_more").click(function() {
		$("#right_side_buttons").height( $("#right_side_buttons_block").height() );
		$(this).hide();
		$("#right_side_buttons_less").show();
	});

	$("#right_side_buttons_less").click(function() {
		$("#right_side_buttons").height("355px");
		$(this).hide();
		$("#right_side_buttons_more").show();
	});

	$("#right_side_buttons_more div, #right_side_buttons_less div, #right_side_buttons_block .button a").hover(function(){
		$(this).stop().fadeTo("fast", 0);
	}, function(){
		$(this).stop().fadeTo("normal", 1);
	});

	
	/*tooltip*/
	$(".nagLink h1 span").hover(function(){
		$("#"+ $(this).parent().parent().parent().attr("id") +" .main_page_tooltip").show().fadeTo("fast", 1);
	}, function(){
		$("#"+ $(this).parent().parent().parent().attr("id") +" .main_page_tooltip").stop().hide();
	});	

	/*graph changer*/
	$(".wykresy .graph_links .graph_names .graph_name").click(function() {
		var instrument = $(this).html();
		$(this).parent().parent().parent().find(".graph_current").hide();
		$(this).parent().parent().parent().find("#graph"+ instrument).show();
	});
	
});


/*password input changer*/
function changeInputType(oldElement, newElementType, value, blankValue, noFocus) {
	if( !oldElement || !oldElement.parentNode || ( newElementType.length < 4 ) || !document.getElementById || !document.createElement ) return;
	var newElement = document.createElement('span');
	newElement.innerHTML = '<input type="'+ newElementType +'" name="'+ oldElement.name +'">';
	newElement = newElement.firstChild;

	var props = ['name', 'id', 'className', 'size', 'tabIndex', 'accessKey', 'onblur'];
	for( var i = 0, l = props.length; i < l; i++ ) {
		if( oldElement[ props[i] ] ) newElement[ props[i] ] = oldElement[ props[i] ];
	}

	newElement.onfocus = function() { return function() {
		if( this.hasFocus ) return;
		var newElement = changeInputType(this, 'password', value, ( this.value.toLowerCase() == value.toLowerCase() ) ? true : false);
		if( newElement ) newElement.hasFocus = true;
	}}();
	newElement.onblur=function() {return function() {
		if( this.hasFocus ) {
			if( this.value == '' || ( this.value.toLowerCase() == value.toLowerCase() ) ) {
				changeInputType(this, 'text', 'password', false, true);
			}
		}
	}}();	
	
	newElement.hasFocus = false;
	if( !blankValue ) newElement.value = value;
	oldElement.parentNode.replaceChild(newElement, oldElement);
	if( !blankValue ) newElement.value = value;
	if( !noFocus || typeof(noFocus) == 'undefined' ) {
		window.tempElm = newElement;
		setTimeout('tempElm.hasFocus=true; tempElm.focus();', 1);
	}
	return newElement;
}

function checkPasswordDefault(oldElement) {
	if( oldElement.value == 'password' ) changeInputType(oldElement, 'text', 'password');
}

function addToFavorites() {
	var title = document.title;
	var url = document.location;
	if( window.sidebar ) window.sidebar.addPanel(title, url, '');			//Mozilla Firefox
	else if( window.external ) window.external.AddFavorite(url, title);		//IE
}


