function smartphone_check() {
	
	if (document.referrer.indexOf('mobile.html') != -1) { 
		var switch_to_full = true;
	}
	
	else {
		var switch_to_full = false;
	}

	if( (switch_to_full == false) && DetectSmartphone()){
		window.location = "/mobile.html";
	}

}













function dom_init() {
$(document).ready(function(){



	/* =============================================================
	
		cache
	
	============================================================= */

	var win = $(window);
	var bridge = $('.bridge');
	var subnav_item = $('li h3 a');
	var go_next = $('.go-next');
	var go_prev = $('.go-prev');





	/* =============================================================
	
		highlight active nav item
	
	============================================================= */
	
	var bridge_active_nav = function() {

		bridge.each(function () {

			var section_id = $(this).next('section').attr('id');
			$(this).attr('id', 'above-'+section_id);

		});

	}
	
	
	
	
	


	/* =============================================================
	
		close current article and open next one
	
	============================================================= */
	
	var go_article = function(close, open) {
		// close
		close.hide();

		// remove active class
		var where = close.parent().attr('id');
		$('#'+where+' li h3 a').removeClass('active');
		
		// open
//		open.fadeIn(700,'easeInOutQuart');
		open.show();

		// add active class
		var add = open.attr('id');
		add = '.go-'+add;
		$(add).addClass('active');


		// positioning
		article_aside();	
	}
	
	
	
	
	

	/* =============================================================
	
		logic for subnav & content slider
	
	============================================================= */

	var article_nav = function() {
			
			
		// subnav for multiple articles in one section
		subnav_item.click(function () {

			var article_id = $(this).attr('class').replace('go-','');
			var section_id = $(this).closest('section').attr('id');

			var current_article = $('#'+section_id+' article:visible');
			var next_article = $('#'+article_id);
			
			// dont close and open if current and next article are the same
			if ( $(this).hasClass('active') == false ) {
				go_article(current_article, next_article);
			}
			
	    });
	    
	    
		// navigate throught articles using next button
		go_next.click(function () {

			var section_id = $(this).closest('section').attr('id');
			var current_article = $('#'+section_id+' article:visible');

			// if current article is the last one, start over with the first one
			if( current_article.hasClass('last') == true ) {
				var next_article = $('#'+section_id+' .primary');
			}
			
			else {
				var next_article = current_article.next('article');
			}
			
			go_article(current_article, next_article);	

		});


		// navigate throught articles using prev button
		go_prev.click(function () {

			var section_id = $(this).closest('section').attr('id');
			var current_article = $('#'+section_id+' article:visible');

			// if current article is the first one, start over with the last one
			if( current_article.hasClass('primary') == true ) {
				var prev_article = $('#'+section_id+' .last');
			}
						
			else {
				var prev_article = current_article.prev('article');
			}

			go_article(current_article, prev_article);

		});



	}
	
	
	
	
	
	/* =============================================================
	
		open impressum layer
	
	============================================================= */
	
	var go_impressum = function() {
		$('#go-impressum').click(function () {
			$('#impressum').fadeIn(700,'easeInOutQuart');
						
			$('#close-impressum').click(function () {
				$('#impressum').fadeOut(700,'easeInOutQuart');
			});
			
		});
	}





	/* =============================================================
	
		pseudo parallax
	
	============================================================= */
	
	var pseudo_parallax = function() {

		var bg_shadow = $('#bg-shadow');
		
		win.scroll(function() {
			var pos_y = win.scrollTop();
			var new_y = (2800 - pos_y);
		
			bg_shadow.css('background-position', 'center -' + new_y + 'px');
		});	

	}





	/* =============================================================
	
		position prev, next buttons
	
	============================================================= */
	
	var content_slider = function(article_set, article_parent, offset) {

		var t = 0;
		var t_elem;
		
		$('#'+article_set).each(function () {
			var elem = $(this);
				
			if ( elem.outerHeight() > t ) {
				t_elem = this;
				t = elem.outerHeight();
    		}
		});

		var new_top = offset + (t / 2);
				
		$('#'+article_parent+' .go-prev, #'+article_parent+' .go-next').css({
			'top': new_top+'px'
		});

	}





	/* =============================================================
	
		workarounds & fixes
	
	============================================================= */
	
	var article_aside = function() {
	
		/*
		 * wrap a div around article text, then wrap list of services
		 * inside an aside while keeping it simple for the content editor
		 */		
		$('#leistungen article h4:visible, #leistungen article ul:visible').wrapAll('<aside />');
		$('#leistungen article p:visible').wrapAll('<div class="text" />');

		/* wrap content of li elements in span in order
		 * to give them a different color than the ul square
		 */
		$('#leistungen article ul li:visible').wrapInner('<span />');

	}
	
	var subnav_first_active = function() {
		$('.subnav li:first-child h3 a').addClass('active');
	}





	/* =============================================================
	
		ipad stuff
	
	============================================================= */

	var gallery_warning = function() {
		$('.theme-default').removeClass('theme-default');
		$('#slider').html('Um die Galerie unserer Projekte zu betrachten, benutzen Sie<br />Ihr iPad bitte im Querformat und laden die Seite neu.');
		
	}



	var ipad_nav = function() {
		
		$('#main').html('Zum Navigieren nach rechts oder links wischen.');
		
		$('section').css({
			'display': 'none'
		})		
		 
	 } /* ipad nav */
		


	var swipe_nav = function() {

			// header data-serial is set to 0
			// increment for each section
			var i_current = 1;
			$('section').each(function() {
				$(this).attr('data-serial', i_current);
				i_current++;
			});

			var swipeOptions = {
				swipe:swipe,
				threshold:100
			}
		
			$(function() {			
				$('header, section:not(#impressum)').swipe( swipeOptions );
			});
		
			function swipe(event, direction) {		

				// get current serial ID
				var current_serial = parseInt($('[data-serial]:visible').attr('data-serial'));
				// only for debugging / var tmp_current_ser = current_serial;
				
				// which helps identify the current section				
				var current_section = $('[data-serial="'+current_serial+'"]').attr('id');
				
				// now identify next and prev section				
				var next_serial = current_serial + 1;
				var prev_serial = current_serial - 1;
				
				// but stop swipe nav after first/last section
				if( prev_serial<0 ) {
					prev_serial = 0;
				}
				
				// where do we actually need to stop
				var limit_serial = i_current - 2;
				
				if( next_serial> limit_serial) {
					next_serial = limit_serial;
				}
				
				var next_section =  $('[data-serial="'+next_serial+'"]').attr('id');
				var prev_section =  $('[data-serial="'+prev_serial+'"]').attr('id');
	
				//alert('current_section: '+current_section+'('+tmp_current_ser+') /// next_section: '+next_section+'('+next_serial+') /// prev_section: '+prev_section+'('+prev_serial+')');
	
				// next page
				if(direction == 'left') {
					$('#'+current_section).animate({
						'left': '-1024px'
					}, 800);
								
					$('#'+current_section).fadeOut(300,'easeInOutQuart');

					if( current_section == 'banner') {
						$('#'+current_section).animate({
							'left': '0'
						}, 0);						
					}
					
					else if( win.width() == 768) {
						$('#'+current_section).animate({
							'left': '0'
						}, 0);						
					}
					
					else {
						$('#'+current_section).animate({
							'left': '62px'
						}, 0);						
					
					}

					$('#'+next_section).fadeIn(700,'easeInOutQuart');


				}
				
				// prev page
				else if(direction == 'right') {
					$('#'+current_section).animate({
						'left': '1024px'
					}, 800);
								
					$('#'+current_section).fadeOut(300,'easeInOutQuart');

					if( current_section == 'banner') {
						$('#'+current_section).animate({
							'left': '0'
						}, 0);						
					}

					else if( win.width() == 768) {
						$('#'+current_section).animate({
							'left': '0'
						}, 0);						
					}
										
					else {
						$('#'+current_section).animate({
							'left': '62px'
						}, 0);						
					
					}

					$('#'+prev_section).fadeIn(700,'easeInOutQuart');

				}
				
			}
		
	} /* swipe nav */

	
	



	/* =============================================================
	
		run functions
	
	============================================================= */

	pseudo_parallax();
	subnav_first_active();
	article_nav();
	article_aside();
	bridge_active_nav();
	go_impressum();

	content_slider('news article', 'news', 0);
	content_slider('leistungen article', 'leistungen', 0);
	
	if(DetectIpad()){
		ipad_nav();
		swipe_nav();
		content_slider('news article', 'news', 165);
	}




	/* =============================================================
	
		run plugins
	
	============================================================= */


	/* nivo */
	win.load(function() {
		$('#slider').nivoSlider({
			effect:'fade',
			pauseTime:5000,
			controlNav:false,
			directionNavHide:false
		});
	});
	
	if(DetectIpad()){
		if ( win.width() == 768 ) {
			gallery_warning();
		}
	}
	
	
	
	/* local scroll */
	$.localScroll({
		offset:-100,
		easing:'easeInOutQuart',
		duration:2000,
		reset:true,
		hash:true,
		stop:true
	});
	
	





});
}
