var curObj;
(function($){
    var random = 0;
    $.expr[':'].random = function(a, i, m, r) {
        if (i == 0) {
            random = Math.floor(Math.random() * r.length);
        }
        return i == random;
    };
})(jQuery);
$(document).ready(function(){
	var curObj = $("#mycrawler a:random");
	$("a.thumbs").click(function(){
		if (typeof(curObj) == "object" && !$(this).children("img").hasClass('cur')){
			$("#mycrawler img").removeClass("cur");
			if (curObj != this){
				var largePath = $(this).attr("href");
				var largeAlt = $(this).attr("title");
				curObj = this;
				$("#display_galery").fadeOut("slow", function(){
					$("#display_galery").attr({ src: largePath, alt: largeAlt }).load(function(){$("#display_galery").fadeIn("slow");});
				});
				$(this).children("img").addClass('cur');
				curObj = $(this);
			}
		}
		return false;
	});
	$(".arrow_left").click(function(){
		$("#mycrawler a:first-child").clone(true).insertAfter("#mycrawler a:last-child");
		$("#mycrawler a:first-child").remove();
    });
	$(".arrow_right").click(function(){
		$("#mycrawler a:last-child").clone(true).insertBefore("#mycrawler a:first-child");
		$("#mycrawler a:last-child").remove();
    });
	if (curObj){
		curObj.trigger("click");
		$(curObj).clone(true).insertBefore("#mycrawler a:first-child");
		$(curObj).remove();
	}
});

