function show(id) 
{
    var e = document.getElementById(id);
    if(e.style.display == 'none')
      e.style.display = 'block';
    else
      e.style.display = 'none';
}

function slideShow() {
  
	$('.carousel:first').fadeIn(3000); 
	//$('.carousel').css({opacity: 0.0});
	//$('.carousel:first').css({opacity: 1.0});
	gallery();
	i=setInterval('gallery()',7000);
	
}

function gallery() 
{	
	var current = ($('.carousel.show')?  $('.carousel.show') : $('.carousel:first'));
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('.carousel:first') :current.next()) : $('.carousel:first'));	
	//Set the fade in effect for the next image, show class has higher z-index
	
  //Hide the current image
  current.fadeOut(3000).removeClass('show');
  
  //Set the fade in effect for the next image, show class has higher z-index
  next.fadeIn(3000).addClass('show');
}

function isValidEmailAddress(emailAddress) {
 		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
 		return pattern.test(emailAddress);
	}
	
function FormValidate()
{
    var valid=true;
    $('.required').each( function(index){
    if( $(this).val()=='' || $(this).val()==$(this).attr('title') )
    {
        valid=false;
				$( this ).css( 'border', '1px solid #CA0000' );
    }
    else
        $( this ).css( 'border', '1px solid #D7D7D7' );

    });
    
    
    var email_address=$('#question_email');
    if (isValidEmailAddress(email_address.val()))
    {
      email_address.css( 'border', '1px solid #D7D7D7' );
    }
    else
    {
      valid=false;
      email_address.css( 'border', '1px solid #CA0000' );
    }
    return valid;       
}       

$(document).ready(function()
{  
  $("#ask_button").fancybox({
  	'scrolling'		: 'no',
  	'titleShow'		: false,
  	'onClosed'		: function() {
  	    $("#question_error").hide();
  	}
  });
  
  $("#question_form").bind("submit", function() {
  if (FormValidate()===false)
  {
      $("#question_error").show();
	    $.fancybox.resize();
	    return false;
  
	}
	$.fancybox.showActivity();
  var qemail=$('#question_email').val();
  var question=$('#q').val();
  var zapisnlt=$('#zapis_newsletter').is(':checked');
	$.ajax({
		type		: "POST",
		url		: "/ajx_pytanie",
		data		: {qemail:qemail,question:question,zapis_newsletter:zapisnlt},
		success: function(data) {
		    $.fancybox(data);
		}
	});

	return false;
});

  $("#privlink").fancybox({
  	'scrolling'		: 'auto',
  	'titleShow'		: false,
  	'width'       : '800'
  });

  $('.submenu > a').hover(
    function(){
      $(this).css({opacity:0.9});
    },
    function(){
      $(this).css({opacity:1.0});
    });



  slideShow();
  
  

	$('a').each(function(){  
      
      if ($(this).attr('href') !== undefined && $(this).attr('href') != '' && $(this).attr('href') != '#')
      {
	      var linkx = $(this).attr('href');
	      var s = linkx.split('.');
	      var ext = (s[s.length-1]).toLowerCase();
	      if(ext=='jpg' || ext=='jpeg' || ext=='gif' || ext=='png')
	        $(this).attr('class','fancybox');
				//$(this).attr('rel','group');
			} 
  
  });
  
  $('a.fancybox').fancybox({
    'transitionOut'		: 'none',
		'titleShow' 	: false
  });
  
  
  
  $('.afot').hover(
  function(){
    $('.afot #lupka').show();
  },
  function(){
    $('.afot #lupka').hide();
  });
  
  var lang=$('#lang').val();
  if (lang=='en')
    var podpis = 'Photo ';
  else
    var podpis = 'Zdjęcie ';
  $("a[rel=galeria]").fancybox({
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">' + podpis + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});	
  
  
  
  
  
  
  
   
});

