/* markblasius.com global.js */

$(document).ready(function(){

// simple check for touch devices
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))||(navigator.userAgent.match(/Android/i))) {
		var isTouchScreen = 1;
	}
	else {
		var isTouchScreen = 0;
	}

	if (isTouchScreen) {

	}
	else {
		// animate scroll top
		$(window).scroll(function(){
			if($(window).scrollTop() > 400){
				$('#scrolltop').fadeIn(100);
			}
			else {
				$('#scrolltop').fadeOut(100);
			}
		});

		// animate top headline
	//	$('body#upfront #top h1').css('opacity', 0).delay(800).fadeTo(400, 1);

		// scroll top
		$('#scrolltop').click(function(){
			$('html, body').animate({scrollTop:0}, 500);
			return false;
		});
	}

// scroll to ...
	$('ul#recent a, ul#nav a.resumelink, #top h1 a.resumelink, #top h1 a.contactlink').anchorScroll();

// show/hide imprint
		$('a#showhideimprint').click(function(){
			$('#imprint').slideToggle(200);
			$('html, body').animate({scrollTop: 60000}, 500);
			return false;
		});

// layout fixes
	$('#recentteaser a:nth-child(4n)').css('margin-right','0');
	$('#selectedlisting a:nth-child(4n)').css('margin-right','0');

	// no dotted outline on hover, focus
	$('a').focus(function() {
  		$(this).blur();
	});

});

// additional plugins
(function($){
    $.fn.anchorScroll = function(options) {
        var defaults = {
            speed: 800,
            fx: "jswing"
        };
        //var version =  "1.0";
        var options = $.extend(defaults, options);
        return $(this).each(function(){
            var element = this;


            $(element).click(function (event) {

                var locationHref = window.location.href;
                var elementClick = $(element).attr("href");

                var destination = $(elementClick).offset().top;

                $("html,body").animate({ scrollTop: destination}, options.speed,  options.fx);

                //Stop links default events
                event.preventDefault();
                return false;
            })
        })
    }
})(jQuery);
