$(document).ready(function(){
	// cień dookoła wrappera
	ww = document.documentElement.clientWidth;

	if (ww && ww > 1024) {
		$("#container").css('width', '1025px');
		$("#menu").css('left', '210px');
		$("#submenu").css('left', '200px');
		$("#search").css('left', '700px');
		$("#topmenu").css('left', '390px');
		$("#logo").css('left', '60px');
		ie6=$.browser.msie&&($.browser.version == "6.0")&&!window.XMLHttpRequest;
		if (!ie6) {
			$("#container").css('background-image', 'url(images/template/container_bg.png)');
		}
	}

	$(".events_list").hide();
	$("#events_button_last").removeClass("active");
	$("#events_button_coming").addClass("active");
	$("#events_list_coming").show();

	$("#events_button_last").click(function(){
		$("#events_list_last").show();
		$("#events_list_coming").hide();
		$("#events_button_coming").removeClass("active");
		$("#events_button_last").addClass("active");
		return false;
    });

    $("#events_button_coming").click(function(){
		$("#events_list_coming").show();
		$("#events_list_last").hide();
		$("#events_button_last").removeClass("active");
		$("#events_button_coming").addClass("active");
		return false;
    });

    //rozwija element następujący po klikniętym elemencie
    $(".next_read_more").click(function(){
    	$(this).next().show("slow");
    	$(this).hide();
    	return false;
    });

	$(".next_photo").click(function(event){
		event.stopPropagation();
		photoSlider.next();
		return false;
	});

	$(".prev_photo").click(function(event){
		event.stopPropagation();
		photoSlider.prev();
		return false;
	});

	$("#newsletter_container input.submit").click(function(){
		var e = $(this);
		var val = $("#newsletter_e-mail").css('border-color', '#c2c2c2').val();
		if (val == '') return false;
		$.getJSON('/newsletter/submit', {email:val}, function(r){
			if (typeof r == 'boolean' && r) {
				$("#newsletter_container").html('<p style="padding:5px;"><small>Na Twój adres e-mail została wysłana wiadomość z prośbą o potwierdzenie rejestracji.<small></p>');
			} else {
				$("#newsletter_e-mail").css('border-color', '#cc0a13');
			}
		});
		return false;
	});
});

var photoSlider = {
	idx: 0,
	rand: function()
	{
		var max = photos.length-2 + 1;
		this.idx = Math.floor(Math.random()*max);
		this.render();
	},
	next: function()
	{
		if (this.idx < photos.length-2) {
			this.idx++;
		} else {
			this.idx = 0;
		}
		this.render();
	},
	prev: function()
	{
		if (this.idx > 0) {
			this.idx--;
		} else {
			this.idx = photos.length-2;
		}
		this.render();
	},
	render: function()
	{
		$("#photo_container div.photo_img").css('background-image', 'url(http://www.autoklub.pl/fotogalerie/cache/' + photos[this.idx][1] + '.jpg)');
		$("#photo_container a.photo_title").attr('title', 'fot. ' + photos[this.idx][2]);
		$("#photo_container a.photo_title").attr('href', photos[this.idx][3]);
		$("#photo_container a.photo_title").html(photos[this.idx][0]);
	},
	select: function()
	{
		document.location=photos[this.idx][3];
	}
};

