/**
 * helpform constructor creates a dynamic form for showing a popup with related content
 * @author Tom Cool @ FrenzyMedia B.V. - http://frenzymedia.eu
 * @class Namespace object
 * @constructor
 * @param {jQuery} $ The jQuery object - to prevent conflicts with similar libraries
 */
var helpform = (function ($) {

	/**
	 * Additional css-selectors are stored seperately
     * @namespace Private properties
     */
	var selectors = {
		form :		'form#helpform',
		options :	'.helpform_radio',
		checkbox :	'input:checkbox',
		submit	:	'helpform_submit',
		selected :	'selected'
	},

	/**
     * @namespace Private properties and methods
     */
	privs = {
		
		/*
		 * sets radiobuttun to 'checked within the form
		 */
		setOption : function () {
			$(selectors.options).click( function () {
				
				$(this).toggleClass(selectors.selected);
				
				var checkbox = $(selectors.checkbox, this);

				if (checkbox.is(':checked')) {
					checkbox.removeAttr('checked');
				} else {
					checkbox.attr('checked','true');
				}
				
				privs.updatePopupLink(this.id);
			});
		},
		
		/*
		 * passes additional options to contact form
		 */
		updatePopupLink : function (name) {
			
			var link = document.getElementById(selectors.submit),
				search = link.href.split('?'),			
				keys = search[1].split('&'),
				values = [],
				i = 0,
				j = 0;
			
			for ( n = keys.length; i < n; i++ ) {
				values[i] = keys[i].split('=');
				if (values[i][0] == name) {
					values[i][1] = (values[i][1] == 'true') ? 'false' : 'true';
				}
			}
			
			for ( n = values.length; j < n; j++ ) {
				values[j] = values[j].join('=');
			}

			link.href = search[0] + '?' + values.join('&');
		}
	};

	/**
	 * @namespace Public properties and methods
     * @scope log
     */
	return {

		/*
		 * function initiated on body onload
		 */
		initiate : $(function () {
			privs.setOption();
		})
	};

})(jQuery);
