function initNavMenu ( )
{
	if ( typeof ( GuiAnimatedMenu ) != 'undefined' && document.getElementById ( 'TopMenu__' ) )
		var n = new GuiAnimatedMenu ( document.getElementById ( 'TopMenu__' ) );
	else setTimeout ( 'initNavMenu ( )', 50 );
}
initNavMenu ( );

include ( 'javascript/slideshow.js' );


function parseMarkdown ( str )
{
	// h3
	var h3;
	while ( h3 = str.match ( /###[\w\W]*?[#]*(.*?)\n/ ) )
		str = str.split ( h3[ 0 ] ).join ( '<h3>' + h3[ 1 ] + '</h3>\n' );
	
	// h2
	var h2;
	while ( h2 = str.match ( /##[\w\W]*?[#]*(.*?)\n/ ) )
		str = str.split ( h2[ 0 ] ).join ( '<h2>' + h2[ 1 ] + '</h2>\n' );
		
	// h1
	var h1;
	while ( h1 = str.match ( /#[\w\W]*?[#]*(.*?)\n/ ) )
		str = str.split ( h1[ 0 ] ).join ( '<h1>' + h1[ 1 ] + '</h1>\n' );
		
	// emphasized
	var em;
	while ( em = str.match ( /\*\*([^*\n]*?)\*\*/ ) )
		str = str.split ( "**" + em[ 1 ] + "**" ).join ( '<em>' + em[ 1 ] + '</em>' );
	
	// strong
	var strong;
	while ( strong = str.match ( /\*([^*\n]*?)\*/ ) )
		str = str.split ( "*" + strong[ 1 ] + "*" ).join ( '<strong>' + strong[ 1 ] + '</strong>' );
	
	// Make linked lists
	var li; var i = 0;
	while ( li = str.match ( /\*\ [\w\W]*?(.*?)\n/ ) )
		str = str.split ( "* " + li[ 1 ] + "\n" ).join ( '<li>' + li[ 1 ] + '</li>' );
	str = str.replace ( /(\<li\>[\w\W]*?)(\<[^l]*?\>)/, "<ul>$1</ul>\n$2" );
	
	// Convert carriage return
	str = str.split ( "\r\n" ).join ( "<br/>" );
	
	return str;
}


function changeProductDetailText ( )
{
	if ( document.body )
	{
		var eles = document.body.getElementsByTagName ( 'div' );
		for ( var a = 0; a < eles.length; a++ )
		{
			if ( eles[ a ].className.indexOf ( 'ProductDetail' ) >= 0 )
			{
				eles[ a ].innerHTML = parseMarkdown ( eles[ a ].innerHTML );
				return;
			}
		}
		return;
	}
	setTimeout ( 'changeProductDetailText ( )', 50 );
}
changeProductDetailText ( );

function InitBlestshoppen ( )
{
	if ( typeof ( BlestBoxSet ) != 'undefined' )
	{
		// Vedtekter		
		var wm = document.getElementById ( 'WebshopOutput__' );
		if ( !wm ) wm = document.getElementById ( 'WebModule__' );
		
		var base = document.getElementsByTagName ( 'base' );
		base = base[ 0 ].href;
		
		// Set some blestbox options
		BlestBoxSet ( 'background-opacity', 0.9 );
		BlestBoxSet ( 'graphics-path', base + 'gfx' );
		BlestBoxSet ( 'background-color', '#ffffff' );
		BlestBoxSet ( 'shadowbackground-color', '#000000' );
		BlestBoxSet ( 'framebackground-color', '#ffffff' );
		BlestBoxSet ( 'page-width', 640 );
		BlestBoxSet ( 'page-height', 480 );
	}
	else
	{
		setTimeout ( 'InitBlestshoppen ( )', 50 );
	}
}
InitBlestshoppen ( );


