jQuery.noConflict();


var actpage = 1;
var numpages = 0;



var actPopup = '';
var popupStatus = 0;


function loadPopup() {
  //loads popup only if it is disabled
  if(popupStatus==0){
    jQuery("#backgroundPopup").css({
      "opacity": "0.7"
    });
    jQuery("#backgroundPopup").fadeIn("slow");
    jQuery("#"+actPopup).fadeIn("slow");
    popupStatus = 1;
  }
}

function disablePopup(){
  //disables popup only if it is enabled
  if(popupStatus==1){
    jQuery("#backgroundPopup").fadeOut("slow");
    jQuery("#"+actPopup).fadeOut("slow");
    popupStatus = 0;
  }

}

//centering popup
function centerPopup(){
  //request data for centering
  var windowWidth = document.documentElement.clientWidth;
  var windowHeight = document.documentElement.clientHeight;
  var popupHeight = jQuery("#"+actPopup).height();
  var popupWidth  = jQuery("#"+actPopup).width();
  //centering
  jQuery("#"+actPopup).css({
    "position": "absolute",
    "z-index": "200",
    "top": windowHeight/2-popupHeight/2,
    "left": windowWidth/2-popupWidth/2
  });

  //only need force for IE6
  jQuery("#backgroundPopup").css({
    "height": windowHeight
  });

}



function placeImages() {

  // ausrichtung linke spalte
  jQuery("div.anker").each( function(i) {
    var actanker = jQuery(this);
    var id = actanker.attr('id').substr(5);
    var position = actanker.position();
    
    //alert(position.top);

    jQuery("#lc"+id).css({
      "position": "absolute",
      "top": position.top+60,
      "display": "block"
    });

    //alert(position.top);
  });


}

function hideImages() {

  jQuery("div.anker").each( function(i) {
    var actanker = jQuery(this);
    var id = actanker.attr('id').substr(5);

    jQuery("#lc"+id).css({
      "display": "none"
    });

  });


}



jQuery(document).ready(function() {

  hideImages();

  // top navigation
  //jQuery("#topnavigation ul li").eq(0).addClass("ueberuns");
  //jQuery("#topnavigation ul li").eq(1).addClass("leistungen");
  //jQuery("#topnavigation ul li").eq(2).addClass("arbeiten");
  //jQuery("#topnavigation ul li").eq(3).addClass("kontakt");


  setTimeout("placeImages()", 1000);
  
  // slideshow
  
  //numpages = jQuery("div.next a").length;
  numpages = jQuery("div.page").length;

  var pageid = 1;
  jQuery("div.page").each( function(i) {
    var actpage = jQuery(this);
    actpage.attr('id', 'page'+pageid);
    if (pageid == 1) {
      actpage.removeClass('hidden');
    } else {
      actpage.addClass('hidden');
    }
    
    pageid++;

  });

  
  
  /*
  jQuery("div.next a").each( function(i) {
    var actlink = jQuery(this);
    var id_page = actlink.parent().parent().attr('id').substr(4);

    var next = (id_page == numpages) ? 1 : (id_page*1)+1;

    actlink.attr("href", "javascript:void(0);");

    actlink.click( function() {
      jQuery("#page"+id_page).fadeOut("slow");
      jQuery("#page"+next).fadeIn("slow");
    });

  });
  */


  var actlink = jQuery("#nextpage");
  actlink.attr("href", "javascript:void(0);");

  actlink.click( function() {
    var next = (actpage == numpages) ? 1 : (actpage*1)+1;
    jQuery("#page"+actpage).fadeOut("slow");
    jQuery("#page"+next).fadeIn("slow");
    //jQuery("#page"+actpage).hide();
    //jQuery("#page"+next).show();
    actpage = next;
  });

  var actlink2 = jQuery("#nextpage2");
  actlink2.attr("href", "javascript:void(0);");

  actlink2.click( function() {
    var next = (actpage == numpages) ? 1 : (actpage*1)+1;
    jQuery("#page"+actpage).fadeOut("slow");
    jQuery("#page"+next).fadeIn("slow");
    //jQuery("#page"+actpage).hide();
    //jQuery("#page"+next).show();
    actpage = next;
  });
  
  var prevlink = jQuery("#prevpage");
  prevlink.attr("href", "javascript:void(0);");

  prevlink.click( function() {
    var prev = (actpage == 1) ? numpages : (actpage*1)-1;
    jQuery("#page"+actpage).fadeOut("slow");
    jQuery("#page"+prev).fadeIn("slow");
    actpage = prev;
  });

  var prevlink2 = jQuery("#prevpage2");
  prevlink2.attr("href", "javascript:void(0);");

  prevlink2.click( function() {
    var prev = (actpage == 1) ? numpages : (actpage*1)-1;
    jQuery("#page"+actpage).fadeOut("slow");
    jQuery("#page"+prev).fadeIn("slow");
    actpage = prev;
  });



  jQuery("div.openpopup a").each( function(i) {
    var actlink = jQuery(this);
    var id_content = actlink.parent().attr('id').substr(5);

    actlink.attr("href", "javascript:void(0);");

    actlink.click( function() {
      actPopup = id_content;
      centerPopup();
      loadPopup();
    });

  });

  var closelink = jQuery("#popupClose");
  closelink.attr("href", "javascript:void(0);");

  closelink.click(function(){
    disablePopup();
  });

  //Click out event!
  jQuery("#backgroundPopup").click(function(){
    disablePopup();
  });

  jQuery(".popupContent a").click(function(){
    disablePopup();
  });


});
