/* == FUNCTION: ADD FANCYBOX == */

function addFancyBox(selector)
{
	if ($(selector).length > 0)
	{
		$(selector).fancybox({
			'overlayShow' : true,
			'hideOnContentClick' : true,
			'overlayOpacity' : 0.8
		});
	}
}



/* == ADD READ MORE == */

function addReadMore(selector)
{
	$(selector).each(function() {
		
		var container_div = this;
		
		if ($("p.intro", this).length > 0) {
			
			if ($("p.text", this).length > 0) {
				$("p.text", this).hide();
			}
					
			if ($("div.downloads", this).length > 0) {
				$("div.downloads", this).hide();
			}
		
			$(this).append("<p class=\"read_more\"><a href=\"#\">" + text_read_more + "</a></p>");
				
			$("p.read_more a", this).click(function() {
				
				if ($("p.text", container_div).length > 0) {
					$("p.text", container_div).slideToggle("fast");
				}
			
				if ($("div.downloads", container_div).length > 0) {
					$("div.downloads", container_div).slideToggle("fast");
				}
				
				if ($(this).html() == text_read_more) {
					$(this).html(text_close);
				}
				else if ($(this).html() == text_close) {
					$(this).html(text_read_more);
				}
				
				return false;
			});
		}
	});
}



/* == FUNCTION: ADD SCROLLABLE == */

function addScrollable(selector)
{
	if ($(selector).length > 0)
	{
		$(selector).parent().prepend("<a class=\"prevPage browse up\" href=\"#\">Previous</a>");
		$(selector).parent().append("<a class=\"nextPage browse down\" href=\"#\">Next</a>");
		
		$(selector).scrollable({
			vertical: true,
			size: 3
		});
		
		$(selector).parent().find("a.browse").click(function() {
			return false;
		});
	}
}



/* == EVENTS == */

$(document).ready(function() {
	addFancyBox("div#content div.content_item_image a.fancybox");
	
	addReadMore("div#content div.content_item");
	addReadMore("div#content div.content_item_image");
	
	addScrollable("div#news div.scrollable");
});
