
RASA = {};

RASA.parseUri = function  (str) {
	var	o   = RASA.parseUri.options,
	m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
	uri = {},
	i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

RASA.parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&)([^&=]*)=?([^&]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};

RASA.url = RASA.parseUri( document.location );

RASA.openDialog = function(dialog) {
	$(dialog).dialog("open");
}





$.datepicker.setDefaults({
	firstDay: 1,
	dateFormat: "dd.mm.yy",
	regional: 'no'
});


$(document).ready(function(){
	$(".btn").button();
	
	$('ul.toggleroot li').click(function() {
		$(this).children('.toggle').toggle();
		return false;
	}).children('.toggle').hide();

	$(".datepicker").datepicker({
		firstDay:1,
		showWeek:true,
		changeMonth: true,
		changeYear: true,
		dateFormat: "dd.mm.yy"
	});
	$(".radiobuttonset").buttonset();

	$('#frontpageimages').cycle({
    fx:     'fade',
    speed: 2500,
    random: 1,
    timeout: 8000
	});

	$('input.number').focus(function(){
		$(this).select();
	});


	// dialog
	$("div.rasadialog").each(function() {
		var dialogWidth = "384px";
		if($(this).css("width")){
			dialogWidth = $(this).css("width");
		}
		$(this).dialog({
			"position": ["center","center"],
			autoOpen: false,
			width: dialogWidth
		});

	});

	// dialog starter with popup
	$(".rasapopup").click(function(el) {
		var url = RASA.parseUri( this.href );
		if( url.anchor && $("#"+url.anchor).hasClass("rasadialog")){
			RASA.openDialog($("#"+url.anchor));
		}
		return false;
	});

	// url popup
	if (RASA.url.anchor && $("#"+RASA.url.anchor).hasClass("rasadialog")){
		RASA.openDialog($("#"+RASA.url.anchor));
	}

});



