var $j = jQuery.noConflict();

$j(document).ready(function(){

  //Colorboxes
  $j(".disclaimer").colorbox();

  // Image Slider
  var count_windows = $j("ul#gallery li").length;
  if(count_windows > 1)
  {
    for(var i = 2; i <= count_windows; i++)
    {
      $j("#gallery_" + i + " p").hide();
      $j("#gallery_" + i + " h4").hide();
      $j("#line_" + i + " img").hide();
      $j("#flash_" + i).hide();
      $j("#bottom_left_" + i).hide();
      $j("#bottom_right_" + i).hide();
    }
    var position = 1;
    // Show first window
    $j("#gallery #gallery_1 p").show();
    $j("#gallery #gallery_1 h4").show();
    $j("#line_1 img").show();
    // Arrows
    $j("#gallery_right").show();
    // Right Arrow click
    $j("#gallery_right").click(function(){
      position++; // Increment current position
      if(position < count_windows)
      {
        // Hide current box
        $j("#gallery_" + --position + " h4").hide();
        $j("#gallery_" + position + " p").hide();
        $j("#line_" + position + " img").hide();
        $j("#flash_" + position).hide();
        $j("#bottom_left_" + position).hide();
        $j("#bottom_right_" + position).hide();
        // Show current box
        $j("#gallery_" + ++position + " h4").show();
        $j("#gallery_" + position + " p").show();
        $j("#line_" + position + " img").show();
        $j("#flash_" + position).show();
        if (noLeftFade(position)) {
          $j("#bottom_left_" + position).show();
        } else {
          $j("#bottom_left_" + position).fadeIn();
        }
        if (noFade(position)) {
          $j("#bottom_right_" + position).show();
        } else {
          $j("#bottom_right_" + position).fadeIn();
        }
        // Show previous link
        $j("#gallery_left").show();
      }
      else if(position == count_windows)
      {
        // Hide current box
        $j("#gallery_" + --position + " h4").hide();
        $j("#gallery_" + position + " p").hide();
        $j("#line_" + position + " img").hide();
        $j("#flash_" + position).hide();
        $j("#bottom_left_" + position).hide();
        $j("#bottom_right_" + position).hide();
        // Show current box
        $j("#gallery_" + ++position + " h4").show();
        $j("#gallery_" + position + " p").show();
        $j("#line_" + position + " img").show();
        $j("#flash_" + position).show();
        $j("#gallery_right").hide();
        if (noLeftFade(position)) {
          $j("#bottom_left_" + position).show();
        } else {
          $j("#bottom_left_" + position).fadeIn();
        }
        if (noFade(position)) {
          $j("#bottom_right_" + position).show();
        } else {
          $j("#bottom_right_" + position).fadeIn();
        }
      }
      //alert(position);
      return false;
    });

    $j("#gallery_left").click(function(){
      position--; // Decrement current position
      if(position > 1)
      {
        // Hide current box
        $j("#gallery_" + ++position + " h4").hide();
        $j("#gallery_" + position + " p").hide();
        $j("#line_" + position + " img").hide();
        $j("#flash_" + position).hide();
        $j("#bottom_left_" + position).hide();
        $j("#bottom_right_" + position).hide();
        // Show current box
        $j("#gallery_" + --position + " h4").show();
        $j("#gallery_" + position + " p").show();
        $j("#line_" + position + " img").show();
        $j("#flash_" + position).show();
        if (noLeftFade(position)) {
          $j("#bottom_left_" + position).show();
        } else {
          $j("#bottom_left_" + position).fadeIn();
        }
        if (noFade(position)) {
          $j("#bottom_right_" + position).show();
        } else {
          $j("#bottom_right_" + position).fadeIn();
        }
        // Show next link
        $j("#gallery_right").show();
      }
      else if(position == 1)
      {
        $j("#gallery_left").hide();
        $j("#gallery_next").show();
        // Hide current box
        $j("#gallery_" + ++position + " h4").hide();
        $j("#gallery_" + position + " p").hide();
        $j("#line_" + position + " img").hide();
        $j("#flash_" + position).hide();
        $j("#bottom_left_" + position).hide();
        $j("#bottom_right_" + position).hide();
        // Show current box
        $j("#gallery_" + --position + " h4").show();
        $j("#gallery_" + position + " p").show();
        $j("#line_" + position + " img").show();
        $j("#flash_" + position).show();
        if (noLeftFade(position)) {
          $j("#bottom_left_" + position).show();
        } else {
          $j("#bottom_left_" + position).fadeIn();
        }
        if (noFade(position)) {
          $j("#bottom_right_" + position).show();
        } else {
          $j("#bottom_right_" + position).fadeIn();
        }
      }
      //alert(position);
      return false;
    });

  }
  else if(count_windows == 1)
  {
    $j("#gallery #gallery_1 h4").show();
    $j("#gallery #gallery_1 p").show();
    $j("#line_1 img").show();
  }
});

function noFade(position) {
  if (cat == "home" || cat == "tena" || (cat == "producten" && position != 4) || cat == "samen") {
    return true;
  } else {
    return false;
  }
}

function noLeftFade(position) {
  if (cat == "producten" && position != 4) {
    return true;
  } else {
    return false;
  }
}
