function Timer(id, rok, miesiac, dzien, godzina,minuty,sekundy)
{
	var targetDate = new Date(rok,miesiac-1,dzien,godzina,minuty,sekundy);
	R(id, targetDate);
	setInterval(function() { R(id, targetDate) },1000);
}
function CD(d,o,t,x){return[x=~~(t=(d-o)/864e5),x=~~(t=(t-x)*24), x=~~(t=(t-x)*60),~~((t-x)*60)]}
function R(id, targetDate)
{
	t=CD(new Date( (targetDate.getTime())-(60*60*1000) ),new Date( (new Date().getTime())+(new Date().getTimezoneOffset()*60*1000) ));
	document.getElementById(id).innerHTML=''+Math.max(0, t[0])+' '+((t[0]==1)?'dzień ':'dni ')+((t[1]<10)?'0':'')+Math.max(0, t[1])+':'+((t[2]<10)?'0':'')+Math.max(0, t[2])+':'+((t[3]<10)?'0':'')+Math.max(0, t[3]);
	if(!t[0]&&!t[1]&&!t[2]&&!t[3]) { document.getElementById(id).innerHTML='zakończone'; }
}

function validateEmail(email){ 
  var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ 
 return email.match(re) 
}


function validate(name,email,comment){
  var is_ok = true;
  if(name == ''){
    //$('#commentName').css({backgroundColor: 'red'});
    is_ok = false;
  }else{
    //$('#commentName').css({backgroundColor: '#FFFFFF'});
  }
  if(email == '' || !validateEmail(email)){
    //$('#commentEmail').css({backgroundColor: 'red'});
    is_ok = false;
  }else{
    //$('#commentEmail').css({backgroundColor: '#FFFFFF'});
  }
  if(comment == ''){
    //$('#commentContent').css({backgroundColor: 'red'});
    is_ok = false;
  }else{
    //$('#commentContent').css({backgroundColor: '#FFFFFF'});
  }
  return is_ok;
  
}




$.fn.widget = function () {
	
	return this.each(function () {
		var open = 0;
		var items = null;
		items = $('.list li', this).hide();
		
		for(var i=0;i<items.length;i++)
		{
			$('.panel-navigator', this).append('<li'+((i==open)?' class="selected"':'')+'><a href="#" onclick="gotoWidget('+i+');return false">'+(i+1)+'</a></li>');
		}
		
		$(items[open]).show();
		
		function gotoPage(x)
		{
			if(x!=open)
			{
				$(items[open]).fadeOut(
					function()
					{
						links = $('#panel .panel-navigator li');
						y=x;
						if(y>=items.length) { y=0; }
						else if(y<0) { y=items.length-1; }
						open=y;
						
						$('#panel .panel-navigator .selected').removeClass('selected');
						$(links[open]).addClass('selected');
					}
				);
				y=x;
				if(y>=items.length) { y=0; }
				else if(y<0) { y=items.length-1; }
				open=y;
				$(items[open]).fadeIn();
			}
		}
		
		function gotoPageNext()
		{
		
			nr=open+1;
			if(nr>=items.length) { nr = 0; }
			gotoPage(nr);
		}
		
		gotoWidget = function(x) { gotoPage(x); };
		gotoNext = function() { gotoPageNext(); };
	});
};





var bHidden = true ; 

function showlayer(object) {
	if (bHidden)
		show(object);
	else
		hide(object);
	bHidden = !bHidden;
}

function show(object) {
  if (document.getElementById) {
    document.getElementById(object).style.visibility = 'visible';
	document.getElementById(object).style.position = 'static'; 
  }
  else if (document.layers && document.layers[object]) {
    document.layers[object].visibility = 'visible';
	document.layers[object].position = 'static'; 
  }
  else if (document.all) {
    document.all[object].style.visibility = 'visible';
	document.all[object].style.position = 'static'; 
  }
}

function hide(object) {
  if (document.getElementById) {
    document.getElementById(object).style.visibility = 'hidden';
	document.getElementById(object).style.position = 'absolute'; 
  }
  else if (document.layers && document.layers[object]) {
    document.layers[object].visibility = 'hidden';
	document.layers[object].position = 'absolute'; 
  }
  else if (document.all) {
    document.all[object].style.visibility = 'hidden';
	document.all[object].style.position = 'absolute'; 

  }
}



$(document).ready(function () {
	if($('.select-line').length>0) { $('.select-line').jqTransform({imgPath:'http://jezykiobce.net/images/'}); }
	if($('.page-title .select').length>0) { $('.page-title .select').jqTransform({imgPath:'http://jezykiobce.net/images/'}); }
	if($('.sort-form').length>0) { $('.sort-form').jqTransform({imgPath:'http://jezykiobce.net/images/'}); }
	
	$('#search-form .input').focus(function(){if(this.value==this.defaultValue){this.value='';}});
	$('#search-form .input').blur(function(){if(this.value==''){this.value=this.defaultValue;}});
	
	$('.newsletter-form .input').focus(function(){if(this.value==this.defaultValue){this.value='';}});
	$('.newsletter-form .input').blur(function(){if(this.value==''){this.value=this.defaultValue;}});
	
	$('.bonus-input .input').focus(function(){if(this.value==this.defaultValue){this.value='';}});
	$('.bonus-input .input').blur(function(){if(this.value==''){this.value=this.defaultValue;}});
	
	
	if($('.book-panellist').length>0)
	{
		$('.book-panellist .list a').click(function(){
			$('.book-panellist .active').removeClass('active');
			nr=this.className.replace('item', '');
			$($('.book-panellist .list li')[nr-1]).addClass('active');
			$($('.book-panellist .big-list li')[nr-1]).addClass('active');
			return false;
		});
	}
	
	
	$('#panel').widget();
	if($('#panel').length>0) { setInterval('gotoNext()', 5000); }
	
	$('.text_prof ul:not(.visib)').css('display', 'yes');
	$('.text_prof a.check').click(function(){$(this).next('ul').show();if($(this).attr('href') == '#'){return false;}else{return true;}});
	
	$('.animationPop').popupWindow({ centerScreen:1});
	
	$("a[rel^='prettyPhoto']").prettyPhoto({opacity: 0.30,theme: 'light_rounded',});
	
    $('#opinionSendButton').click(
      function(){
        var name = $('#commentName').val();
        var email = $('#commentEmail').val();
        var comment = $('#commentContent').val();
        var prod_id = $('#prod_id').val();
        var time = $('#time').val();
        var write = $('#write_something').val();
        var package_id = $('#package_id').val();
        valid = validate(name,email,comment);
        if(valid){
          $('#CommentMsgBox').hide();
          $.ajax({
            url: 'add_comment.php',
            type: 'POST',
            data:{
              name: name,
              email: email,
              prod_id: prod_id,
              comment: comment,
              time: time,
              write: write,
              package_id: package_id              
            },
            beforeSend: function(html){
              $('#opinionSendButton').hide('slow');
              $('#CommentMsgBox').html('Czekaj...');                                
            },
            success: function(tekst){
              $('#CommentMsgBox').html('Opnia została poprawnie dodana').show();
              //$('#commentForm').hide();
            },
            error: function(){
              $('#CommentMsgBox').html('Podczas wysyłania wystąpił błąd');
              $('#opinionSendButton').show('slow');
            } 
          });
        }else{
          $('#CommentMsgBox').html('Wszytskie pola musza być wypełnione').show();
          
        }
        
        return false;
      }
    );	
	
	 $('#fiszki_pop').click(
        function(){
          $('#fiszki_popup').slideToggle();
          return false;
        }
      );
    $('.zamknij').click(
      function(){
        $('#fiszki_popup').slideToggle();
        return false;
      }
    );
	
});
