var flowCFmax = 0;
var flowIFmax = 0;
var skipIFmax = 0;
var flowmax = 0;
var activeShow = new Object();
var activeBorder = 0;




$(document).ready(function() {
  // alert(flowIFmax+"/"+flowIFend);
  
  if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPad/i))) {
  $("#untenbox").swipe({
      swipeLeft: function() { beRightIF(); },
      swipeRight: function() { beLeftIF(); }
  });
  
  $(".iconflowDetail").swipe({
      swipeLeft: function() { skipRight(); },
      swipeRight: function() { skipLeft(); }
  });
  }
  
  if (flowIFmax == 0) $("#leftIF").css( "background-image", "url(typo3conf/ext/iconflow/img/schalter_iconflow_links_ki.jpg)");
  if ((flowIFend+10) < 10) $("#rightIF").css( "background-image", "url(typo3conf/ext/iconflow/img/schalter_iconflow_rechts_ki.jpg)");

    
  $("#leftIF").hover(function (){
		    if (flowIFmax > 0) $(this).css( "background-image", "url(typo3conf/ext/iconflow/img/schalter_iconflow_links_aktiv.jpg)"); 
    }, function(){ 
        if (flowIFmax > 0) $(this).css( "background-image", "url(typo3conf/ext/iconflow/img/schalter_iconflow_links_inaktiv.jpg)"); 
    });
    
	$("#rightIF").hover(function (){
		    if (flowIFmax < flowIFend) $(this).css( "background-image", "url(typo3conf/ext/iconflow/img/schalter_iconflow_rechts_aktiv.jpg)"); 
    }, function(){ 
        if (flowIFmax < flowIFend) $(this).css( "background-image", "url(typo3conf/ext/iconflow/img/schalter_iconflow_rechts_inaktiv.jpg)"); 
    });
 

});

function beLeftIF(was){
  link_status = 1;
  if (flowIFmax <= 0) {
  
  } else {
    $(".iconflowDetail").css({ "backgroundImage": "url(typo3conf/ext/iconflow/img/schalter_iconflow_rechts_inaktiv.jpg)" });
    // $("#flowIF").animate({left: "+=92px"}, 500 );
    flowIFmax--;
    if (flowIFmax == 0) {
      $("#leftIF").css({ "backgroundImage": "url(typo3conf/ext/iconflow/img/schalter_iconflow_links_ki.jpg)" });
    }
  }
  setTimeout(function(){ resetLink() }, 1000 );
}

function skipLeft(was){
  
  if (skipIFmax <= 1) {
  
  } else {
    skipIFmax--;
    // $(".iconflowDetail").animate({left: "-=92px"}, 500 );
    $(".iconflowDetail").animate({left: "+=400px", opacity: 0.0}, 400 )
                        .animate({left: "-=400px"}, function() {
                        $(".iconflowDetail").css({ "backgroundImage": "url(uploads/tx_iconflow/"+jumpBI[skipIFmax]+")" })
                                            .animate({opacity: 1.0});
    });
    $("#subTitle").html(subIF[skipIFmax]);                    
    // $("#arrowLeft").html(skipIFmax);

  }
    
}

function beRightIF(was){

  link_status = 1;
  if (flowIFmax >= flowIFend) {
  
  } else {
    $("#flowIF").animate({left: "-=92px"}, 500 );
    $("#leftIF").css({ "backgroundImage": "url(typo3conf/ext/iconflow/img/schalter_iconflow_links_inaktiv.jpg)" });
    flowIFmax++;
    if (flowIFmax == flowIFend) {
      $("#rightIF").css({ "backgroundImage": "url(typo3conf/ext/iconflow/img/schalter_iconflow_rechts_ki.jpg)" });
    }
  }
  setTimeout(function(){ resetLink() }, 1000 );
  
}

function skipRight(was){
  // $("#arrowRight").html(was);
  if ((skipIFmax+1) >= skipIFend) {
  
  } else {
    
    skipIFmax++;
    $(".iconflowDetail").animate({left: '-=400', opacity:0.0}, 400)
                        .animate({left: '+=400'}, function() {
                         
                        $(".iconflowDetail").css({ 'background-image': 'url(uploads/tx_iconflow/'+jumpBI[skipIFmax]+')' });
                        $(".iconflowDetail").animate({opacity:1.0});
    });
                       
    $("#subTitle").html(subIF[skipIFmax]);
                        
    
    // $("#arrowRight").html(skipIFmax);

  }
    
}

function hightLight(id){

  if (id==1) { var idBefore = 11; } else { var idBefore = id-1; }
  if (id==11) { var idNext = 1; } else { var idNext = id+1; }
  
  var imgNext = "#showIF"+idNext;
  var imgBefore = "#showIF"+idBefore;

  var image = "#img"+id;
  var border = "#showIF"+id;
  $(border).animate({width: 100, height:59, left: "-=10px", top: "-=10px"} , 100 );
  $(image).animate({ width: "+=20px", height: "+=20px"}, 100);
  $(imgNext).animate({ opacity: 0.4, left: "+=5px"}, 100);
  $(imgBefore).animate({ opacity: 0.4,  left: "-=5px"}, 100);

}


function resetLink() {
  link_status=0;
}

function lowLight(id){

  if (id==1) { var idBefore = 11; } else { var idBefore = id-1; }
  if (id==11) { var idNext = 1; } else { var idNext = id+1; }
  
  var imgNext = "#showIF"+idNext;
  var imgBefore = "#showIF"+idBefore;

  var image = "#img"+id;
  var border = "#showIF"+id;
  $(border).animate({width: 80, height:39, left: "+=10px", top: "+=10px"} , 100 );
  $(image).animate({ width: "-=20px", height: "-=20px"}, 100);
  $(imgNext).animate({ opacity: 1,  left: "-=5px"}, 1);
  $(imgBefore).animate({ opacity: 1,  left: "+=5px"}, 1);
}

function switchBorder(id, text, image){

  skipIFmax=id;
  
  if (jumpIF[id] != "0") {
    var jumpLink = "/?id="+jumpIF[id]+"&L="+jumpLa[id];
    document.location.href = jumpLink;
    
    
  } else {
  
    if (jumpBI[id] != "") { 
    
      if (jumpLa[id] == "3" ){
        var closeImage = "button_gallery_close_inaktiv.gif";
      } else {
        var closeImage = "button_gallery_close_inaktiv.gif";
      }
      
           
      var fHeight = $(window).height();
      var fWidth = $(window).width();
      $("#layer").animate({ width: fWidth+"px", height: fHeight+"px"}, 5 )
               .animate({ opacity: 1 }, 500);
      $("#layer").html("<div id='stageT'></div><div id='stageV' style='top:"+((fHeight-300)/2)+"px; left:"+((fWidth-400)/2)+"px;'><div id='detailBorder'><div id='ifD' class='iconflowDetail' style='background-position: center; background-repeat: no-repeat; position: relative; margin: 0 auto; width: 100%; top: 150px; height: 1px; width: 1px; opacity: 1; filter: alpha(opacity = 100);'></div></div><div id='subTitle'>"+subIF[id]+"</div><div id='detailBottom'><div id='arrowLeft' onClick='skipLeft();' onMouseover='hoverLeft();' onMouseout='outLeft();'></div><div id='closeDetail' onClick='closeDetail();' onMouseover='hoverClose();' onMouseout='outClose();' style='position: relative; float: left; left: 23px; width: 36px; height: 26px; top: 0px; background-image: url(/typo3conf/ext/iconflow/img/"+closeImage+"); cursor: pointer;'></div><div id='arrowRight' onClick='skipRight();' onMouseover='hoverRight();' onMouseout='outRight();'></div></div></div>");
      $("#stageT").animate({ width: fWidth+"px", height: fHeight+"px"}, 5 )
               .animate({ opacity: 0.9 }, 500);
      $("#detailBorder").css( "background-image", "url(typo3conf/ext/iconflow/img/loading_bar_black.gif)");     
      // alert(jumpBI.length);         
      for(var lo=0; lo<skipIFend; lo++){
        jQuery.preLoadImages("uploads/tx_iconflow/"+jumpBI[lo]);
        // $("#arrowRight").html(lo);
      }
      
      setTimeout(function(){
        $("#detailBorder").css( "background-image", "none");
        $(".iconflowDetail").css( "background-image", "url(uploads/tx_iconflow/"+image+")");
        $(".iconflowDetail").animate({ width: "+=399px", height: "+=299px", top: "-=150px" }, 700);
      }, 2500);

      
              
    }
  
  }
}

function hoverLeft() {
		    $("#arrowLeft").css( "background-image", "url(typo3conf/ext/iconflow/img/button_gallery_left_aktiv.gif)"); 
}

function outLeft(){
        $("#arrowLeft").css( "background-image", "url(typo3conf/ext/iconflow/img/button_gallery_left_inaktiv.gif)"); 
}

function hoverRight() {
		    $("#arrowRight").css( "background-image", "url(typo3conf/ext/iconflow/img/button_gallery_right_aktiv.gif)"); 
}

function outRight(){
        $("#arrowRight").css( "background-image", "url(typo3conf/ext/iconflow/img/button_gallery_right_inaktiv.gif)"); 
}

function hoverClose() {
		    $("#closeDetail").css( "background-image", "url(typo3conf/ext/iconflow/img/button_gallery_close_aktiv.gif)"); 
}

function outClose(){
        $("#closeDetail").css( "background-image", "url(typo3conf/ext/iconflow/img/button_gallery_close_inaktiv.gif)"); 
}

function closeDetail() {
  
  $("#stageT").animate({ opacity: 0 }, 500);
  $("#layer").animate({ opacity: 0 }, 500)
             .animate({ width: "0px", height: "0px"}, 500 )
             .html("");  
  
}

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
