$(window).load(function() {

   //$("div.komentarze div.naglowekl .tytull").eq(0).css({display:'none'});						//only to right_side
   $("div.komentarze div.zawartoscl").eq(0).css({display:'block'});
   $("div.komentarze").eq(0).addClass('selected');   
   
   $("#formacionList div.komentarze div.naglowekl .tytull").eq(0).css({display:'none'});		//only to right_side 
   $("#formacionList div.komentarze div.zawartoscl").eq(0).css({display:'block'});
	  
   $("div.komentarze div.naglowekl").live('click',function() {
	  $("div.komentarze div.naglowekl .tytull").css({display:'block'});
	  $("div.komentarze div.zawartoscl").css({display:'none'});
	  $("div.komentarze").removeClass('selected');
	  
	  //$(this).parent().find("div.naglowekl .tytull").css({display:'none'});		//only to right_side
      $(this).parent().find("div.zawartoscl").css({display:'block'});
	  $(this).parent().addClass('selected');
   });	  
	  
   $("#formacionList div.komentarze div.naglowekl").live('click',function() {
	  $("div.komentarze div.naglowekl .tytull").css({display:'block'});
	  $("div.komentarze div.zawartoscl").css({display:'none'});
	  $("div.komentarze").removeClass('selected');
	  
	  $(this).parent().find("div.naglowekl .tytull").css({display:'none'});		//only to right_side
      $(this).parent().find("div.zawartoscl").css({display:'block'});
	  $(this).parent().addClass('selected');
   });
   
	$("div.komentarze div.zawartoscl").live('click',function() {
		document.location.href = $(this).children('div').children('.more').children('a').attr('href');
	});

	$("div.nowosci, div.komentarze").live('mouseover',
		function(){ $(this).addClass('activeHover'); }
	);
	
	$("div.nowosci, div.komentarze").live('mouseout',
		function(){$(this).removeClass('activeHover');}
	);
	
	archiwum.putMore();
});

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

archiwum.putMore = function(contenerId) {
	if( contenerId == undefined) contenerId = "";
	else contenerId = "#"+ contenerId;
	$( contenerId +" div.nowosci a").append('<span class="more">más&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[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();
		}
	});
 
	
});

function wykres_link_prev(obj) {}

function wykres_link_next(obj) {
	var sh = obj.parent().parent().parent().children('div.kursLinkDiv:hidden:first');
	var hid = obj.parent().parent().parent().children('div.kursLinkDiv:visible:first');
	sh.show();
	hid.hide();
}

function change_foto(name,diff) {
	$('#obraz'+diff).attr('src', 'http://admin.xtb.es/wykresy/default3/'+ name+'.gif');
	$('#current'+diff).html(name);
}

$().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("287px");
		$(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();
	});	

});


/*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');
}

