var base_url;

function site_url(link)
{
	return base_url + link;
}


/**
 * last angiver antal pladser fra sidste (2/1/0). 
 * string er den url 
 */
function extract_segment(last, url)
{
	if (url != undefined)
	{
		url_array = url.split("/");
		array_count = url_array.length;
		return url_array[array_count-(1+last)];
	}
}

function chop_segments(count, url)
{
	url_array = url.split("/");
	array_count = url_array.length;
	new_url_array = url_array.slice(0,array_count-count);
	return new_url_array.join("/");
}

function extract_id(string)
{
	if (string !== undefined)
	{
		array = string.split("-");
		return array[1];
	}
}

function get_picture_browser_url(file_id)
{
	return  site_url("/image/" + file_id + "/area");
}
/*
function open_picture_browser(url)
{
	window.open(url,null,'menubar=yes,toolbar=no,status=no,width=855,height=595,resizable=yes,scrollbars');		
}*/

$(document).ready(function()
{
	/*
	 * Sets the first element to active and opens it
	 */
	$(".area_imgs .imgs a").eq(0).addClass("active");
	
	// ------------
	// apartments [information/area/$id]
	if ($(".area_imgs").size() > 0)
	{
		$(".area_imgs .imgs a").click(function()
		{
			base_url = chop_segments(3, location.href);
			image_url =  $(this).attr("href");
			$(".area_imgs .imgs a").removeClass("active");
			$(this).addClass("active");
			file_id = extract_segment(1, image_url);
			area_id = extract_segment(0, location.href);
			
			picturebrowser_url = get_picture_browser_url(file_id);
			$(".area_imgs .big_img > a img").attr("src", picturebrowser_url);
			//$(".area_imgs .big_img > a").attr("href", picturebrowser_url);		
			
			return false;
		});
		
		
		$(".area_imgs > a").click(function()
		{
			open_picture_browser($(this).attr("href"));
			return false;
		});
	}
	// -------------
	/*
	 * lightbox
	 */
	$(".type_active .type_imgs  a").lightBox();
	
	$(".area_imgs .imgs a").lightBoxImageSlide();
	
	
	

	
	
	
activateTypeBrowser();

function activateTypeBrowser()
{
	$("#type_browser .type a.typelink, #type_browser .type_active a.typelink").click(function()
	{
		//currentActive = $("#type_browser .type_active");
		//currentActive.addClass("type");
		//currentActive.removeClass("type_active");
		if ($(this).parent().hasClass("type"))
		{
			$(this).parent().removeClass("type");
			$(this).parent().addClass("type_active");
		}
		else
		{
			$(this).parent().addClass("type");
			$(this).parent().removeClass("type_active");
		}
		$(".type_active .type_imgs  a").lightBox();
		//activateTypeBrowser();
		return false;
	});
}	
	
activatePresentationsTabs();
function activatePresentationsTabs()
{
	$(".presentation li a").click(function(){
		clicked = this;
		clickedno = -1;
		$(".presentation li a").each(function(i){
			if (clicked == this)
				clickedno = i;
		});
		
		$(".presentation li .active").removeClass("active");
		$(this).addClass("active");
		
		$(".presentation .presentation_info .show").removeClass("show");
		$(".presentation .presentation_info .presentation_entry").eq(clickedno).addClass("show");

		return false;
	});
}
	
});

