// JavaScript Document
$(document).ready(function() { 
    timeout	= 50;
    closetimer	= 0;
    ddmenuitem	= 0;
    // pokaz submenu
    function mopen(id)
    {	
	// wyczysc timer
	mcancelclosetime();

	// zamknij stare (over) submenu i pokaz aktywne
	if(ddmenuitem) 
	{
	    ddmenuitem.removeClass("submenu_over");
	    ddmenuitem.addClass("submenu_hidden");
	    ddmenuzakladka=ddmenuitem.attr("id").substr(8);
	    ddmenuzakladka=$("#m_"+ddmenuzakladka);
	    $(".submenu_active").css("display","block");
	    ddmenuzakladka.removeClass("menu_text_over");
	    ddmenuzakladka.addClass("menu_text");
	}
	$("#m_"+id).removeClass("menu_text");
	$("#m_"+id).addClass("menu_text_over");
	// get new layer and show it
	ddmenuitem = $("#submenu_"+id);
	$("#submenu_"+id).removeClass("submenu_hidden");
	$("#submenu_"+id).addClass("submenu_over");
	$(".submenu_active").css("display","none");
    //ddmenuitem.style.visibility = 'visible';

    }
    // zamknij submenu i  pokaz aktywne
    function mclose()
    {
	if(ddmenuitem) {
	    ddmenuitem.removeClass("submenu_over");
	    ddmenuitem.addClass("submenu_hidden");
	    $(".submenu_active").css("display","block");
	    $.over=$("#menu").find(".menu_text_over");
	    $.over.removeClass("menu_text_over");
	    $.over.addClass("menu_text");
	}
    }
    // ustaw wywolanie funkcji
    function mclosetime()
    {
	closetimer = window.setTimeout(mclose, timeout);
    }
    // usun timer z wywolywaniem funkcji
    function mcancelclosetime()
    {
	if(closetimer)
	{
	    window.clearTimeout(closetimer);
	    closetimer = null;
	}
    }
    $(".menu_text").mouseover(function(){
	$.id_name=$(this).attr("id");
	$.id_name=$.id_name.substr(2);
	mopen($.id_name);
    }).mouseout(function(){
	mclosetime();
    });
    $(".submenu_item").mouseover(function(e){
	mcancelclosetime()
    }).mouseout(function(){
	mclosetime()
    });
    /*box newsletter w artykule*/
    $(".newsletter_input_field").click(function(){
	if ($(this).val()=="wpisz adres e-mail") {
	    $(this).val("");
	}
    });
    /*obsluga wynikow*/
    /*wyniki - wiersze - najazd*/
    $(".wyniki_row").mouseover(function(){		
	$(this).children(".wyniki_row_content").css("background-color","#f9f9f9");
	$(this).children(".wyniki_row_content").children("div").each(function(i,element){
	    $.name_class= $(element).attr("class");
	    if ($.name_class.indexOf("sort")!=-1){
		$(element).css("background-color","#f3f3f3");
	    }
	});
    }).mouseout(function(){
	$(this).children(".wyniki_row_content").css("background-color","transparent");
	/* zaznaczona kolumna */
	$(this).children(".wyniki_row_content").children("div").each(function(i,element){
	    $.name_class= $(element).attr("class");	
	    if ($.name_class.indexOf("sort")!=-1){
		
		$(element).css("background-color","#f9f9f9");
	    }
	});
	/*zaznaczony wiersz*/
	if (($(this).children(".row_check").children("input:checkbox").attr("checked"))){
	    $(this).children(".wyniki_row_content").css("background-color","#f0fafe");//wroc do klikniecia
	}
    });
 
    /*zaznaczanie wierszy*/
    $.max_compare=2;
    $(".row_check").click(function(){       
	$.parentclass=$(this).parents("div:first").attr("class");
	if ($.parentclass=="wyn_row"){
	    $(this).parents("div:first").children(".row_content").css("background-color","#f9f7de");
	}
	else{//wyn_row_first
	    $(this).parents("div:first").children(".row_content_first").css("background-color","#f9f7de");
	}
	if ($(this).children("input:checkbox").attr("checked")){
	    $(this).children("input:checkbox").attr("checked","");
	    if ($.parentclass=="wyn_row"){
		$(this).parents("div:first").children(".row_content").css("background-color","#fff9bd");
	    }
	    else{//wyn_row_first
		$(this).parents("div:first").children(".row_content_first").css("background-color","#fff9bd");
	    }
	    $(this).children("input:checkbox").attr("name",$(this).children("input:checkbox").attr("id"));
	}
	else{
  
	    $(this).children("input:checkbox").attr("checked","true");
  
	}
	for ($.i=0;$.i<$(".row_check input:checkbox:checked").length;$.i++){
	    $(".row_check input:checkbox:checked")[$.i].name="id_oferty"+($.i+1)+"_";
	}
	if ($(".row_check input:checkbox:checked").length==$.max_compare) {
  
	    $('#form_wyniki').submit();
	}
	if ($(".row_check input:checkbox:checked").length>$.max_compare) {
	    alert("Można zaznaczyć tylko " + $.max_compare + " oferty!");
	}   
    });
    $(".row_check input:checkbox").click(function(){
	if ($(this).attr("checked")){
	    $(this).attr("checked","");
	}else{
	    $(this).attr("checked","true");
	}
		
    });
    /* obsluga spisu kalkulatorow */

    $(".kalkulator_head div, .kalkulator_head span, .kalkulator_head img").click(function(){
	$.header=$(this).parents("div:first");//.kalkulator_head
	$.prefix=$.header.attr("id").substr(10);//"KH", "KG",...
	if ($("#kalk_sep_" + $.prefix).attr("class")=="kalk_showed"){//nie widac linkow dla kalkulatore
	    $("#kalk_sep_" + $.prefix).attr("class", "kalk_hidden");//ukryj separator
	    $("#kalk_links_" + $.prefix).attr("class", "kalk_showed");//pokaz linki
	    $.header.find("span:first").html("zwiń");
	    ;//zmien napis z rozwinietego na "zwin"
	    $.header.find("img:first").attr("src","../_img/_templates/opcje_off.png");//obrazek zmien
	}
	else{ //zwijamy linki
	    $("#kalk_sep_" + $.prefix).attr("class", "kalk_showed");//pokaz separator
	    $("#kalk_links_" + $.prefix).attr("class", "kalk_hidden");//ukryj linki
	    $.header.find("span:first").html("rozwiń");
	    ;//zmien napis ze zwinietego na "rozwin"
	    $.header.find("img:first").attr("src","../_img/_templates/opcje_on.png");//obrazek zmien
	}
    /* if ($.header.find("span:first").html()=="zwiń"){
        $.header.find("span:first").html("rozwiń");
     }
     else{
       $.header.find("span:first").html("zwiń");
     }
     */
		
    });
    $(".kalkulator_head div, .kalkulator_head span, .kalkulator_head img").mouseover(function(){		
	$(this).css("text-decoration","underline");
	$(this).css("cursor","pointer");
    }).mouseout(function(){
	$(this).css("text-decoration","none");
	$(this).css("cursor","auto");
    });

    /*przy kredytach hipotecznych ukrycie sumy kredytow konsumpcyjnych*/
    if ($("#szuk_cel_k").val()!=5){
	$("#kkk_item").css("display","none");//ukrycie w formularzu konsolidacji
    }
    /* obsluga formularza wyszukiwania by byl rozwiniety*/  
  
    /*
    if ((document.getElementById("more_option")!=null)&&($("#more_option input:checked").length>0)){
      $(".opcje_z_zwin").find("a:first").html("zwiń");
      $(".opcje_z_ico").find("a:first").find("img:first").attr("src","../_img/_templates/opcje_on.png");
      $("#more_option").css("display","block");
    }*/
    
    $(".opcje_z_ico").click(function(){
	if ($("#more_option").css("display")=="none")//wylaczone
	{ 
	    $(this).find("a:first").find("img:first").attr("src","../_img/_templates/opcje_on.png");
	    $(".opcje_z_zwin a:first").html("zwiń");
	    $("#more_option").css("display","block");
	}
	else
	{
	    $(this).find("a:first").find("img:first").attr("src","../_img/_templates/opcje_off.png");
	    $(".opcje_z_zwin a:first").html("rozwiń");
	    $("#more_option").css("display","none");
	}
    });
    $(".opcje_z_zwin").click(function(){
	if ($("#more_option").css("display")=="none")//wylaczone
	{ 
	    $(".opcje_z_ico").find("a:first").find("img:first").attr("src","../_img/_templates/opcje_on.png");
	    $(this).find("a:first").html("zwiń");
	    $("#more_option").css("display","block");
	}
	else
	{
	    $(".opcje_z_ico").find("a:first").find("img:first").attr("src","../_img/_templates/opcje_off.png");
	    $(this).find("a:first").html("rozwiń");
	    $("#more_option").css("display","none");
	}
    });
    
    
    /* -- obsluga pytajnikow ---------*/
    $(".pytajnik").mouseover(
	function()
	{
	    of = $(this).offset();
	    $("#chmurka").css("left", of.left + 7);
	    idp = $(this).attr("name");
	    $.get("/ajax/pytajnik.php", 
	    {
		id: idp
	    }, 
	    function(data)
	    {
		//$("#chmurka .m").html("");
		$("#chmurka .chmurka_content").html(data);
		$("#chmurka").css("top", of.top - $("#chmurka").height() - 3);
	    }
	    );			
	    $("#chmurka").show();	
	}
	);
    $(".pytajnik").mouseout(
	function()
	{
	    $("#chmurka").hide();
	}
	);
    /* -- obsluga pytajnikow 2 - ogonek w druga strone---------*/
    $(".pytajnik2").mouseover(
	function()
	{
	    of = $(this).offset();
	    $("#chmurka2").css("left", of.left - $("#chmurka2").width() + 7);
	    idp = $(this).attr("name");
	    $.get("/ajax/pytajnik.php", 
	    {
		id: idp
	    }, 
	    function(data)
	    {
		//$("#chmurka .m").html("");
		$("#chmurka2 .chmurka_content").html(data);
		$("#chmurka2").css("top", of.top - $("#chmurka2").height() - 3);
	    }
	    );			
	    $("#chmurka2").show();	
	}
	);
    $(".pytajnik2").mouseout(
	function()
	{
	    $("#chmurka2").hide();
	}
	);
    /*najazd na schowe*/
    $(".schowek_add").mouseover(function(){
	$("#chmurka .chmurka_content").html("Dodaj ofertę do schowka");
	$.of = $(this).offset();
	$("#chmurka").css("left", $.of.left + 7);
	$("#chmurka").css("top", $.of.top - $("#chmurka").height() - 3);
	$("#chmurka").show();
    }).mouseout(function(){
	$("#chmurka").hide();
    });
    $(".schowek_rem").mouseover(function(){
	$("#chmurka .chmurka_content").html("Usuń ofertę ze schowka");
	$.of = $(this).offset();
	$("#chmurka").css("left", $.of.left + 7);
	$("#chmurka").css("top", $.of.top - $("#chmurka").height() - 3);
	$("#chmurka").show();
    }).mouseout(function(){
	$("#chmurka").hide();
    });
    /*------------------------------OBSLUGA FORUM W SZCZEGOLE PRODUKTU i Artykule ------------*/
    $(".dodaj_watek_text").mouseover(function(){
	$(this).css("cursor","pointer");
	$(this).find("span:first").css("text-decoration","underline");
    }).mouseout(function(){
	$(this).css("cursor","auto");
	$(this).find("span:first").css("text-decoration","none");
       	
    });
    $(".button_dodaj_watek").mouseover(function(){
	$(this).css("cursor","pointer");
    }).mouseout(function(){
	$(this).css("cursor","auto");         	
    });
    $(".button_dodaj_watek, .dodaj_watek_text, #komentuj_art_link").click(

	function()
	{
	    $("#forum_brak_kom_info").hide();//ukryj info ze nie bylo watkow
	    $(".form_odp_odp").each(function(i,element){
		$(element).hide()
	    });//ukryj formularze odpowiadania
	    $("#form_odp_main").show();//pokaz formularz dodawania nowego watku			
	}
	);
    /* obsluga forum */
    $(".forum_odpowiedz,.forum_comment_sign, .forum_show_all").mouseover(function(){
	$(this).css("cursor","pointer");
    }).mouseout(function(){
	$(this).css("cursor","auto");
    });
    /* pokaz odpowiedzi do komentarza - forum pod produktem*/
    $(".forum_comment_sign").click(function(){
	$.myNode=$(this).parents('div:first').parents('div:first').find(".forum_subcomments");
	if ($.myNode.css("display")=="none"){
	    $.myNode.css("display","block");
	    $(this).parents('div:first').find(".forum_comment_full").show();
	    $(this).parents('div:first').find(".forum_comment_short").hide();
	    $(this).children("img:first").attr("src","../_img/_templates/blue_standard_minus.png");
	}
	else{
	    $.myNode.css("display","none");
	    $(this).parents('div:first').find(".forum_comment_full").hide();
	    $(this).parents('div:first').find(".forum_comment_short").show();
	    $(this).children("img:first").attr("src","../_img/_templates/blue_standard_plus.png");
	}
    });
    /* pokaz wszystkie - forum pod produktem*/
    $(".forum_show_all").click(function(){
	if ($(".forum_show_all span").html().indexOf("ukryj")>=0){
	    $(".forum_show_all span").html(" pokaż wszystkie komentarze");
	    $(".forum_subcomments").hide();
	    $(".forum_comment .forum_comment_full").hide();
	    $(".forum_comment .forum_comment_short").show();
	    $(".forum_comment_sign img").attr("src","../_img/_templates/blue_standard_plus.png");
	}
	else{
	    $(".forum_comment .forum_comment_full").show();
	    $(".forum_comment .forum_comment_short").hide();
	    $(".forum_show_all span").html(" ukryj wszystkie komentarze");
	    $(".forum_subcomments").show();
	    $(".forum_comment_sign img").attr("src","../_img/_templates/blue_standard_minus.png");
	}
    });
    //wywolanie aby uzupelnic obrazki
    $.ajax({ 
	type: "GET",
	url: "../_img/obrazek_refresh.php",
	async: false,
	success: function(data){
	    $(".f_odp_obrazek_aut").each(function(i,element){
		$(element).children("img:first").attr("src",data);
	    });
	    $("#kod_obrazek").attr("src",data);//uzupelnij przy newsletterze
	}
    }); 
    //najazd na refresha
    $(".refresh_obrazek").mouseover(function(){
	
	$(this).css("cursor","pointer");
    }).mouseout(function(){

	$(this).css("cursor","auto");
    });
    //przeladowanie obrazka
    $(".refresh_obrazek").click(
	function()
	{
	    $.ajax({
		type: "GET",
		url: "../_img/obrazek_refresh.php",
		async: false,
		success: function(data){
		    $(".f_odp_obrazek_aut").each(function(i,element){
			$(element).children("img:first").attr("src",data);
		    });
		}
	    });
           

	}
	);
    $("#form_odp_main form ,.form_odp_odp form").submit(
	function()
	{
		
	    val = true;
	    $.text = '';
	    if( $(this).find("input[name='odp_autor']").val() == '')
	    {
		$.text += 'Pole AUTOR jest puste. \n';
		val = false;
	    }
	    if( $(this).find("input[name='odp_tytul']").val() == '')
	    {
		$.text += 'Pole TYTUŁ jest puste. \n';
		val = false;
	    }
	    if( $(this).find("textarea[name='odp_komentarz']").val() == '')
	    {
		$.text += 'Pole KOMENTARZ jest puste. \n';
		val = false;
	    }
	    if( $(this).find("input[name='odp_obrazek']").val() == '')
	    {
		$.text += 'Pole KOD jest puste. \n';
		val = false;
	    }
	    else
	    {//sprawdz czy kod z obrazka sie zgadza
		//sprawdz czy kod z obrazka sie zgadza
		//wywoluje ajaxa - synchronicznie (async:false),metoda get dla pliku check_captcha przekazuje kod z obraza
		$.ajax({
		    type: "GET",
		    url: "../_inc/check_captcha.php",
		    data: ({
			captcha_val:$(this).find("input[name='odp_obrazek']").val()
		    }),
		    async: false,
		    success: function(data){
			if(data=="-1"){
			    $.text += 'Wpisz poprawny kod.\n';
			    val = false;
			}
		    }
		});
            
	    }
	    if(!val)
	    {
		alert($.text);
	    }
	    return val;	
			
			
	}
	); 
		
    $(".button_odpowiedz input").mouseover(function(){
	$(this).css("cursor","pointer");
    }).mouseout(function(){
	$(this).css("cursor","auto");
    });		
    $(".forum_odpowiedz").mouseover(function(){
	$(this).css("cursor","pointer");
	$(this).find("span:first").css("text-decoration","underline");
    }).mouseout(function(){
	$(this).css("cursor","auto");
	$(this).find("span:first").css("text-decoration","none");
    });
    
    $(".forum_odpowiedz").click(
	function()
	{ 
	    $.hide_it=false; //czy nalezy ukryc bo teraz klikanie odpowiedz powoduje chowanie
	    //ukryj wszystkie formularze odpowiedzi
	    $(".form_odp_odp").each(function(i,element){
        
		if ($(element).is(":visible")) {
		    $.hide_it=true;
		    $.hidden_el=$(element)
		}
		$(element).hide();
	    });
	    $(this).parents("div:first").parents("div:first").find(".form_odp_odp").show();//pokaz odpowiedni formularz
	    $("#form_odp_main").hide();//ukryj formularz od dodawania nowego watku
	    //i na koncu ukryj jesli taka potrzeba
	    if ($.hide_it) {
		$.hidden_el.hide();
	    }
	}
	);
    $(".form_odp_main_close span").mouseover(function(){
	$(this).css("cursor","pointer");
	$(this).css("text-decoration","underline");
    }).mouseout(function(){
	$(this).css("cursor","auto");
	$(this).css("text-decoration","none");
    });
    $(".form_odp_main_close img").mouseover(function(){
	$(this).css("cursor","pointer");
    }).mouseout(function(){
	$(this).css("cursor","auto");
    });
    
    
    $(".form_odp_main_close span, .form_odp_main_close img").click(
	function()
	{
	    $(this).parents("div:first").parents("div:first").parents("div:first").hide();//schowaj formularz
	}
	);

	   
	   
	   
    $.limit_kom=2000;
    $(".f_odp_field textarea").keyup(function(){

	$.text = $(this).val(); 
	$.textlength = $.text.length;
	if($.textlength > $.limit_kom)
	{
	    alert('Maksymalna długosc komentrza wynosi ' +$.limit_kom+ ' znaków');
	    $(this).val($.text.substr(0,$.limit_kom));
	}
    });
    $.limit_tyt=120;
    $(".f_odp_field .f_odp_tytul").keyup(function(){

	$.text = $(this).val(); 
	$.textlength = $.text.length;
	if($.textlength > $.limit_tyt)
	{
	    alert('Maksymalna długosc tytulu wynosi ' +$.limit_tyt+ ' znaków');
	    $(this).val($.text.substr(0,$.limit_tyt));
	}
    });
    $.limit_aut=12;
    $(".f_odp_field .f_odp_autor").keyup(function(){
	$.text = $(this).val(); 
	$.textlength = $.text.length;
	if($.textlength > $.limit_aut)
	{
	    alert('Maksymalna długosc tytulu wynosi ' +$.limit_aut+ ' znaków');
	    $(this).val($.text.substr(0,$.limit_aut));
	}
    });
	   
	   
	   
	   
    /*----------------kredyty samochodowe---------------------*/
    $("#szuk_marka_").click(function(){
	if ($(this).attr("checked")){
	    $("#form_item_marki").css("display","block");
	}
	else{
	    $("#form_item_marki").css("display","none");
	}
    });
      
    /*obsluga pomoc - przy wynikach p=2 */
    $(".row_pomoc").mouseover(function(){
	$(this).css("cursor","pointer");
    }).mouseout(function(){
	$(this).css("cursor","auto");
    });
    $(".row_pomoc").click(function(){
	$("#doradca_pomoc_box_div").css("left",($(this).offset().left));
	$("#doradca_pomoc_box_div").css("top",($(this).offset().top-100));
	$("#doradca_pomoc_regulamin_dane").css("left",($(this).offset().left+10));
	$("#doradca_pomoc_regulamin_dane").css("top",($(this).offset().top-90));
	$("#doradca_pomoc_regulamin_produkty").css("left",($(this).offset().left+20));
	$("#doradca_pomoc_regulamin_produkty").css("top",($(this).offset().top-80));
    });
    $(".rysuj_wykres").mouseover(function(){
	$(this).css("cursor","pointer");
    }).mouseout(function(){
	$(this).css("cursor","auto");
    });
    $(".rysuj_wykres").click(function(){
	$.liczba_funduszy=0;
	$.liczba_walut=0;
	$.liczba_gield=0;
	$(".checkbox_fundusz").each(function(i,element){
	    if ($(element).attr("checked")){
		$.liczba_funduszy+=1;
	    }
	});
	if ($.liczba_funduszy==0){
	    alert("Proszę wybrać przynajmniej jeden fundusz");

	} 
	$(".checkbox_waluta").each(function(i,element){
	    if ($(element).attr("checked")){
		$.liczba_walut+=1;
	    }
	});
	$(".checkbox_gielda").each(function(i,element){
	    if ($(element).attr("checked")){
		$.liczba_gield+=1;
	    }
	});
	if( ($.liczba_funduszy+$.liczba_walut+$.liczba_gield) >10){
	    alert("Możesz wybrać łącznie maksymalnie dziesięć funduszy, walut oraz indeksów giełdowych");
	}
	else{      
	    document.getElementById('p_action').value=3;
	    document.getElementById('form_wyniki').submit();
	}
    });      
    $(".rysuj_wykres").mouseover(function(){
	$("#chmurka .chmurka_content").html("Aby porównać hisotryczne wyniki funduszy, zaznacz poniżej te, które Cię interesują, a następnie kliknij w ikonę 'Rysuj wykres'.<br /><br />Dodatkowo możesz porównać wybrane fundusze z walutami lub indexami giełdowymi (opcja dostępna pod wynikami wyszukiwania)");
	$.of = $(this).offset();
	$("#chmurka").css("left", $.of.left + 7);
	$("#chmurka").css("top", $.of.top - $("#chmurka").height() - 3);
	$("#chmurka").show();
    }).mouseout(function(){
	$("#chmurka").hide();
    }); 
    
    /*------------polec newsletter -------------*/
    $(".nl_refresh_obrazek").mouseover(function () {
	$(this).css("cursor","pointer");
    }).mouseout(function(){
	$(this).css("cursor", "auto");
    });
    //przeladowanie obrazka w newsletterze - polec znajomemu
    $(".nl_refresh_obrazek").click(
	function(){
	    $.ajax({
		type: "GET",
		url: "../_img/obrazek_refresh.php",
		async: false,
		success: function(data){
		    $("#kod_obrazek").attr("src",data);
		}
	    });
	}
	);
    
    /*---------------do sitemapy-------------*/
    $(".sitemap_ico").mouseover(function () {
	$(this).css("cursor","pointer");
    }).mouseout(function(){
	$(this).css("cursor", "auto");
    });
    
    /*---------------szukanie na stronie glownej-------------*/
    $(".menu_search_link").mouseover(function () {
	$(this).css("cursor","pointer");
    }).mouseout(function(){
	$(this).css("cursor", "auto");
    });
    
    /*konta bankowe */
    $(".link_plus, .link_minus").mouseover(function(){
	$(this).css("cursor","pointer");
 
    }).mouseout(function(){
	$(this).css("cursor", "auto");
    });
    
    /*------------------------box waluty i stopy ----------------------------*/
    $("#waluty ul li span, li.spread, #stopa_pln, #stopa_eur").mouseover(function(){		
	$(this).css("cursor","pointer");
    }).mouseout(function(){
	$(this).css("cursor","auto");
    });
    
    /*$("#kursy_walut, #stopy_procentowe").mouseover(function(){		

	$(this).css("cursor","pointer");
	$(this).css("text-decoration","underline");
	}).mouseout(function(){
  if (($(this).attr("id")=="kursy_walut") && ($("#stopy_procentowe").css("text-decoration")=="underline"))
  {
    $(this).css("text-decoration","none");
  }
  else if (($(this).attr("id")=="stopy_procentowe") && ($("#kursy_walut").css("text-decoration")=="underline"))
  {
    $(this).css("text-decoration","none");
  }
	$(this).css("cursor","auto");
  });
  */
    /*klikniecie waluty w menu boxa*/
    $("#kursy_walut").click(function(){
	if ($("#stopy_procentowe").css("text-decoration")=="underline")
	{
  
	    $.get("/ajax/box_waluty_i_stopy_ajax_wykres.php", 
	    {
		akcja: 3
	    },
	    function(data)
	    {			
		$("#kurs_z_dnia").html("aktualne kursy NBP z " + data);
	    });
	    $(this).css("text-decoration","underline");    
	    typ=jQuery.trim($("#ul_waluty").find(".waluta_active").text()) ;
	    $("#stopy_procentowe").css("text-decoration","none");
	    $.get("/ajax/box_waluty_i_stopy_ajax_wykres.php", 
	    {
		akcja: 1,
		wal: typ
	    },
	    function(data)
	    {			
		$("#ul_waluty").css("display","block");
		$("#ul_stopy").css("display","none");
		$("#box_white_walutyy_waluty").css("display","block");
		$("#box_white_walutyy_stopy").css("display","none");
		$("#waluty_graph_y_label").html("[PLN]");
		if (typ=='SPREAD'){
		    g = new Dygraph(document.getElementById('waluty_graph'), data,{
			colors:['#08A6E2','#C81036','#00AD39'],
			fillGraph:false,
			labelsDiv:document.getElementById('waluty_graph_label'),
			axisLabelFontSize:12  
		    });
		}
		else{
		    g = new Dygraph(document.getElementById('waluty_graph'), data,{
			colors:['#08A6E2'],
			fillGraph:true,
			labelsDiv:document.getElementById('waluty_graph_label'),
			axisLabelFontSize:12  
		    });
		}	      	
	    });
	}
    });
    /*klikniecie menu stopy procentowe*/
    $("#stopy_procentowe").click(function(){
	if ($("#kursy_walut").css("text-decoration")=="underline")
	{
	    $.get("/ajax/box_waluty_i_stopy_ajax_wykres.php", 
	    {
		akcja: 4
	    },
	    function(data)
	    {			
		$("#kurs_z_dnia").html("z dnia " + data);
	    });
	    var typ = jQuery.trim($("#ul_stopy").find(".waluta_active").text());	
	    if (typ=='WIBOR') {
		typ='PLN';
	    }
	    else if (typ=='EURIBOR') {
		typ='EUR';
	    }
	    $("#stopy_procentowe").css("text-decoration","underline");
	    $("#kursy_walut").css("text-decoration","none");
	    $.get("/ajax/box_waluty_i_stopy_ajax_wykres.php", 
	    {
		akcja: 2,
		wal: typ
	    },
	    function(data)
	    {			
				
		$("#ul_waluty").css("display","none");
		$("#ul_stopy").css("display","block");
		$("#box_white_walutyy_stopy").css("display","block");
		$("#box_white_walutyy_waluty").css("display","none");
		$("#waluty_graph_y_label").html("[%]");
		g = new Dygraph(document.getElementById('waluty_graph'), data,{
		    colors:['#08A6E2'],
		    fillGraph:true,
		    labelsDiv:document.getElementById('waluty_graph_label'),
		    axisLabelFontSize:12  
		});
	    }
	    );	
     
	}
    });
  
    /*klikniecie w walute EUR,CHF,USD - pokazanie wykresu*/
    $("#waluta_eur, #waluta_chf, #waluta_usd, #waluta_gbp").click(function(){
	var typ = $(this).text();
	$.get("/ajax/box_waluty_i_stopy_ajax_wykres.php", 
	{
	    akcja: 1,
	    wal: typ
	}, 
	function(data)
	{
	    $("#ul_waluty span.waluta_active").each(function(i,element){
		$(element).removeClass("waluta_active")
	    });//ukryj formularze odpowiadania
	    $("#waluta_spread").removeClass("waluta_active");
	    $("#spread_link_contener").css("background-color","");
	    $("#waluta_"+typ.toLowerCase()).addClass("waluta_active");
	    $("#waluty_graph_y_label").html("[PLN]");
	    g = new Dygraph(document.getElementById('waluty_graph'), data,{
		colors:['#08A6E2'],
		fillGraph:true,
		labelsDiv:document.getElementById('waluty_graph_label'),
		axisLabelFontSize:12  
	    });
	}
	);	
    });
    /*klikniecie wibor/libor/euribor - pokaz odpowiednie wykresy*/
    $("#stopa_eur, #stopa_chf, #stopa_usd, #stopa_pln").click(function(){
	var typ = jQuery.trim($(this).text());
	if (typ=='WIBOR') {
	    typ='PLN';
	}
	else if (typ=='EURIBOR') {
	    typ='EUR';
	}
	$.get("/ajax/box_waluty_i_stopy_ajax_wykres.php", 
	{
	    akcja: 2,
	    wal: typ
	}, 
	function(data)
	{
	    $("#ul_stopy span.waluta_active").each(function(i,element){
		$(element).removeClass("waluta_active")
	    });//ukryj formularze odpowiadania
	    $("#stopa_"+typ.toLowerCase()).addClass("waluta_active");
	    $("#waluty_graph_y_label").html("[%]");
	    g = new Dygraph(document.getElementById('waluty_graph'), data,{
		colors:['#08A6E2'],
		fillGraph:true,
		labelsDiv:document.getElementById('waluty_graph_label'),
		axisLabelFontSize:12  
	    });
	}
	);	
    });
    /* po klinieciu w spread pokaz wykres spreadu*/ 
    $("#waluta_spread").click(function(){
	var typ = $(this).text();
	$.get("/ajax/box_waluty_i_stopy_ajax_wykres.php", 
	{
	    akcja: 1,
	    wal: typ
	}, 
	function(data)
	{  
	    $("#ul_waluty span.waluta_active").each(function(i,element){
		$(element).removeClass("waluta_active")
	    });//ukryj formularze odpowiadania
              
	    $("#waluta_spread").addClass("waluta_active");
	    $("#spread_link_contener").css("background-color","#eadf63");
              
	    g = new Dygraph(document.getElementById('waluty_graph'), data,{
		colors:['#08A6E2','#C81036','#00AD39'],
		fillGraph:false,
		labelsDiv:document.getElementById('waluty_graph_label'),
		axisLabelFontSize:12  
	    });
	}
	);	
    });
  
    //FACEBOOK
    $('.facebook_zakladka').each(function () {
	var distance = 250;
	var time = 350;
	var hideDelay = 700;
	var hideDelayTimer = null;
	var beingShown = false;
	var shown = false;
	var trigger = $('.fb_wyzwalacz', this);
	var popup = $('.fb_pasek', this).css('opacity', 0);

	$([trigger.get(0), popup.get(0)]).mouseover(function () {
     
	    if (hideDelayTimer) clearTimeout(hideDelayTimer);

     
	    if (beingShown || shown) {
		return;
	    } else {
		beingShown = true;

      
		popup.css({
		    top: -10,
		    left: 0,
		    display: 'block' 
		})

      
		.animate({
		    left: '-=' + distance + 'px',
		    opacity: 1
		}, time, 'swing', function() {
         
		    beingShown = false;
		    shown = true;
		});
	    }
	}).mouseout(function () {
      
	    if (hideDelayTimer) clearTimeout(hideDelayTimer);
      
      
	    hideDelayTimer = setTimeout(function () {
		hideDelayTimer = null;
		popup.animate({
		    left: '+=' + distance + 'px',
		    opacity: 0
		}, time, 'swing', function () {
         
		    shown = false;
          
		    popup.css('display', 'none');
		});
	    }, hideDelay);
	});
    }); 
  
  
    /* przelaczanie kart mega artu*/
    $('div#centrum_wiedzy_mega_art div#centrum_wiedzy_kroki div.step_by_step_head a').click(function(){
	var id_basic = $('div#centrum_wiedzy_kroki div.step_by_step_content input:hidden[name=id_basic]').val(); //pobranie id boksu
	var page = $(this).text(); //pobranie numeru strony
	page--;
	$('#centrum_wiedzy_mega_art .step_by_step_content').animate({
	    opacity: 0
	}, 250, function() {
	    $('#centrum_wiedzy_mega_art').load('../_inc/centrum_wiedzy_mega_art.php?&id_basic=' + id_basic + '&page=' + page); //wykonanie akcji i zaladowanie nowego wygladu
	});  
    });
    
    /*ustawienie pierwszej kuli w arcie */
    //$('div#centrum_wiedzy_mega_art .centrum_wiedzy_tematy_linki').css({"display":"none"}); //ukrycie wszystkich zakladek
    //$('div#centrum_wiedzy_mega_art .centrum_wiedzy_tematy_linki:first').css({"display":"block"}); //odsloniecie pierwszej zakladki
    $('div#centrum_wiedzy_mega_art .centrum_wiedzy_tematy_title[display!=none] img:first').attr('src', '../_img/_templates/opcje_off.png'); //znikniecie strzalki rozwijajacej
    	
    $('div#centrum_wiedzy_mega_art .centrum_wiedzy_tematy_title').click(function() { //akcja wykonywana przy kliknieciu w przycisk
	/*ustalenie czy zakladka jest rozwinieta czy zwinieta*/
	var szerokosc=$(this).children('img').attr('src');
	if(szerokosc=='../_img/_templates/opcje_off.png')
	{
	    $(this).children('img').attr('src', '../_img/_templates/opcje_on.png'); //pokazanie strzalki
	    $(this).next('.centrum_wiedzy_tematy_linki').toggle("fast") //szybkie zwiniecie
	}
	else
	{
	    $(this).children('img').attr('src', '../_img/_templates/opcje_off.png'); //znikniecie strzalki
	    $(this).next('.centrum_wiedzy_tematy_linki').toggle("normal") //normalne zwiniecie
	}
    });
  
    //rodzina na swoim produkt 
    /* maksymalna wielkosc nieruchomosci */
  
    $(".form_item_field2 select[id=przedmiot_rns_]").change(function(){
	wartosc = $(this).val();
	if(wartosc == 1)
	{
	    $("#max_metraz").text("(max 75m)");
	}
	else if(wartosc == 2)
	{
	    $("#max_metraz").text("(max 140m)");
	}
    });
    /* zakup lub budowa domu */
  
    $(".form_item_field select[id=typ_rns_]").change(function(){

	wartosc = $(this).val();
	if(wartosc == 1)  {  
	    $("#przedmiot_item").css("display","block");
	    if ($(".form_item_field2 select[id=przedmiot_rns_]").val()==1)//mieszkanie
	    {
		$("#max_metraz").text("(max 75m)");
	    }
	    else
	    {
		$("#max_metraz").text("(max 140m)");
	    }
	}

	else if(wartosc == 4){
	    $("#przedmiot_item").css("display","none");
	    $("#max_metraz").text("(max 140m)");
	}
    });

    /*obliczenie maxymelnego okresu kredytu na podstawie wieku*/
 
    $("#wiek_rns_").change(function(){
	wartosc = $(this).val();
	wartosc = 75 - wartosc;
	wartosc = "(max "+ wartosc+" lat)";
	$("#max_okres").text(wartosc);
    });
    /*nazwy miast*/
    $("#wojewodztwo_rns_").change(function(){
	wartosc = $(this).val();
	$("#miasto_rns_").load('../rodzina_na_swoim/rodzina_na_swoim_ajax.php?&action=1&woj=' + wartosc);
	$.get('../rodzina_na_swoim/rodzina_na_swoim_ajax.php', {
	    action: '2', 
	    miasto: $("#miasto_rns_").val()
	}, function(data) {
	    // data contains the response
	    $("#max_val_metr_").val(data);
	}); 

    });
    $("#miasto_rns_").change(function(){
	$.get('../rodzina_na_swoim/rodzina_na_swoim_ajax.php', {
	    action: '2', 
	    miasto: $("#miasto_rns_").val()
	}, function(data) {
	    // data contains the response
	    $("#max_val_metr_").val(data);
	}); 
    }); 
 
 
  
}
); 
/*function switchImageMenuItem(img, turn)
{
    if (turn)
	img.attr('src', img.attr('src') + '&color=707476');
    else
    {
	var src = img.attr('src');
	if (src && src.indexOf('&color=') > -1)
	    src = src.substring(0, src.indexOf('&color='));
	img.attr('src', src);
    }
}
*/

function switchImageMenuItem(img, turn)
{
    var url = img.attr('src');
    if (url != null)
    {
	var extension = url.split('.').pop();
	var urlFile = url.substr(0, url.length-extension.length-1);
	if (urlFile.substr(urlFile.length - 5) == '_over' && !turn)
	{
	    urlFile = urlFile.substr(0, urlFile.length - 5);
	}
	else if (urlFile.substr(urlFile.length - 5) != '_over' && turn)
	{
	    urlFile += '_over';
	}
	urlFile += '.' + extension;
	img.attr('src', urlFile);
    }
}
$(function(){
    $("img", ".menu_text").each(function(){
	// cache grafik
	var img = $(this);
	var url = img.attr('src');
	var extension = url.split('.').pop();
	var urlFile = url.substr(0, url.length-extension.length-1);
	if (urlFile.substr(urlFile.length - 5) == '_over')
	{
	    urlFile = urlFile.substr(0, urlFile.length - 5);
	}
	else if (urlFile.substr(urlFile.length - 5) != '_over')
	{
	    urlFile += '_over';
	}
	urlFile += '.' + extension;
	$("body").append("<img src=\"" + urlFile + "\" id=\"temp_img\" style=\"display: none;\" />");
	$("#temp_img").remove();
    });
    $(".menu_text").hover(function(){
	var img = $("img", this);
	switchImageMenuItem(img, true);
    }, function(){
	var img = $("img", this);
	switchImageMenuItem(img, false);
    });
    $(".submenu_item").not(".submenu_active").hover(function(){
	var id = $(this).attr('id').substr($(this).attr('id').indexOf('_')+1);
	//alert("ID: " + id);
	var img = $("img", "#m_" + id);
	switchImageMenuItem(img, true);
    }, function(){
	var id = $(this).attr('id').substr($(this).attr('id').indexOf('_')+1);
	var img = $("img", "#m_" + id);
	switchImageMenuItem(img, false);
    });
    $(".menu_text_active").each(function(){
	switchImageMenuItem($("img", this), true);
    });
    
    $("img.over_add_u").each(function(){
	var img = $(this);
	var url = img.attr('src');
	var extension = url.split('.').pop();
	var urlFile = url.substr(0, url.length-extension.length-1);
	urlFile += '_u';
	urlFile += '.' + extension;
	$("body").append("<img src=\"" + urlFile + "\" id=\"temp_img\" style=\"display: none;\" />");
	$("#temp_img").remove();
	img.hover(function(){
	    img.attr('src', urlFile);
	}, function(){
	    img.attr('src', url);
	})
    });
    
    $("img[src='../images/details.png']").hover(function(){
	$(this).attr('src', '../images/details_u.png');
    }, function(){
	$(this).attr('src', '../images/details.png');
    });
    
    // rozwijalny opis nad wynikami wyszukiwania.
    $("span.dots", ".wyniki_opis").text('...');
    
    $("span.expand", ".wyniki_opis_wrapper").click(function(){
	var defHeight = 30; // domyślna wysokość css elementu opisu.
	
	var opis = $(".wyniki_opis", $(this).parents(".wyniki_opis_wrapper"));
	var dots = $(".dots", opis);
	var maxHeight = opis.prop('scrollHeight') - 20; // odjęcie marginesu ostatniego p

	var newExpandLabel = (opis.height() == defHeight ? 'zwiń' : 'rozwiń');
	opis.animate({
	    'height' : (opis.height() == defHeight ? maxHeight : defHeight)
	});
	$(this).text(newExpandLabel);
	if (opis.height() == defHeight)
	{
	    dots.fadeOut();
	    $(this).addClass('collapse');
	}
	else
	{
	    dots.fadeIn();
	    $(this).removeClass('collapse');
	}
    });
});

