$(document).ready(function () { 
	
	// Ukrywanie wszystkich imprez
	$("#all-events").hide();
	
	$.fn.opacity = function(amount) {
        if (amount > 1) amount = 1;
        if (amount < 0) amount = 0;
        if ($.browser.msie) {
                amount = (parseFloat(amount) * 100);
                this.css('filter', 'alpha(opacity='+amount+')');
        } else {
                this.css('opacity', amount);
                this.css('-moz-opacity', amount);
        }
        return this;
	}

	// News :not(.calendar)
	$(".news .more").toggle(
	
		function() 
		{
			$(this).parent().parent().parent().find(".longNews").slideDown();
			
			$(this).removeClass("on");
			$(this).addClass("off");
		},
		
		function() 
		{
			$(this).parent().parent().parent().find(".longNews").slideUp();
			
			$(this).removeClass("off");
			$(this).addClass("on");
		}
		
	);
	
	/* Comments */
	$(".news .comment.toggle").toggle(
	
		function() 
		{
			$(this).parent().parent().find(".comments").slideDown();
		},
		
		function() 
		{
			$(this).parent().parent().find(".comments").slideUp();
		}
		
	);
	
	// Popups	
	$(function()
	{
		$(".popupwindow").popupwindow();
	});
	
	// Gallery
	$(".news.photo").hover(
		
		function() 
		{
			$(this).addClass("hover");
		},
		function() 
		{
			$(this).removeClass("hover");
		}
		
	);
	
	
	// Photos
	$(".text.gallery a div").hide();	
	$(".text.gallery a").hover(
	
		function() 
		{
			$(this).find("div").show();
			$(this).find("img").css('opacity',0.6);
		},
		function() 
		{
			$(this).find("div").hide();
			$(this).find("img").css('opacity',1);
		}
		
	);
	
	// Hover
	$(".thickbox").hover(
	
		function() 
		{
			$(this).find("img").css('opacity',0.6);
		},
		function() 
		{
			$(this).find("img").css('opacity',1);
		}
		
	);
	
	// Artists
	$("form.calendar select").change(function() {
	var ID = $(this).attr("value");
	
		if ( ID != "undefined" )
		{
			window.location = "/calendar/artist/" + ID;
		}
		else
		{
			return false;
		}
	
	});
	
	// All events
	/*
	$(".all-events").toggle(
		
		function ()
		{
			$("#all-events").slideDown(700);
		},
		function ()
		{
			$("#all-events").slideUp(300);
		}
		
		
	);
	*/

  $(".contact .submit").click(function() {
    if (document.getElementById('inputControlcontact').value != document.getElementById('controlValidcontact').value) {
      document.getElementById('inputControlcontact').style.border = '1px solid red';
      doControl('contact');
      return false;
    }
  });
	
});

function doControl(id) {
  var n1;
  var n2;

  n1 = (Math.round((Math.random()*9)+1))
  n2 = (Math.round((Math.random()*9)+1));
  
  document.getElementById('control'+id).innerHTML = n1 + ' + ' + n2 + ' =';
  document.getElementById('controlValid'+id).value = n1 + n2;
}
