/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
intervalID = false;
tmp = '';
$(document).ready(function (){
    $(".sl").hide();
    $(".sl:first").show("slow");
    $("#allPhoto").html($(".sl").length);
    $("#currentPhoto").html("1");
    $("#slprev").click(function (){
        if ($(this).attr('rel')!='clicked'){
            sliderPrev();
        }
    });
    $("#slnext").click(function (){
        if ($(this).attr('rel')!='clicked'){
            sliderNext();
        }
    });
    $(".slimg").click(function (){
        if ($("#slnext").attr('rel')!='clicked'){
            sliderNext();
        }
    });
    $("#slideshowbtn").click(function (){
        if (intervalID){
            clearInterval(intervalID);
            intervalID = false;
            $(this).removeClass("slideron");
            $(this).html(tmp)
        }else{
            intervalID = setInterval("sliderNext()",2500);
            $(this).addClass("slideron")
            tmp = $(this).html()
            $(this).html($("#slideshowbtnon").val());
        }
    });

    $('img').mousedown(function(e) {
        if (e.which === 3) {
            /* Right Mousebutton was clicked! */
            alert('Apsaugota Autorių teisių!\n Nuotraukas galite įsigyti Fotodiena.lt \n Ačiū');
            $(this)[0].oncontextmenu = function() {
					return false;
				}
            return false;
        }
    });

})

function sliderNext(){
        if ($(".sl:visible").next().hasClass('sl')){
            $("#slnext").attr('rel','clicked');
            $("#currentPhoto").html(parseInt($("#currentPhoto").html())+1);
            $(".sl:visible").hide("slow");
            $(".sl:visible").next().show("slow",function(){
                $("#slnext").removeAttr("rel");
            });
            return true;
        }else{
            return false;
        }
}

function sliderPrev(){
        if ($(".sl:visible").prev().hasClass('sl')){
            $("#slprev").attr('rel','clicked');
            $("#currentPhoto").html(parseInt($("#currentPhoto").html())-1);
            $(".sl:visible").hide("slow");
            $(".sl:visible").prev().show("slow",function (){
                $("#slprev").removeAttr("rel");
            });
           
            return true;
        }else{
            return false;
        }
}

