$(document).ready(function () {
	$("#showform").click(function(){
		$("#closedform").slideToggle("slow");
		$(this).toggleClass("hidden");
	});

	
	$('#aml_search_box #id_q').val('vpiši iskalni niz');
	$('#aml_search_box #id_q').click(function(){
		$(this).val("");
		$(this).css({'background':'#eee'});
	});
	
	// article detail carousel
	if ($('#carousel').length != 0 ) {
		$.getScript(
			"/media/js/jcarousel/jquery.jcarousel.pack.js",
			function(data, textStatus){
				$('#carousel').jcarousel({ scroll: 5, easing: 'swing'});
		});
	}

	//sidebar sticky
	if ($('.aside .latestRSS').length != 0 ) {
		$.waypoints.settings.scrollThrottle = 0;
		$('.aside').find('.latestRSS').waypoint(function(event, direction) {
			$('.latestRSS').toggleClass('sticky', direction === "down");
			event.stopPropagation();
		});
	}

// 	if ($('#related').length != 0 ) {
//         $(window).bind("scroll", function(event) {
//             $('#related_content').stop();
//             var top_offset = $(window).scrollTop() - $('#article_content').offset().top;
//             var max_offset = $('#article_content').height() - $('#related_content').height();
//             if (top_offset < 0) { top_offset = 0; }
//             if (top_offset > max_offset) { top_offset = max_offset; }
//             if (top_offset != $('#related_content').css('marginTop')) {
//                 $('#related_content').animate({"marginTop": (top_offset) + "px"}, 0 );
//             }
//         });
//     }

	if ($('#related').length != 0 ) {
        scrollheight = $('#article_content').height() - $('#related').height();
        if (scrollheight > 0 ) {
            $(window).bind("scroll", function(event) {
                acoffset = $(window).scrollTop() - $('#article_content').offset().top;
                if (acoffset <= 0) {
                    $('#related').css('top','0px').css('bottom','auto').css('position','absolute');
                }
                if (acoffset >= scrollheight) {
                    $('#related').css('top','auto').css('bottom','0px').css('position','absolute');
                }
                if (acoffset < scrollheight && acoffset > 0 ) {
                    $('#related').css('top','0px').css('bottom','auto').css('position','fixed');
                }
            });
        } else {
            $('#article_content').height($('#related').height());
        }
	}

/*
	$("#twitter-feed").getTwitter({ 
		userName: "aktivni", 
		numTweets: 5, 
		loaderText: "Samo trenutek...", 
		slideIn: true, 
		showHeading: false, 
		headingText: "", 
		showProfileLink: false
	});
*/
});
