var current_active = '';
var nxshow_timer = false;
var links_blocked = false;

function showActive(active_link, first_call) {
 if (current_active == active_link) return;

 links_blocked = true;
 window.setTimeout(function(){links_blocked = false;}, 1200);

 if (current_active) {
  if (current_active=='contact') {window.setTimeout(function(){$('#map').get(0).innerHTML='';}, 300);}

  animateLink($('#link-'+current_active).get(0), 0, -1);
  $('.page-pic').css({zIndex: 1});
  
  if (nxshow_timer) window.clearTimeout(nxshow_timer);
  $('#nx-'+current_active).hide();
  $('#cl-'+current_active).stop(true, true);
  $('#cl-'+current_active).delay(300).slideUp(300);
  $('#cr-'+current_active).stop(true, true);
  $('#cr-'+current_active).slideUp(300);

  $('#bg-'+current_active).css({zIndex: 2});
 }
 current_active = active_link;

 $('#link-'+current_active).get(0).blur();
 animateLink($('#link-'+current_active).get(0), 0, 1);

 if (! first_call) {
  $('#cl-'+current_active).stop(true, true);
  $('#cl-'+current_active).delay(1000).slideDown(1000);
  $('#cr-'+current_active).stop(true, true);
  $('#cr-'+current_active).delay(1500).slideDown(1000);
  nxshow_timer = window.setTimeout(function(){$('#nx-'+current_active).show();nxshow_timer = false;}, 2500);

  $('#bg-'+current_active).stop(true, true);
  $('#bg-'+current_active).hide();
  $('#bg-'+current_active).css({zIndex: 3, height: '340px'});
  $('#bg-'+current_active).delay(350).fadeIn(1200);

 } else {
  $('#cl-'+current_active).slideDown(1000);
  $('#cr-'+current_active).delay(500).slideDown(1000);
  nxshow_timer = window.setTimeout(function(){$('#nx-'+current_active).show();nxshow_timer = false;}, 1500);

 }
}


var steps = [-21, -17, -13, -9, -5, -1, 3, 7, 11, 15];
var steps_c = ['000000','1a0303','330606','4d0909','660c0c','800f0f','991111','b31414','cc1717','e61a1a','ff1d1d'];

function animateLink(aobj, frame, dir) {
 aobj.style.backgroundPosition = '0px '+steps[((dir==1) ? frame : steps.length-1-frame)]+'px';
 aobj.style.color = '#'+steps_c[((dir==1) ? frame : steps_c.length-1-frame)];
 frame++;
 if (frame <= steps.length) {
  window.setTimeout(function(){animateLink(aobj, frame, dir);}, 50);
 }
}


function goAbout() {
 if (links_blocked) return false;
 showActive('about');
 return false;
}

function goServices() {
 if (links_blocked) return false;
 showActive('services');
 return false;
}

function goProjects() {
 if (links_blocked) return false;
 showActive('projects');
 $('#more-link').show();
 $('#more-projects').hide();
 return false;
}

function goContact() {
 if (links_blocked) return false;
 showActive('contact');
 window.setTimeout(function(){$('#map').get(0).innerHTML='<iframe width="440" height="290" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.de/maps?source=s_q&amp;f=q&amp;hl=de&amp;geocode=&amp;q=Hauptst%C3%A4tter+Stra%C3%9Fe+121,+Stuttgart&amp;aq=0&amp;sll=48.770075,9.175508&amp;sspn=0.023957,0.052228&amp;vpsrc=6&amp;ie=UTF8&amp;hq=&amp;hnear=Hauptst%C3%A4tter+Stra%C3%9Fe+121,+Stuttgart+70178+Stuttgart,+Baden-W%C3%BCrttemberg&amp;t=m&amp;ll=48.769598,9.172554&amp;spn=0.01584,0.03768&amp;z=14&amp;output=embed&amp;iwloc=none"></iframe>';}, 1550);
 return false;
}

document.write('<sty'+'le>.content-left, .content-right {display: none;}<'+'/style>');


function initAll() {
 $('a.zoom').click(function(){
  return showPic(this);
 });
 $('#piccontent').click(function(){
  $('#piccontent').fadeOut(150);
  $('#picoverlay').fadeOut(150);
 });
}

function showPic(link) {
 $('#piccontent').get(0).style.backgroundImage = 'none';
 $('#piccontent').get(0).style.backgroundImage = 'url('+link.href+')';
 $('#piccontent').fadeIn(300);
 $('#picoverlay').fadeIn(300);
 return false;
}

document.write('<div id="piccontent"></div><div id="picoverlay"></div>');
