; //in honor of the mergin-god

/*
 * google preparing
 */
var _gaq = window._gaq || [];
_gaq.push(['_setAccount', 'UA-1247751-1']);
_gaq.push (['_gat._anonymizeIp']);

/*
 * for modus-changing in css
 */
(function($) {
	var getParamModus = location.search.match(/gp-modus=(\w+)/i);
	if(getParamModus != null){
		$('html').addClass(getParamModus[1]);
	}
})(jQuery);


jQuery(function($) {
	
	$.debug(true);
	$.log('GP is started ...DB-Mode');

	// get all nav-element which has li children
	// other have no menu
	
	//var $hoverable = $('#nav>ul>li>ul>li').parent().closest('li');
	var $hoverable = $('#nav>ul>li');
	var $on = $('#nav>ul>li.on');
	$.log($on);
	//$hoverable = $('#nav>ul>li');
	
	if (true) { //}!Modernizr.touch){
		$hoverable.on({
			mouseover: function () {
				$('ul', this).css('top', '52px');
				$on.removeClass('on');
				//$hoverable.addClass('on');
			},
			mouseout: function () {
				$('ul', this).css('top', '-1000px');
				$on.addClass('on');
				//$hoverable.removeClass('on');
			},
	
		});
	}
	else {/*
		$('a', $hoverable).removeAttr('href');
		$hoverable.on({
			click: function () {
				var ul = $('ul', this);
				if(ul.css('top') == '-1000px') {
					ul.css('top', '52px');
				} else {
					ul.css('top', '-1000px');
				}
			}
		});*/
		$hoverable.on({
			touchstart: function (event) {
				event.preventDefault();
				$on.removeClass('on');
				$('ul', this).css('top', '52px');
			},
			touchend: function (event) {
				//event.preventDefault();
				$on.addClass('on');
				$('ul', this).css('top', '-1000px');
				$e = $(event.target);
				$.log($e.html());
				if(typeof($e.attr('href')) == 'string') {
					//location.href = $e.attr('href');
				}
			}	
		});	
	}
	
	// go back
	$('#breadcrumb').prepend('<span><a href="/" class="LOCATION_BACK">&larr;zurück</a></span> || ');
	$('.LOCATION_BACK').on('click', function(){
		history.back();
	});
	
	
	
	/*
	 * google 
	 */

	_gaq.push(['_trackPageview']);
	var google_file = 'ga.js';
	if($.cookie('gp_debug_ga') != null){
		google_file = 'u/ga_debug.js'; // for debuging;
	}
	//async loading
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/'+google_file;
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);	
});
