
var data = Array("tests");
var offset = 1;


/*
 *	Chili code highlighting
 *  http://code.google.com/p/jquery-chili-js/
 */

ChiliBook.recipeFolder = "js/chili/";;
ChiliBook.lineNumbers = true;



$(document).ready(function(){
	

	// lightbox

	$("a[@rel*=lightbox]").lightbox();



	// autocomplete

	$(".searchInput").autocomplete("autocomplete.php", { minChars: 2, delay: 50 });
		

	$("#next").click(function() {

		$.ajax({
			url: 'feed.php?getLastArticles=' + offset,
			type: 'GET',
			dataType: 'html',
			timeout: 1000,

			error: function(){
				alert('Error loading XML document');
			},

			success: function(response){

				$("#lastArticles").fadeOut("fast", function () {

				$("#lastArticles").html(response);
				$("#lastArticles").fadeIn("fast");

				offset++;
				});
			}

		});


	});




	// rakstu vertesana

	$("#rating #1, #rating #2, #rating #3, #rating #4, #rating #5").bind("mouseenter mouseleave click", function(e){
        
		switch(e.type)
		{
			case "mouseenter":
				drawTux(e.target.id);
			break;

			case "mouseleave":
				drawTux(0);
			break;

			case "click":

				var id = $("#rating").attr("article");

				$.ajax({
					url: 'feed.php?id=' + id + "&vote=" + e.target.id,
					type: 'GET',
					dataType: 'html',
					timeout: 1000,

					error: function(){
						alert('Error loading XML document');
					},

					success: function(response){
						$("#rating").html(response);
					}
				});

			break;
		}

    });



	function drawTux(item)
	{

		$("#rating img").each(function() {
			if(this.id <= item) {
				this.src = "pleznas/plezna18_1.jpg";
			} else {
				this.src = "pleznas/plezna18_0.jpg";
			}
		});
	}





	$(".image").bind("mouseenter",function(){
		$(this).css({ border : "1px solid red"});
	});
	$(".image").bind("mouseleave",function(){
		$(this).css({ border : "1px solid white"});
	});


	// emocijas

	$("div#emotions div.emo").click(function(){
		$('#texis').focus();
		$('#texis').replaceSelection(this.id);

		$("div#emotions").hide();
	});



	$("div#emotions div.emo").hover(
		function () {
			$(this).css("border", "1px solid red");
		}, 
		function () {
			$(this).css("border", "1px solid #EFEFEF");
		}
	);




	// twitter load

	$("#twitter").load('twitter.php');

	
});


// emocijas

function emotions(el) {
	
	$("div#emotions").toggle();
	$("#texis").focus();
}
