$(document).ready(function(){
  $(".lightbox").lightbox();
if($.cookie('aktualnosci')=='null' || $.cookie('aktualnosci')==1)
{
  //alert($.cookie('aktualnosci'));
}
if($.cookie('aktualnosci')==2)
{
  //alert($.cookie('aktualnosci'));
  $("#tresc_lewa").width(10);
  $("#tresc_prawa").width(680);
  $("#tresc_lewa a").animate( {opacity: "0"}, { queue:false, duration:10 } );
  $("#tresc_lewa div.tresc").animate( {opacity: "0"}, { queue:false, duration:10 } );
  $("#rozwin").animate( {opacity: "100"}, { queue:false, duration:500 } );
  $("#rozwin").show();
}
$("#zwin").click(function(){
      /* $("#tresc_lewa").animate( { width:"0" }, { queue:false, duration:500 } ) */
      /* $("#tresc_lewa").animate({
      "width": "toggle", "opacity": "toggle"
    }, { duration: 500 }); */
    $("#tresc_lewa a").animate( {opacity: "0"}, { queue:true, duration:500 } );
    $("#tresc_lewa").animate( {opacity: "100", width:"10px"}, { queue:true, duration:500 } );
    $("#tresc_lewa div.tresc").animate( {opacity: "0"}, { queue:true, duration:500 } );
    //$("#tresc_lewa div.tresc").animate( {opacity: 0,margin:"0px"}, { queue:true, duration:500 } );
    //$("#tresc_lewa div.tresc").animate( {opacity: 100}, { queue:true, duration:500 } );
    $("#rozwin").animate( {opacity: "100"}, { queue:true, duration:500 } );
    $("#rozwin").show();
    $("#tresc_prawa").animate( { width:"680px" }, { queue:true, duration:500 } );
    $.cookie('aktualnosci', 2);
    return false;
    });


$("#rozwin").click(function(){


    $("#tresc_lewa").animate( {"opacity": "0"}, { queue:true, duration:1 } );
    $("#tresc_prawa").animate( { "width": "460px" }, { queue:true, duration:100 } );
    $("#tresc_lewa").animate( {"width": "230px"}, { queue:true, duration:500 } );
    $("#tresc_lewa").animate( {"opacity": "100"}, { queue:true, duration:1000 } );
    $("#tresc_lewa div.tresc").animate( {"opacity": "100"}, { queue:true, duration:1000 } );
    //$("#tresc_lewa div.tresc").animate( {opacity: 100}, { queue:true, duration:500 } );
    $("#rozwin").animate( {"opacity": "0"}, { queue:true, duration:500 } );
    $("#tresc_lewa a").animate( {"opacity": "100"}, { queue:true, duration:15 } );
    $("#rozwin").hide();
    $.cookie('aktualnosci', 1);
    return false;
    });
    
    
    
$("#tresc_prawa h4").click(function(){
/*     $(this).parent().next().animate({height: 'toggle', opacity: 'toggle'}, 'slow', null);
    $(this).parent().next().next().animate({height: 'toggle', opacity: 'toggle'}, 'slow', null);
    
    //alert($(this).parent().next().next().next().children().children().text());
    if($(this).parent().next().next().next().children().children().is(":contains('więcej')"))
    {
      $(this).parent().next().next().next().children().children().text('zwiń');
    }
    else
    {
      $(this).parent().next().next().next().children().children().text('więcej');
    }
    
    return false; */
    /******************* NARAZIE TEGO WYRZEJ NIE POTRZEBUJE *********************/


/*     if ($(this).parent().next().next().is(":visible"))
    {
      $(this).parent().next().slideDown("slow");
      $(this).parent().next().next().slideUp("slow");
      //$(this).parent().next().animate({height: 'toggle', opacity: 'toggle'}, 'slow', null,);
      //$(this).parent().next().next().animate({height: 'toggle', opacity: 'toggle'}, 'slow', null,);
      return false;
    }
    else
    {
     $(this).parent().next().next().slideDown("slow");
     $(this).parent().next().slideUp("slow");
     return false;
    } */
  });
  


  $("#tresc_prawa a.wiecej").click(function(){
    $(this).parent().parent().prev().prev().animate({height: 'toggle', opacity: 'toggle'}, 'slow', null);
    $(this).parent().parent().prev().animate({height: 'toggle', opacity: 'toggle'}, 'slow', null);
    /* $(this).parent().parent().prev().prev().animate( {opacity: "0"}, { queue:false, duration:10 } );
    $(this).parent().parent().prev().animate( {opacity: "0"}, { queue:false, duration:10 } ); */
    if($(this).is(":contains('więcej')"))
    {
      $(this).text('zwiń');
    }
    else
    {
      $(this).text('więcej');
    }
    
    return false;
    
/*     if ($(this).parent().parent().prev().is(":visible"))
    {
      $(this).text('zwiń');
      return false;
    }
    else
    {
     $(this).text('więcej');
     return false;
    }
    return false; */
/*     if ($(this).parent().parent().prev().is(":visible"))
    {
      $(this).parent().parent().prev().prev().slideDown("slow");
      $(this).parent().parent().prev().slideUp("slow");
      return false;
    }
    else
    {
     $(this).parent().parent().prev().slideDown("slow");
     $(this).parent().parent().prev().prev().slideUp("slow");
     return false;
    } */
  });
//$("#tytul_2").click();

$("#zapisz_nws").click(function(){
     if(SprawdzMail())
     {
         $.ajax({
         type: "POST",
         url: "newsletter.php",
         data: "zapisz=true&mail="+document.getElementById("nws_mail").value,
         success: function(msg){
           alert(msg);
         }
       });
     }
     else
     {
       alert("Podaj prawidłowy adres email");
     }
  });
$("#wypisz_nws").click(function(){
     if(SprawdzMail())
     {
         $.ajax({
         type: "POST",
         url: "newsletter.php",
         data: "wypisz=true&mail="+document.getElementById("nws_mail").value,
         success: function(msg){
           alert(msg);
         }
       });
     }
     else
     {
       alert("Podaj prawidłowy adres email");
     }
  });

$("#nws_form").submit(function(){
   alert('Użyj przycisku zapisz, albo wypisz');
   return false;
  });
 //id='zapisz_nws'
 //id='wypisz_nws'
});
String.prototype.trim = function()
{
  return this.replace(/^\s+|\s+$/g,"");
};
function Sprawdz_szukaj() {
var txt = document.getElementById("szuk").value;
if(txt.trim() == '' || txt=='fraza do wyszukania...') {alert('wpisz szukaną frazę');return false;}
else{return true;}
}
function SprawdzMail() {
	var regemail = /^[a-z0-9][\w\.-]*\w@([\w-]+\.)*[a-z]{2,4}$/;
	var mail = document.getElementById("nws_mail").value;
	if(!regemail.test(mail)){ /* alert("Podaj prawidłowy adres email"); */ return false;}
	else{return true;}
}

