$(document).ready(function() {
	
	var boxesCache = new Array();
	boxesCache[0] = $('#boxes').html();
	
	var pages = $('a.slider-point').size();
	var i = 0;
	
	var boxesCarousel = setInterval(function() {
		$('a.slider-point').eq(i).trigger('click');    
	    i++;    
	    if (i == pages) i = 0;
	}, 6000);
	
	$('a.slider-point').click(function(event) {
		
		if (event.originalEvent) clearInterval(boxesCarousel);
		
		var categoryId = $(this).attr('category_id');	
		var page 	   = $(this).attr('page');
		
		$('a.slider-point').removeClass('selected');
		$(this).addClass('selected');
		
		if (boxesCache[page] != undefined) {
			$('#boxes').html(boxesCache[page]);
		} else {
			var loader = '<img src="/gfx/ajax-loader.gif"/><br/>Ładowanie';
			$('#boxes').html(loader).addClass('boxes-center');
			$.post(sRemoteServer, {
				request: 'index/getBoxes',
				category_id: categoryId,
				page: page
			}, function(data){
				$('#boxes').removeClass('boxes-center').html(data);
				boxesCache[page] = data;
			});
		}
		return false;	
	});
	
	$('ul.pikame-gallery').each(function() {
		$('#'+this.id).PikaChoose({
			text: {
				play:'',
				stop:'',
				previous:'', //Poprzednie
				next:'' //Następne
			},
			carousel: false
		});	
	});
	
	//ui fix for firefox
	if ($.browser.mozilla) $('#textarea-bg').css('background-color', '#4C4C4C');
	
	$('#contact-send-button').click(function() {
		if (!FormValidation.string('msg_title')) {
			alert('Proszę wpisać tytuł wiadomości');return false;
		}
		if (!FormValidation.string('msg_content')) {
			alert('Proszę wpisać treść wiadomości');return false;
		}
		if (!FormValidation.email('msg_email')) {
			alert('Proszę wpisać poprawny adres zwrotny');return false;
		}
		var form = document.getElementById('contactformjs');
		form.style.display = 'none';
		var ind = document.getElementById('send-indicator');
		ind.style.display = 'block';
		$.post(sRemoteServer, {
			request: 'send/contactform',
			data: Ui.collect('contactformjs')
		}, function(data) {
			var o = eval('('+data+')');
			ind.innerHTML = o.msg;
		});
		return false;
	});
	
	$('#subscribe-button').click(function() {
		if (!FormValidation.email('subscribe-input')) {
			alert('Proszę wpisać poprawny adres email');return false;
		}
		var form = document.getElementById('subscribe-container');
		form.style.display = 'none';
		var ind = document.getElementById('subscribe-indicator');
		ind.style.display = 'block';
		$.post(sRemoteServer, {
			request: 'send/newsletter',
			email: $('#subscribe-input').val()
		}, function(data) {
			var o = eval('('+data+')');
			ind.innerHTML = o.msg;
		});
		return false;
	});
	
});
