var flowCFmax = 0;
var flowUTmax = 0;
var flowmax = 0;
var automatic=0;
var trigger=0;


jQuery(document).ready(function() {
	
  if (flowCFmax == 0) jQuery("#leftCF").css( "background-image", "url(typo3conf/ext/pflow/img/button_links_inaktiv.jpg)");
  if ((flowCFend+3) < 4) jQuery("#rightCF").css( "background-image", "url(typo3conf/ext/pflow/img/button_rechts_inaktiv.jpg)");

    
  jQuery("#leftCF").hover(function (){
		    if (flowCFmax > 0) jQuery(this).css( "background-image", "url(typo3conf/ext/pflow/img/button_links_aktiv.jpg)"); 
    }, function(){ 
        if (flowCFmax > 0) jQuery(this).css( "background-image", "url(typo3conf/ext/pflow/img/button_links_inaktiv.jpg)"); 
    });

    
	jQuery("#rightCF").hover(function (){
		    if (flowCFmax < flowCFend) jQuery(this).css( "background-image", "url(typo3conf/ext/pflow/img/button_rechts_aktiv.jpg)"); 
    }, function(){ 
        if (flowCFmax < flowCFend) jQuery(this).css( "background-image", "url(typo3conf/ext/pflow/img/button_rechts_inaktiv.jpg)"); 
    });

    jQuery.preloadImages("typo3conf/ext/pflow/img/button_rechts_aktiv.jpg",
                    "typo3conf/ext/pflow/img/button_rechts_inaktiv.jpg",
                    "typo3conf/ext/pflow/img/button_links_aktiv.jpg",
                    "typo3conf/ext/pflow/img/button_links_inaktiv.jpg");
  
  window.setTimeout("beRightCF(1)",5000);
  
});

function beLeftCF(trigger){

  if (flowCFmax <= 0) {
  
  } else {
    if (trigger == 1 && automatic == 1){
    } else {
    
      jQuery("#rightCF").css({ "backgroundImage": "url(typo3conf/ext/pflow/img/button_rechts_inaktiv.jpg)" });
      jQuery("#flowCF").animate({left: "+=860px"}, 500 );
      flowCFmax--;
      if (flowCFmax == 0) {
        jQuery("#leftCF").css({ "backgroundImage": "url(typo3conf/ext/pflow/img/button_links_inaktiv.jpg)" });
      }
      if (automatic == 0 && trigger == 1) {
        if (flowCFmax == 0) {
          window.setTimeout("beRightCF(1)",5000);
        } else {
          window.setTimeout("beLeftCF(1)",5000);
        }
      }
      if (trigger == 99) {
        automatic = 1;
      }
    }
  }
}

function beRightCF(trigger){

  if (flowCFmax >= flowCFend) {
  
  } else {
    if (trigger == 1 && automatic == 1){
    } else {
  
      jQuery("#flowCF").animate({left: "-=860px"}, 500 );
      jQuery("#leftCF").css({ "backgroundImage": "url(typo3conf/ext/pflow/img/button_links_inaktiv.jpg)" });
      flowCFmax++;
      if (flowCFmax == flowCFend) {
        jQuery("#rightCF").css({ "backgroundImage": "url(typo3conf/ext/pflow/img/button_rechts_inaktiv.jpg)" });
      }
    
      if (automatic == 0 && trigger == 1) {
        if (flowCFmax == flowCFend) {
          window.setTimeout("beLeftCF(1)",5000);
        } else {
          window.setTimeout("beRightCF(1)",5000);
        }
      }
      if (trigger == 99) {
        automatic = 1;
      }
    }
  }

  
}

function skipper(target){

  if (target>flowCFmax){
    // alert(flowCFmax+"/"+target);
    var steps = target-flowCFmax;
    for (x=0;x<steps;x++) { beRightCF(99); }
  } else if (target<flowCFmax) {
    var steps = flowCFmax-target;
    for (x=0;x<steps;x++) { beLeftCF(99); }
  } else {
  
  }
    

}

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}
