
function theRotator() {
	//Set the opacity of all images to 0
	$('div#photo ul li').css({opacity: 0.0});

	//Get the first image and display it (gets set to full opacity)
	$('div#photo ul li:first').css({opacity: 1.0});

	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds

	$(document).everyTime(3000,"slider",function(){
		rotate();
	});

}

function rotate() {	
	//Get the first image
	var current = ($('div#photo ul li.show')?  $('div#photo ul li.show') : $('div#photo ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#photo ul li:first') :current.next()) : $('div#photo ul li:first'));	

	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	$('div.indicatorActive').removeClass("indicatorActive").addClass("indicator");
	$('div[num='+$(next).attr("num")+']').addClass("indicatorActive");
	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');

};

function showSlidePhoto(num){
	$(document).stopTime("slider");
	$('div.indicatorActive').removeClass("indicatorActive").addClass("indicator");

	$('div[num='+num+']').addClass("indicatorActive");
	$("div#photo ul li").animate({opacity: 0.0}, 1000).removeClass('show');
	$('div#photo ul li[num='+num+']').css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	$(document).everyTime(3000,"slider",function(){
		rotate();
	});


}

$(document).ready(function() {		
	//Load the slideshow
	theRotator();
});

$(document).ready(function(){	
	$("#newsSlider").easySlider();
});

function sendMessage(){

	$.get("/sendMail.php?"+$("#kontaktai").serialize(),function(data){
		$("#responder").fadeOut("slow",function(){


			if(data=="OK"){
				$( "form" )[ 0 ].reset();
				$("#responder").html("Jūsų žinutė sėkmingai išsiųsta.").addClass("success").removeClass("error").fadeIn("slow");
			}else{
				$("#responder").html(data).removeClass("success").addClass("error").fadeIn("slow");
			}
		});
	});

	return false;

}

function filtruoti(kategorija){



	if(kategorija=="all"){
		if($("#filtravimoSelectas").val() == "") {
			window.location="/naudotu-motociklu-pardavimas/"; 
		}else{
			window.location="/naudotu-motociklu-pardavimas/kubatura/"+$("#filtravimoSelectas").val()+"cc/"; 
		}
	}else{
		if($("#filtravimoSelectas").val() == "") {
			window.location="/naudotu-motociklu-pardavimas/tipas/"+kategorija+"/"; 
		}else{
			window.location="/naudotu-motociklu-pardavimas/tipas/"+kategorija+"/kubatura/"+$("#filtravimoSelectas").val()+"cc/"; 
		}
	}

}
$(document).ready(function(){
	$('.popup_link').popupWindow({ 
		height:500, 
		width:800, 
		centerBrowser:1, 
		centerScreen:1
	});	


});


$(document).ready(function(){
	var height = $(window).height();
	var sidebar = $("#sidebar").height();
	if(sidebar<height)
	$("#sidebar").css("height",(height-184)+"px");
});