### About application programming interfaces (APIs)

An API is a way to control an application, or get some info about the data which the application is working with. This is a way to two separate application can work together. LayerSlider has an API too, you can control the slider from outside of the application.

### API methods

- integer: The slider will change to the specified slide. It starts with 1.
- next: The slider will change the next layer.
- prev: The slider will change the previous layer.
- stop: Will stop the slideshow.
- start: Will continue or start the slideshow.
- redraw: Redraws the slider contents and updates its layout.
- data: Will return all the data which LayerSlider is working with. For example you can identify which slide is showing currently, or which one will the next to show.

### Using the API

To run one of the above API command, you have to call the LayerSlider jQuery method on the slider element and pass the command as a parameter. WordPress uses IDs on each slider with the word "layerslider_" and the number of the selected slider.
Example: jQuery('#layerslider_1').layerSlider(2);
This will switch to the second slide. If you want to use this with a link, you can use the following code:
<a href="javascript:void(0);" onclick="$('#layerslider').layerSlider(2);">to slide 2</a>

### Working with LayerSlider data

The LayerSlider data object is a huge collection with all the information you need. We don't have enough space here to list all of the properties you can work with, you have to check them manually. Here are the most important ones:

- curLayer: The current slide DOM element.
- curLayerIndex: The current slide index. Starts with 1.
- nextLayer: The next slide DOM element.
- nextLayerIndex: The next layer index. Starts with 1.
- isAnimating: This property returns whether the slider animating or not with boolean.
- layersNum: Returns the count of layers (slides).

### Callback functions and LayerSlider API

When you request the LayerSlider data object with its API call, you will have the information for that exact moment. When LayerSlider working along, these informations may change or will be outdated. You probably want to use this information in an exact moment, when something just happened, so you have to use the LayerSlider API and the callback events at the same time. To do that, you can use a custom named variable in the callback function header section which will be filled with the data object of LayerSlider. Here is an example of using both with the cbAnimStart event:

    function(data) {
    	alert('The next slide is: ' + data['nextLayerIndex']);
    }

### A more complex example

Here is a more complex example which show which things you can do with our API. This example implement a custom navigation area for a LayerSlider slider.
You can find this example here.