﻿function addEffects( context )
{
	if (typeof(context) == 'undefined') {
		context = '';
	} else {
		context += ' ';
	}

	$(context + '.button').hover( function() {
		$(this).addClass('hover');
		if ($(this).hasClass( 'pushed_' )) {
		  	$(this).addClass( 'pushed' );
		}
	}, function() {
		$(this).removeClass('hover');
		$(this).removeClass( 'pushed' );
	} ).mousedown( function() {
		$(this).addClass( 'pushed' ).addClass( 'pushed_' );
	}).mouseup( function() {
		$(this).removeClass( 'pushed' ).removeClass( 'pushed_' );
	});
	$('#body').mouseup( function() {
		$('.button').removeClass( 'pushed' ).removeClass( 'pushed_' );
	} );
}

$(document).ready( function() {
	$('table.index tr').hover( function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	} );

	if ( $.browser.msie ) {
	    $('body').addClass('msie');
	    $('body').addClass('msie' + $.browser.version.replace('.','_') );
	    $('body').addClass('msie' + $.browser.version.substr(0,$.browser.version.indexOf('.')) );
	}
	if ( $.browser.mozilla ) {
	    $('body').addClass('mozilla');
	}

	addEffects();
} );


function createEditorConfig( addButtons, saveCallback, cancelCallback )
{
	if (typeof( addButtons ) == 'undefined') {	addButtons = false;	}

	editorConfig = {
		css: path + 'styles/editor.css',
		controls : { }
	};

	if (addButtons) {
		editorConfig.controls['khtmlSep'] = { separator : true };
		editorConfig.controls['save'] = {
				visible   : true,
				exec      : saveCallback,
				className : 'postSaveBtn'
			};
		editorConfig.controls['close'] = {
				visible   : true,
				exec      : cancelCallback,
				className : 'postCancelBtn'
			};
	}

	return editorConfig;
}

function createWYMEditorConfig( extraSettings )
{
	if ( typeof( extraSettings ) == 'undefined' ) {
		extraSettings = '<div class="extraEditorSettings" id="extraEditorSettings">&nbsp;</div>'
	}
	editorConfig = {
		stylesheet: path + 'styles/editor.css',
		lang: 'sv',
		jQueryPath: path + 'scripts/lib/jquery.js',
	    classesHtml:       "<div class='wym_classes wym_section'>"
	                        + "<h2>{Classes}</h2><ul>"
	                        + WYMeditor.CLASSES_ITEMS
	                        + "</ul></div>"
							+ extraSettings,
        postInit: function(wym) {
            //activate 'hovertools' plugin
            //which gives advanced feedback to the user:
            wym.hovertools();
            wym.resizable({handles: "s,e",
                           maxHeight: 900});
			//adjust the editor's height
			jQuery(wym._box).find(wym._options.iframeSelector)
			    .css({'width': '99%', 'height': '420px'});
			//render the containers box as a panel
			//and remove the span containing the '>'
			//jQuery(wym._box).find(wym._options.containersSelector)
			setTimeout( function() {
				$('.wym_containers')
				    .removeClass('wym_dropdown');
				$('.wym_containers')
				    .addClass('wym_panel');
				$('.wym_containers h2 > span').remove();
			}, 500 )

        }

	};
/*
	if (addButtons) {
		editorConfig.controls['khtmlSep'] = { separator : true };
		editorConfig.controls['save'] = {
				visible   : true,
				exec      : saveCallback,
				className : 'postSaveBtn'
			};
		editorConfig.controls['close'] = {
				visible   : true,
				exec      : cancelCallback,
				className : 'postCancelBtn'
			};
	}*/

	return editorConfig;
}

