var accordion;
var accordionClicks;
var accordionContents;

window.onDomReady( function() {
	accordionClicks = document.getElementsByClassName('menuitemgroup');
	accordionContents = document.getElementsByClassName('submenu');
	var el = $('item-'+document.parentId)
	//alert( document.parentId );
	var menu = $('menu');
	var items = document.getElementsByClassName('menuitemgroup');
	var i = -1;
	for( i = 0; i < items.length; ++i ) 
	{
		if( items[i].id == 'group-'+document.parentTopId ) break;
	}
	accordion = new Fx.Accordion(accordionClicks, accordionContents, { duration: 200, show: i });
	// The accordion breaks when there are visible menu items that are not on the top level, or first descendant level. 
} );

function initMCE()
{
	if( typeof(tinyMCE) == 'undefined' )
		return;
	tinyMCE.init({
	//theme : 'simple',
		theme : 'advanced',
 //  	theme : 'msb',
		//mode : 'exact',
		mode : 'none',
		relative_urls : false,
		remove_script_host : true,
		content_css: '/css/punch.css',
		language: 'da',
		//document_base_url : "http://www.site.com/path1/"
		//elements : elems,
		//content_css : 'example_advanced.css',
		extended_valid_elements : 'a[href|target|name]',
		plugins: 'style,msblink',
		//plugins : 'table',
		//theme_advanced_buttons3_add_before : 'tablecontrols,separator',
		theme_advanced_buttons3_add : "styleprops",
		theme_advanced_disable: "indent,outdent,cleanup,help,sup,sub,hr,removeformat,strikethrough,visualaid", 
		theme_advanced_buttons1: "bold,italic,underline,separator,formatselect,styleselect,separator,msblink,unlink,separator,code,separator,bullist,numlist,charmap,separator,undo,redo",
		theme_advanced_blockformats : "p,h1,h2,h3,blockquote",
		//theme_advanced_buttons1: "bold,italic,underline,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,formatselect,separator,bullist,numlist,charmap,separator,image,code,separator,undo,redo",
		theme_advanced_buttons2: "",
		theme_advanced_buttons3: "",
		//invalid_elements : 'a',
		theme_advanced_styles : 'Punch Title Black=title_black;Punch Subtitle Black=subtitle_black;Punch Bodycopy Black=bodycopy_black;Punch Title Grey=title_grey;Punch Subtitle Grey=subtitle_grey;Punch Bodycopy Grey=bodycopy_grey;Punch Title Green=title_green;Punch Subtitle Green=subtitle_green;Punch Bodycopy Green=bodycopy_green;Punch Title Pink=title_pink;Punch Subtitle Pink=subtitle_pink;Punch Bodycopy Pink=bodycopy_pink', // Theme specific setting CSS classes
		//execcommand_callback : 'myCustomExecCommandHandler',
		debug : false
		});
}

initMCE();

function msbNewsletterClear()
{
	var el = $('msb_signup');
	el.value = '';
	msbNewsletterBlur( el );
}

function msbNewsletterBlur( el )
{ 
	if( el.value == '' )
	{
		el.value = el.defaultValue;
		el.addClass( 'inactive' );
	}
}

function msbNewsletterFocus( el )
{ 
  if( el.value == el.defaultValue )
  {
	  el.value = '';
	  el.removeClass('inactive');
  }
}

function msbNewsletterSignup()
{
	var el = $('msb_signup');
	new Ajax( '/msb/ajax/mailinglist.php?email='+el.value, {evalScripts: true, update: 'msb_signup_message'}).request();
}

function msbAddToCart( nicename, name, price, check, count, id, shipping )
{
	var count = $( count ).value;
	var customprice = 0;
	if( price == -1 )
	{
		customprice = $('price-'+check).value;
		if( !parseInt( customprice ) > 0 )
		{
			alert( 'Indtast venligst et gyldigt bel&oslash;b st&oslash;rre end 0 kr' );
			return;
		}
	}
	new Ajax( '/msb/ajax/addtocart.php?nicename='+nicename+'&name='+name+'&price='+price+'&check='+check+'&count='+count+'&id='+id+'&customprice='+customprice+'&shipping='+shipping, {evalScripts: true, update: 'msb_short_cart'}).request();
}

function msbFlashShortCart()
{
	var el = $('msb_short_cart');
	if( el )
	{
		alert( 'Varerne blev tilføjet til din indkøbsvogn' );
		var fx = new Fx.Tween( 'msb_short_cart' );
		fx.start( 'background-color', '#ff0', '#fff' );
	}
}

function onFocusSearch( el )
{
	el.style.color = 'black';
	if( el.value == el.defaultValue )
		el.value = ''
	else
		el.select();

}

function onBlurSearch( el )
{
	if( !el.value )
		el.value = el.defaultValue;
	if( el.defaultValue == el.value )
		el.style.color = '#aaa';
	else
	{
		el.style.color = 'black';
	}
}

