/*
 * ----------------------------------------------------------------------------
 * $Id: index.js,v 1.1 2009/04/11 10:07:11 stephan Exp $
 * ----------------------------------------------------------------------------
 * $Log: index.js,v $
 * Revision 1.1  2009/04/11 10:07:11  stephan
 * Initial revision
 *
 * ----------------------------------------------------------------------------
 */

function initLightbox(collectie)
{
	$(".lblink").click(function()
	{
		var selection = collectie;
		if(typeof(collectie) == "undefined")
		{
			if($(this).attr("href") && $(this).attr("href") != "")
				selection=$(this).attr("href").replace(/(.*\/)*(.*)(\.php.*)/, "$2").toLowerCase();
		}

		showPopbox(function()
		{
			loadCollectie(selection);
		});
		return false;
	});
}

function loadCollectie(collectie)
{
	var value = (typeof(collectie) != "undefined" ? collectie :
		$(document).attr("URL").replace(/(.*\/)*(.*)(\.php.*)/, "$2").toLowerCase());
		
	switch(value)
	{
	case "vloeren":
	case "hardevloeren":
	case "raamdecoratie":
	case "meubels":
	case "wandbekleding":
	case "kastenwanden":
	case "traplopers":
		break;
	default:
		value = "wandbekleding";
		break;
	}

	$.post("/lbcontent.php", {item: value}, function(data) 
	{
		$('#popbox').html(data);

		$(document).ready(function() 
		{ 
			setupPopbox();
		});
	}, "html");
}

function setupPopbox()
{
	$('#lb_sluit').click(hidePopbox);     

	if(!$('#menu').is(':hidden'))
		$('#menu').hide();

	$('#lb_thumbs').hide();
	$('#lb_mainfoto').css("background-image", "url('" + $('#lb_mainfoto img:first').attr("src") + "')");

	var images = new Array();

	$('#lb_thumbs img').each(function()
	{
		/* preload all images temporary in the background-image */
		var thumb = new Image();
		var detail = new Image();
		
		thumb.src = this.src;
		detail.src = this.src.replace(/thumbs\//i, "");
		images.push(thumb, detail);
	});

        $('#lb_thumbs').onImagesLoad({ 
            	selectorCallback: function() 
		{
			$('#lb_thumbs img').css({opacity: "0.5"});
			$('#lb_thumbs img:first').css({opacity: "1.0"});

			$('#lb_thumbs img').click(function() 
			{
				var path = $(this).attr("src");
				path = path.replace(/thumbs\//g,"");

				if(!$('#menu').is(':hidden'))
					$('#menu').hide('slow');

				$('#lb_thumbs img').css({opacity: "0.5"});

				/* put current background in foreground image */
				if($('#lb_mainfoto').css("background-image") != "")
					$('#lb_mainfoto img:first')
					.attr("src", $('#lb_mainfoto').
						css("background-image")
						.replace(/(^url\()(.*)(\)$)/gi, "$2")
						.replace(/[\'\"]/gi, "")
					);

				/* make it visable */
				$('#lb_mainfoto img:first').css("opacity", "1.0");
			
				/* put new image in background */
				$('#lb_mainfoto').css("background-image", "url('" + path + "')");

				/* fade out old picture in foreground */
				$('#lb_mainfoto img:first').fadeTo("slow", 0.0);

				$(this).css({opacity: "1.0"});

				$('#lb_thumbs')[0].scrollTo($(this).position().top-($(this).height()/2)-($('#lb_thumbs').innerWidth()/2)+14);
			});
			$('#lb_thumbs').show();
			$('#lb_thumbs').jScrollPane({animateTo:true});
		}
        }); 

	$('#lb_menu').click(function() 
	{
		if($('#menu').is(':hidden'))
			$('#menu').css({opacity: "0.9", "z-index": 10000}).show("slow");
		else
			$('#menu').hide("slow");
	});

	$('#menu a').click(function() 
	{
		loadCollectie($(this).attr("href").replace(/(.*=)/gi, ""));
		return false;
	});
}
