/* == DECLARE VARS == */

var text_close = "sluit";
var text_open = "lees meer";



/* == FUNCTION: DEFINE LAST LINK == */

function defineLastLink(div_name)
{
	$("div#" + div_name + " ul li a:last").addClass("last");
}



/* == FUNCTION: DEFINITION LIST BEHAVIOR == */

function definitionListBehavior(selector)
{
	if ($(selector).length > 0)
	{
		$(selector + ":first").addClass("first");
		
		$(selector).hover(function() {
			$(this).addClass("hover");
		}, function() {
			$(this).removeClass("hover");
		});
	}
}



/* == FUNCTION: DIV HOVER BEHAVIOR == */

function divHoverBehavior(selector)
{
	if ($(selector).length > 0)
	{
		$(selector).hover(function() {
			$(this).addClass("hover");
		}, function() {
			$(this).removeClass("hover");
		});
	}
}



/* == FUNCTION: GOOGLE MAPS == */

function googleMaps()
{
	var map = new GMap2(document.getElementById("map"));
	map.setCenter(new GLatLng(51.390503, 4.938183), 14);
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	
	var icon = new GIcon();
	icon.image = "../images/maps_marker.png";
	icon.shadow = "../images/maps_marker_shadow.png";
	icon.iconSize = new GSize(21.0, 30.0);
	icon.shadowSize = new GSize(37.0, 30.0);
	icon.iconAnchor = new GPoint(10.0, 30.0);
	icon.infoWindowAnchor = new GPoint(10.0, 15.0);
	
	var marker = new GMarker(new GLatLng(51.390503, 4.938183), icon);
	GEvent.addListener(marker, "click", function()
	{
		marker.openInfoWindowHtml("<p><strong>Ponyhoeve</strong><br />Steenweg op Baarle Hertog 123<br />2300 Turnhout</p>");
	});
	map.addOverlay(marker);
	GEvent.trigger(marker, "click");
}



/* == FUNCTION: TOGGLE CONTENT ITEMS  == */

function toggleContentItems()
{
	if ($("div.content_item.collapse"))
	{
		$("div.content_item.collapse div.detail").hide();
		$("div.content_item.collapse").append("<p class=\"read_more\"><a href=\"#\">" + text_open + "</a></p>");
		$("div.content_item.collapse p.read_more a").click(function()
		{
			$(this).toggleClass("active");
			
			if ($(this).text() == text_open)
			{
				$(this).text(text_close);
			}
			else
			{
				$(this).text(text_open);
			}
			
			if ($(this).parent().prev().attr("class") == "detail")
			{
				$(this).parent().prev().slideToggle("fast");
			}
			
			return false;
		});
	}
}



/* == FUNCTION: SCROLLING DIV == */

/*function newsCarousel(container)
{
	if ($("div#" + container).length > 0)
	{
		$("div#" + container + " dl").wrapAll("<div id=\"" + container + "_scrollable\"></div>");
		$("div#" + container).append("<a href=\"#\" class=\"previous\">Previous</a>");
		$("div#" + container).append("<a href=\"#\" class=\"next\">Volgende</a>");
		//$("div#news_overview_scrollable").scrollable({items:"div#news_overview_scrollable dl",horizontal:false,prev:"div#news_overview a.previous",next:"div#news_overview a.next"});
	}
}*/



/* == EVENTS == */

$(document).ready(function()
{
	defineLastLink("navigation");
	$("a.lightbox").lightbox(); // Lightbox init
	toggleContentItems();
	//newsCarousel("news_overview");
	definitionListBehavior("div#content div.content_item dl.gallery_archive");
	divHoverBehavior("div#content div.content_item div.gallery");
});

$(window).load(function()
{
	if ($("div#map").length > 0)
	{
		googleMaps();
	}
});

$(window).unload(function()
{
	if ($("div#map").length > 0)
	{
		GUnload();
	}
});
