$(document).ready(function() {

	$('#content .content-single, .content-col3').hide();

	function getUrlVars()
	{
	    var vars = [], hash;
	    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	    for(var i = 0; i < hashes.length; i++)
	    {
	        hash = hashes[i].split('=');
	        vars.push(hash[0]);
	        vars[hash[0]] = hash[1];
	    }
	    return vars;
	}

  
    // Navigation Microsite
    $('.jump').click(function() {
        var anchor = $(this).attr('rel');
		var header = 225;
        scroller(anchor,header);
        document.title = $(this).html() + ' - Process Consulting';
		
        return false;
    });
	
    // Scroller
    function scroller(anchor,header) {
        //var header = 168;
        var newpos = $(anchor).offset().top - header;

        $('html:not(:animated),body:not(:animated)').animate({scrollTop:newpos}, 1000);
    }

	function scrollersingle(header){
	    var newpos = header;
        $('html:not(:animated),body:not(:animated)').animate({scrollTop:newpos}, 1000);
	}
    
	
    $('.accordion-col3').toggle(
        function() {
            var anchor = '#' + $(this).parent().parent('div').attr('id');
            var header = 168;
            $(this).next('.content-col3').slideDown('normal');
            $(this).addClass('active');
            scroller(anchor, header);

            return false;
        },
        function(e) {
            $(this).next('.content-col3').slideUp('fast');
            $(this).removeClass('active');
        }
    );

    
	// Open links in a new window
	$('a.button').attr('target', '_blank');
    
    $('.accordion-single').click(function() {
//        var anchor = '#' + $(this).next('.content-single').attr('id');
   //   var anchor = $(this).next('.content-single').position().top;
        var anchor = '#'+$(this).parent('div').attr('id');
        var header = 255;
        $('.accordion-single').removeClass('active');
        $('.content-single').slideUp('normal');
		
        if ($(this).next().is(':hidden') == true) {
            $(this).addClass('active');
            $(this).next().slideDown('normal');
       }
	 scroller(anchor,header);

	 return false;
    });
    
    
    

    // Accordion
   /* $('.accordion').click(function() {
        var anchor = '#' + $(this).next('.content').attr('id');

        $('.accordion').removeClass('active');
        $('.content').slideUp('normal');

        if ($(this).next().is(':hidden') == true) {
            $(this).next().slideDown('normal', function() {
                scroller(anchor);
            });

            $(this).addClass('active');
        }
 
        return false;
    });*/

    // Hash
    /*if (window.location.hash) {
        var anchor = window.location.hash;
        /*var accordiontitle = $(anchor).prev('.accordion');

        accordiontitle.siblings().removeClass('active');

        $(anchor).slideDown('normal', function() {
            scroller(anchor);
        });
		scroller(anchor);
        //accordiontitle.addClass('active');
    }*/



    // Karriere Banner
    $('.col5 a').click(function() {
        var anchor = $(this).attr('rel');
		var header = 168;
        scroller(anchor,header);

        return false;
    });

    // Sub-Navigation 
    $('.nav1 .activepath ul li a, .subnav a').click(function() {
        var anchor = $(this).attr('rel');
        var accordiontitle = $(anchor).prev('.accordion');
        var header = 168;

        //accordiontitle.siblings().removeClass('active');

        /*$(anchor).siblings('.content').slideUp('normal');
        if ($(anchor).is(':hidden')){
            $(anchor).slideDown('normal', function() {
                scroller(anchor);
            });
        }
		
        accordiontitle.addClass('active');*/
        scroller(anchor,header);

        return false;
    });

});

$(window).load(function() {
		function getUrlVars()
		{
		    var vars = [], hash;
		    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		    for(var i = 0; i < hashes.length; i++)
		    {
		        hash = hashes[i].split('=');
		        vars.push(hash[0]);
		        vars[hash[0]] = hash[1];
		    }
		    return vars;
		}
	    function scroller(anchor) {
	        var header = 168;
	        var newpos = $(anchor).offset().top - parseInt(168);
	
	        $('html:not(:animated),body:not(:animated)').animate({scrollTop:newpos}, 1000);
	    }
	//	var anchor = window.location.hash;
		if(getUrlVars()["sub"]){
			var anchor = '#'+getUrlVars()["sub"]
			scroller(anchor);
		}
});
