/* custom JS for index.php */

$(function() {
	if(window.location.search) {
		var arrQuery = parseQuery(window.location.search);
		//console.log(arrQuery);
		for(i = 0; i < arrQuery.length; i++) {
			if(arrQuery[i][0] == 'from') {
				var strReferrer = arrQuery[i][1];
			}
			if(arrQuery[i][0] == 'was') {
				var strJumpTo = arrQuery[i][1];
			}
		}

		if(strJumpTo) {
			window.location.href='#' + strJumpTo;
		}

		if(strReferrer) {
			switch(strReferrer) {
				case 'wg-gesucht':
					$('#form-contact-subject').val('WG-Suche');
					$('#form-contact-realname').focus();
					break;
				case 'wg-gruendung':
					$('#form-contact-subject').val('WG-Gründung');
					$('#form-contact-realname').focus();
					break;
			}
		}
	}

	$('#contact-protector-im').replaceWith('<p><img src="images/x.gif" width="150" height="14" id="data-protector2" class="data-protector" alt="(ICQ)" /><br /><img src="images/x.gif" width="150" height="14" id="data-protector3" class="data-protector" alt="(Jabber)" /></p><div id="modal-window-content-placeholder" style="display:none"><p><input type="text" style="width: 200px; border: 1px solid #999; background-color:#000; color: #fff;" size="50" /></p></div>');


	$('#organoprotector').click(function() {
		$('#form-contact-realname').focus();
	});

	$('#data-protector2').hover(function() {
		$(this).addClass('cursorPointer');
	}, function() {
		$(this).removeClass('cursorPointer');
	}).click(function() {
		//$(this).after('<div id="modal-win1" style="display:none"><p>77'+ '72' + '8' + '907' + '</p></div>');
		tb_show('ICQ', '#TB_inline?height=50&width=300&inlineId=modal-window-content-placeholder');
		$('#TB_ajaxContent input').val('77'+ '72' + '8' + '907');
	});

	$('#data-protector3').hover(function() {
		$(this).addClass('cursorPointer');
	}, function() {
		$(this).removeClass('cursorPointer');
	}).click(function() {
		//$(this).after('<div id="modal-win2" style="display:none"><p></div>'); //jab'+ 'bb' + 'e' + 'r' + '@fw' + 'olf.'+'de</p>
		tb_show('Jabber-ID','#TB_inline?height=50&width=300&inlineId=modal-window-content-placeholder');
		$('#TB_ajaxContent input').val('jab'+ 'bb' + 'e' + 'r' + '@fw' + 'olf.'+'de');
		return false;
	});


	$('#contact-data-adr').attr('title', 'Karte anzeigen').hover(function() {
		$(this).addClass('cursorPointer');
	}, function() {
		$(this).removeClass('cursorPointer');
	}).click(function() {
		tb_show('OpenStreetMap: W&uuml;rzburgerstr. 5, Uffenheim', 'http://fwolf.info/6.5/osmwrapper.php/osm.jpg');
	});
	/*
	static map:
	http://old-dev.openstreetmap.org/~pafciu17/?module=map&lon=10.22781021558&lat=49.546172780928&zoom=17&width=800&height=600&imgType=jpg*/

	// currently dysfunctional
	/*.click(function() {
		tb_show('OpenStreetMap: W&uuml;rzburgerstr. 5, Uffenheim', 'http://fwolf.info/6.5/osm.html?keepThis=true&TB_iframe=true&height=600&width=800');


	});*/

/*
	$.getScript('includes/js/com.bydust.array.js');

	$.getScript('includes/js/parttimetranslation.js', function() {
		$('div#navigation').append('<ul id="nav-translation"><li id="translate-english"><a href="#translate-english"><img src="http://i.f2w.de/icon/famfamfam/flag/png/gb.png" alt="English" title="Translate content partially to english" /></a></li><li id="translate-german"><a href="#translate-german" title="Anzeige auf Deutsch (Standard)"><img src="http://i.f2w.de/icon/famfamfam/flag/png/de.png" /></a></li></ul>');

		$('#translate-english').click(function() {
			addPartTimeTranslation('en');
		});

 		$('#translate-german').click(function() {
 			removePartTimeTranslation();
 		});
	});
*/

});




/**
 * function parseQuery
 *
 * @description Parses the GET query into an multidimensioal array
 * @parameter string Query
 * @return array ParsedQuery Consists of ParsedQuery[n] = array(0 => varName, 1 => varValue)
 */

function parseQuery(strUserQuery) {
	returnData = new Array();
	strQueryString = strUserQuery;

	if(strUserQuery.substr(0, 1) == '?') {
		strQueryString = strUserQuery.substr(1);
	}

	if(strQueryString != '') {
		arrX = strQueryString.split('&');

		for(n = 0; n < arrX.length; n++) {
			arrX2 = arrX[n].split('=');
			returnData[n] = new Array(arrX2[0], arrX2[1]);
		}

	}


	return returnData;
}