$(document).ready(function(){
	
	$('#search_query').focus(function() {
		if ($(this).val() == $('#SEARCH_DEFAULT_KEYWORD').val()) {
			$(this).val('');
		}
	}).blur(function() {
		if ($(this).val() == '') {
			$(this).val($('#SEARCH_DEFAULT_KEYWORD').val());
		}
	});
	
	$('a.photo').colorbox({
		transition: 'none',
		maxWidth : '90%',
		maxHeight : '90%',
		minWidth : 630,
		minHeight : 660
	});
	
	$('a.out').click(function(){
		if ($(this).hasClass('photo') !== true) {
			window.open($(this).attr('href'));
			return false;
		}
	});
	
	// Slideshow
	
	var slideBlocked = false;
	
	slideshowSet = function(n) {
		slideBlocked = true;
		var activeSlide = $('.slideshow img.active');
		var nextSlide = $('.slideshow img[rel=' + n + ']');
		activeSlide.addClass('last-active');
		$('#SSHOW_CURRENT').val(n);
		$('#slidepaging span').removeClass('active');
		$('#slidepaging span[rel=' + n + ']').addClass('active');
		nextSlide.css({ opacity : 0.0 }).addClass('active').animate(
			{ opacity : 1.0 }, 1000, function(){
			activeSlide.removeClass('active last-active');
			slideBlocked = false;
		});
	}
	
	if (parseInt($('#SSHOW_TOTAL').val()) > 1) {
		var slideInterval = setInterval(function(){
			var currentSlide = parseInt($('#SSHOW_CURRENT').val());
			var nextSlide = (1 + currentSlide);
			if ($('.slideshow img[rel=' + nextSlide + ']').length > 0) {
				slideshowSet(nextSlide);
			} else {
				slideshowSet(1);
			}
		}, $('#SSHOW_SECS').val());
	}
	
	$('#slidepaging span').click(function(){
		if ($(this).hasClass('active') || slideBlocked == true) {
			return false;
		} else {
			$('#slidepaging span').removeClass('active');
			$(this).addClass('active');
			slideshowSet($(this).attr('rel'));
			clearInterval(slideInterval);
			return false;
		}
	});
	
	$('.truncate').jTruncate({
        length: 450,
        minTrail: 0,
        moreText: "Preberi več",
        lessText: "Zapri",
        ellipsisText: " [...]"
    });
	
});
