// milliseconds
var slideshow_fadingspeed = 2000;
var slideshow_pause = 5000;

$(document).ready(function() {

 
        $(".internal-link-new-window").fancybox({
                'width'    : 700,
                'height'  : 600,
                'autoScale'  : false,
                'transitionIn'  : 'none',
                'transitionOut'  : 'none',
                'type'    : 'iframe'
        }); 
  
    
// Slideshow der Startseite
$('#coin-slider').bxSlider({
        mode: 'fade',
        speed: slideshow_fadingspeed,
        pause: slideshow_pause,
        auto: true,
        controls: false,
        auto_direction: 'left',
        next_text: 'next image',
        prev_text: 'previous image',
        width: 950,
        wrapper_class: 'ssc'
});

if($('#standbild img').length > 1) {
    $('#standbild ').bxSlider({
        mode: 'fade',
        speed: slideshow_fadingspeed,
        pause: slideshow_pause,
        auto: true,
        controls: false,
        auto_direction: 'left',
        next_text: 'next image',
        prev_text: 'previous image',
        width: 950,
        wrapper_class: 'ssc'
    });
}

$('.ReferenzContainer .ReferenzElement').each(function () {

    var theLink = $(this).find(".RElink").children();
    var theImage = $(this).find(".REimage").children();
    var theInfo = $(this).find(".REinfo").html();

    $(this).find(".RElink").remove();
    $(this).find(".REimage").remove();
    $(this).find(".REinfo").remove();

    $(theLink).html('');
  
    $(this).append(theLink);
    $(theLink, this).attr("title", theInfo);
    $(theLink, this).append(theImage);
    
});

if($('.Projektpresenter').length > 1) {
  $('.ssNextBtn').css('display','block');  
        
        $('.ssNextBtn').unbind('click');
        $('.ssPrevBtn').unbind('click');

        var anzahl_pp = $('.Projektpresenter').length
        var curPos = 1;
        $('.ssContent').css('width', anzahl_pp*920 + 'px');

        $('.ssNextBtn').click(function() {

           curPos++;

           $('.ssContent').animate( {'left': '-=920px' }, 150 );
           $('.ssPrevBtn').css('display','block');

           if( curPos == anzahl_pp ) {
               $('.ssNextBtn').css('display','none');
           }

       });

       $('.ssPrevBtn').click(function() {

            curPos--;

            $('.ssContent').animate( {'left': '+=920px' }, 150 );

            $('.ssNextBtn').css('display','block');

            if( curPos == 1 ) {
                $('.ssPrevBtn').css('display','none');
            }

       });        
        
}

$('.Projektpresenter .qitem').each(function () {

    var theLink = $(this).find(".plink").children();
    var theCurtain = $(this).find(".pimage").children();

    $(this).find(".plink").remove();
    $(this).find(".pimage").remove();
    $(theLink).html('');
  
    $('.caption', this).before(theLink);
    $(theLink, this).append(theCurtain);
    
    var a=1;
    
});

$(".jTscroller .link").each(function() {

    var theLink = $(this).children();
    var theImage = $(this).next().children();
    
    $(this).next().remove();
    $(this).remove();

    $(theLink).html('');
  
    $(".jTscroller").append(theLink);
    $(theLink).append(theImage);

});

// Thumbnailscroller auf der Startseite
$("#tS2").thumbnailScroller({ 
        scrollerType:"clickButtons", 
        scrollerOrientation:"horizontal", 
        scrollSpeed:2, 
        scrollEasing:"easeOutCirc", 
        scrollEasingAmount:600, 
        acceleration:4, 
        scrollSpeed:800, 
        noScrollCenterSpace:10, 
        autoScrolling:1, 
        autoScrollingSpeed:60000, 
        autoScrollingEasing:"linear", 
        autoScrollingDelay:500 
});


$('#socials [img src][title]').qtip({
   content:  {text: false},
   position: {my: 'middle right',  // Position my top left...
              at: 'middle right',
               adjust: {x: -50 , y:0}},
   style:    {classes: '  ui-tooltip-blue ui-tooltip-rounded'}
});

$('#navi2 a[href][title]').qtip({
   content:  {text: false},
   position: {
              my: 'bottom right',  // Position my top left...
              at: 'bottom right',
               adjust: {x: -90 , y:-28}},
   style:    {classes: ' ui-tooltip-blue ui-tooltip-rounded'}
});

$('#navi [img src][title]').qtip({
   content:  {text: false},
   position: {my: 'top center',  // Position my top left...
              at: 'top center',
               adjust: {x: 0 , y:20}},
   style:    {classes: '  ui-tooltip-blue2 ui-tooltip-rounded'}
});

//Custom settings
var style_in = 'easeOutBounce';
var style_out = 'jswing';
var speed_in = 1000;
var speed_out = 300;  

//Calculation for corners
var neg = Math.round($('.Projektpresenter .qitem').width() / 2) * (-1);  
var pos = neg * (-1);  
var out = pos * 2;

$('.Projektpresenter .qitem').each(function () {

        url = $(this).find('a').attr('href');
        img = $(this).find('img').attr('src');
        alt = $(this).find('img').attr('img');
        contentWidth = $('.caption', this).children('img').width();
        contentHeight = $('.caption', this).children('img').height();

        $(this).attr("href", url);
  $(this).attr("target","_top");        

        $('.caption', this).children('img').css("margin-top", (149-contentHeight)/2 +'px' ) ;
        $('.caption', this).children('img').css("margin-left", (213-contentWidth)/2 +'px' ) ;

        $('.curtain', this).remove();
        $(this).find('a').remove();
        
        $(this).append('<div class="topLeft"></div><div class="topRight"></div><div class="bottomLeft"></div><div class="bottomRight"></div>');
        $(this).children('div').css('background-image','url('+ img + ')');

        $(this).find('div.topLeft').css({top:0, left:0, width:pos , height:pos});  
        $(this).find('div.topRight').css({top:0, left:pos, width:pos , height:pos});  
        $(this).find('div.bottomLeft').css({bottom:0, left:0, width:pos , height:pos});  
        $(this).find('div.bottomRight').css({bottom:0, left:pos, width:pos , height:pos});

        // Container in den aktuellen Projekten
        $(this).fancybox({
                'width'    : 800,
                'height'  : 500,
                'autoScale'  : false,
                'transitionIn'  : 'none',
                'transitionOut'  : 'none',
                'type'    : 'iframe'
        }); 

}).hover(
    function () {
        $(this).find('div.topLeft').stop(false, true).animate({top:neg, left:neg}, {duration:speed_out, easing:style_out});  
        $(this).find('div.topRight').stop(false, true).animate({top:neg, left:out}, {duration:speed_out, easing:style_out});  
        $(this).find('div.bottomLeft').stop(false, true).animate({bottom:neg, left:neg}, {duration:speed_out, easing:style_out});  
        $(this).find('div.bottomRight').stop(false, true).animate({bottom:neg, left:out}, {duration:speed_out, easing:style_out});  
    },
    function () {
        $(this).find('div.topLeft').stop(false, true).animate({top:0, left:0}, {duration:speed_in, easing:style_in});  
        $(this).find('div.topRight').stop(false, true).animate({top:0, left:pos}, {duration:speed_in, easing:style_in});  
        $(this).find('div.bottomLeft').stop(false, true).animate({bottom:0, left:0}, {duration:speed_in, easing:style_in});  
        $(this).find('div.bottomRight').stop(false, true).animate({bottom:0, left:pos}, {duration:speed_in, easing:style_in});  
 });
 
$(".qitem").fancybox({
   'width'        : 800,
   'height'      : 500,
   'autoScale'      : false,
   'transitionIn'    : 'none',
   'transitionOut'    : 'none',
   'type'        : 'iframe'
});   



});


// Loewe IT krams
function ELEM_opac(obj, newopac) {
  if (typeof obj == 'object'
      && obj != null
      && (typeof obj.fading == 'undefined'
          || typeof obj.opac == 'undefined'
          || (obj.fading == 'out' && obj.opac > newopac) || (obj.fading == 'in' && obj.opac < newopac))) {
    obj.opac = (newopac < 0 || newopac > 100) ? ((newopac < 0) ? 0 : 100)
        : newopac;
    // newopac = (newopac == 100) ? 99.999 : newopac;
    obj.style.filter = "alpha(opacity:" + newopac + ")";
    obj.style.KHTMLOpacity = newopac / 100;
    obj.style.MozOpacity = newopac / 100;
    obj.style.opacity = newopac / 100;
  }
}

function ELEMID_opac(id, newopac, cmd_after) {
  var obj = document.getElementById(id);
  ELEM_opac(obj, newopac);
  if (typeof cmd_after == 'string' && typeof obj == 'object' && obj != null
      && typeof obj.target == 'number' && obj.target == obj.opac) {
    setTimeout(cmd_after, 0);
  }
}

function ELEM_fade(obj, newopac, stretch, cmd_after) {
  if (typeof obj.id != 'string' || obj.id == '') {
    obj.id = GET_newid();
  }
  if (typeof obj.opac != 'number') {
    obj.opac = 100;
  }
  if (typeof stretch != 'number') {
    stretch = 5;
  }
  var opac = obj.opac;
  var time = 0;
  obj.fading = (opac > newopac) ? 'out' : 'in';
  if (typeof cmd_after == 'string') {
    obj.target = newopac;
    while (opac != newopac) {
      time++;
      opac = (opac > newopac) ? opac - 1 : opac + 1;
      setTimeout('ELEMID_opac(\'' + obj.id + '\', ' + opac + ', "'
          + cmd_after + '")', time * stretch);
    }
  } else {
    while (opac != newopac) {
      time++;
      opac = (opac > newopac) ? opac - 1 : opac + 1;
      setTimeout('ELEMID_opac(\'' + obj.id + '\', ' + opac + ')', time
          * stretch);
    }
  }
}
function ELEMID_fade(id, newopac, stretch, cmd_after) {
  var obj = document.getElementById(id);
  if (typeof obj == 'object' && obj != null) {
    ELEM_fade(obj, newopac, stretch, cmd_after);
  }
}

function ELEM_insertfade(obj, newchild, cmd_after) {
  ELEM_opac(newchild, 0);
  obj.appendChild(newchild);
  if (typeof cmd_after == 'string') {
    ELEM_fade(newchild, 100, 5, cmd_after);
  } else {
    ELEM_fade(newchild, 100);
  }
}

/* Misc */
function GET_newid() {
  x = 'rand_1';
  while (document.getElementById(x)) {
    x = 'rand_' + Math.floor(Math.random() * 100000 + 1);
  }
  return x;
}

function ELEM_pos(obj, x, y) {
  if (typeof obj == 'object' && obj != null) {
    obj.style.left = x + 'px';
    obj.style.top = y + 'px';
  }
}
function ELEMID_pos(id, x, y) {
  var obj = document.getElementById(id);
  ELEM_pos(obj, x, y);
}

function ELEM_display(obj, style) {
  if (typeof obj == 'object' && obj != null) {
    obj.style.display = style;
  }
}
function ELEMID_display(id, style) {
  var obj = document.getElementById(id);
  ELEM_display(obj, style);
}

function PAGE_jump(href) {
  location = href;
}
/* ####################################### */

/** ************************************************************************ */
/* Grafik Menu 1.23 (3-States) - Copyright by Loewel IT - www.loewel-it.de */
/** ************************************************************************ */
function IMGMenu_init(menu_id, path, aktive_href, aktive_fullhref) {
  var objs = document.getElementById(menu_id).getElementsByTagName("a");

  for ( var i = 0; i < objs.length; i++) {
    objs[i].removeChild(objs[i].firstChild);

    if ((typeof aktive_href == 'string' && aktive_href == objs[i].name)
        || (typeof aktive_fullhref == 'string' && aktive_fullhref == objs[i].name)) {
      var img = document.createElement("img");
      img.src = path + '/aktiv/' + objs[i].name + '.png';
      objs[i].appendChild(img);
    }

    else {
      var sub_img = document.createElement("img");
      var top_img = document.createElement("img");

      sub_img.src = path + '/hover/' + objs[i].name + '.png';
      top_img.src = path + '/normal/' + objs[i].name + '.png';

      top_img.name = objs[i].name;

      top_img.onmouseover = function() {
        ELEM_fade(this, 0, 2);
      };
      top_img.onmouseout = function() {
        ELEM_fade(this, 100, 2);
      };

      objs[i].appendChild(sub_img);
      objs[i].appendChild(top_img);
    }
  }
}

/** *********************************************************************** */
/* Slideshow Animation v.2.06 - Copyright by Loewel IT - www.loewel-it.de */
/** *********************************************************************** */
var SLIDE_box, SLIDE_path, SLIDE_images, SLIDE_pos = 0, SLIDE_stretch = 10, SLIDE_timeout = 8000;
function SLIDE_init(id, path, imgarray, stretch, timeout) {
  SLIDE_box = document.getElementById(id);
  SLIDE_path = path;
  SLIDE_images = imgarray;
  if (typeof stretch == 'number') {
    SLIDE_stretch = stretch;
  }
  if (typeof timeout == 'number') {
    SLIDE_timeout = timeout;
  }
  SLIDE_switch();
}

function SLIDE_switch() {
  var aktimg = SLIDE_box.getElementsByTagName("img");
  if (aktimg.length > 1) {
    if (typeof aktimg[0].id != 'string' || aktimg[0].id == '') {
      aktimg[0].id = GET_newid();
    }
    ELEM_fade(aktimg[1], 100, SLIDE_stretch,
        'SLIDE_removeold(\'' + aktimg[0].id + '\')');
  } else if (SLIDE_images.length > 1) {
    if (SLIDE_pos < SLIDE_images.length - 1) {
      SLIDE_pos++;
    } else {
      SLIDE_pos = 0;
    }
    var newimg = document.createElement("img");
    newimg.onload = function() {
      ELEM_opac(newimg, 0);
      SLIDE_box.appendChild(newimg);
      setTimeout('SLIDE_switch()', SLIDE_timeout);
    }
    newimg.src = SLIDE_path + SLIDE_images[SLIDE_pos];
  }
}

function SLIDE_removeold(id) {
  SLIDE_box.removeChild(document.getElementById(id));
  SLIDE_switch();
}

/* ##################################### */

/** *************************************************************************** */
/* Referenz Animation v.1.13 lite - Copyright by Loewel IT - www.loewel-it.de */
/** *************************************************************************** */
var REF_box, REF_run = false;
function REF_switch(src) {
  if (!REF_run || REF_box.getElementsByTagName("img").length == 0) {
    REF_run = true;
    oldimg = REF_box.getElementsByTagName("img");
    if (oldimg.length) {
      if (typeof oldimg[oldimg.length - 1].id != 'string'
          || oldimg[oldimg.length - 1].id == '') {
        oldimg[oldimg.length - 1].id = GET_newid();
      }
      ELEM_fade(oldimg[oldimg.length - 1], 0, 10,
          'REF_removeold(\'' + oldimg[oldimg.length - 1].id + '\')');
    }

    var newimg = document.createElement("img");
    newimg.onload = function() {
      ELEM_opac(newimg, 0);
      REF_box.appendChild(newimg);
      ELEM_fade(newimg, 100);
      REF_run = false;
    }
    newimg.src = src;
  }
}

function REF_removeold(id) {
  var obj = document.getElementById(id);
  if (typeof obj == 'object') {
    REF_box.removeChild(obj);
  }
}

/* ##################################### */

/** ************************************************************** */
/* Unterschiedliches - Copyright by Loewel IT - www.loewel-it.de */
/** ************************************************************** */
var hbox, hlink;
function Hoverbox(hboxid, hlinkid) {
  hbox = document.getElementById(hboxid);
  hlink = document.getElementById(hlinkid);

  hlink.onmouseover = function() {
    ELEM_fade(hlink, 80, 8);
    if (typeof hbox.opac != 'number') {
      ELEM_opac(hbox, 0);
    }
    hbox.style.display = 'block';
    ELEM_fade(hbox, 100, 4);
  }
  hlink.onmouseout = function() {
    ELEM_fade(hbox, 0, 4, "ELEMID_display('" + hbox.id + "', 'none')");
    ELEM_fade(hlink, 100, 8);
  }

}

/* Referenz Special System */
var sref = null;
function sref_init(id, max_x, max_y, path_thumb, path_full) {
  sref = document.getElementById(id);
  if (typeof sref == 'object' && sref != null) {
    sref.max_x = max_x;
    sref.max_y = max_y;
    sref.path_thumb = path_thumb;
    sref.path_full = path_full;
  }
}

function sref_add(src, pos_x, pos_y, target) {
  var thumbimg = document.createElement("img");
  thumbimg.onload = function() {
    ELEM_opac(thumbimg, 0);
    ELEM_pos(thumbimg, pos_x, pos_y);
    thumbimg.onmouseover = function() {
      ELEM_fade(thumbimg, 60);
    }
    thumbimg.onmouseout = function() {
      ELEM_fade(thumbimg, 100);
    }
    thumbimg.title = 'Details ansehen';
    if (typeof target != 'undefined' && target != '') {
      thumbimg.target = 'http://' + target;
    }
    thumbimg.onclick = function() {
      ELEM_opac(thumbimg, 0);
      var fullimg = document.createElement("img");
      fullimg.onload = function() {
        ELEM_opac(fullimg, 0);
        fullimg.style.border = "solid #00879b 1px";
        if ((pos_x + fullimg.width + 2) > sref.max_x) {
          pos_x = sref.max_x - fullimg.width - 2;
        }
        if ((pos_y + fullimg.height + 2) > sref.max_y) {
          pos_y = sref.max_y - fullimg.height - 2;
        }
        ELEM_pos(fullimg, pos_x, pos_y);
        sref.appendChild(fullimg);
        
//        captionwrap = document.createElement("div");
//        captionwrap.style.position = "absolute";
//        captionwrap.style.width = fullimg.width+"px";
//        captionwrap.style.backgroundColor = "#00879B";
//        captionwrap.style.border = "solid #393939 1px";
//        captionwrap.style.textAlign = "center";
//        captionwrap.style.fontSize = "12px";
//        captionwrap.style.fontWeight = "bold";
//        captionwrap.style.lineHeight = "15px"
//        captionwrap.style.color = "#ffffff";
        
        
//        ELEM_pos(captionwrap, pos_x, pos_y + fullimg.height + 2);
//        caption = document.createTextNode('Bitte auf das Bild klicken, um die Seite zu besuchen');
//        captionwrap.appendChild(caption);
//        sref.appendChild(captionwrap);
        
        ELEM_fade(fullimg, 100);
        fullimg.onmouseout = function() {
//          sref.removeChild(captionwrap);
          sref.removeChild(fullimg);
        }
        fullimg.onclick = function() {
          if (typeof thumbimg.target != 'undefined'
              && thumbimg.target != null) {
            window.open(thumbimg.target, "_blank", "");
          } else {
            sref.removeChild(fullimg);
          }
        }
      }
      fullimg.src = sref.path_full + src;
    }
    sref.appendChild(thumbimg);
    ELEM_fade(thumbimg, 100);
  }
  thumbimg.onerror = function() {
    sref_add(src, pos_x, pos_y, target);
  }
  thumbimg.src = sref.path_thumb + src;
}
