$(document).ready(function(){
/*The counter variable counts the pictures which */
var counter = $('#undermask ul').children().size();
var count = counter +1;
/*This variable is neccessary for correct work*/
var switcher = 0;
var creatbtn = "";
var lightisopen = 0;
/*This function is for the slide effect.*/
$(function() {
    $("#undermask").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		btnGo: ["#0","#1","#2","#3","#4","#5","#6","#7","#8","#9"],
	  beforeStart: function(a) {
	  
if (switcher == 1) 
{
active ++;
}else{
active --;
}
    },
    afterEnd: function(a) {
    }
    });	
});

var active = 1;
/*descriptionpart This is for refreshing the title and the description if you click on next or bevore buttons*/
var desc = $( $('#undermask ul li').children()[active +3]).attr("title");
$('#desc .inner a').attr("href", $( $('#undermask ul li').children()[active +3]).attr("href"));
$('#desc .inner a').html($( $('#undermask ul li a').children()[active +3]).attr("title"));
$('.description').html($( $('#undermask ul li').children()[active +3]).attr("alt"));

$('.next').click(function() {
if (active == count) 
{

active = 1;
var desc = $( $('#undermask ul li').children()[active +3]).attr("title");
$('#desc .inner a').attr("href", $( $('#undermask ul li').children()[active +3]).attr("href"));
$('#desc .inner a').html($( $('#undermask ul li a').children()[active +3]).attr("title"));
$('.description').html($( $('#undermask ul li').children()[active +3]).attr("alt"))

}else{

var desc = $( $('#undermask ul li').children()[active +3]).attr("title");
$('#desc .inner a').attr("href", $( $('#undermask ul li').children()[active +3]).attr("href"));
$('#desc .inner a').html($( $('#undermask ul li a').children()[active +3]).attr("title"));
$('.description').html($( $('#undermask ul li').children()[active +3]).attr("alt"))

}

});

$('.prev').click(function() {
if (active == 0) 
{
active = count-1;
var desc = $( $('#undermask ul li').children()[active +3]).attr("title");
$('#desc .inner a').attr("href", $( $('#undermask ul li').children()[active +3]).attr("href"));
$('#desc .inner a').html($( $('#undermask ul li a').children()[active +3]).attr("title"));
$('.description').html($( $('#undermask ul li').children()[active +3]).attr("alt"))
}else{

var desc = $( $('#undermask ul li').children()[active +3]).attr("title");
$('#desc .inner a').attr("href", $( $('#undermask ul li').children()[active +3]).attr("href"));
$('#desc .inner a').html($( $('#undermask ul li a').children()[active +3]).attr("title"));
$('.description').html($( $('#undermask ul li').children()[active +3]).attr("alt"))

}


});

if ( $('#jquery-lightbox').is(':visible') ) { 
}else{
switcher = 0;
		$('.arrowleftover').animate({ 
        opacity: 0
      }, 100 ).animate({ 
        opacity: 1
      }, 100 ); 
	   $('.prev').click();
	   }

if ( $('#jquery-lightbox').is(':visible') ) { 
}else{
switcher = 1;
		$('.arrowrightover').animate({ 
        opacity: 0
      }, 100 ).animate({ 
        opacity: 1
      }, 100 ); 
	   $('.next').click();

}  
});
