$(document).ready(function(){
	var br_height = $(window).height();
	$('body').height(br_height);
	$(window).resize(function () {
		br_height = $(window).height();
		$('body').height(br_height);
	});

    function carousel() {
        var thumbs  = $('#gallery ul li a');
        thumbs.each(function(i) {
            $(thumbs[i]).click(function() {
                $("#resimgoster img").animate({
                    'opacity': .1
                }, 300, function() {
                    $(this).attr('src',thumbs[i].href).show('fast', function() {
                        $(this).load(function() {
                            $(this).animate({
                                'opacity': 1
                            }, 800);
                        });
                    });
                });
                return false;
            });
        });
    }
    carousel();
    var prev    = $("#slidePrev");
    var next    = $("#slideNext");
    var liSize  = 166;
    var margin  = 0;
    var marginTotal = $("#gallery #thumbsHolder ul li").length * liSize;
    prev.click(function() {
        if(margin < 0) {
            margin  = margin + liSize;
            $("#gallery #thumbsHolder ul").animate({
                'left': margin + 'px'
            });
        }
        return false;
    });
    
    next.click(function() {
        if((margin-liSize) > -(marginTotal-(liSize*5))) {
            margin  = margin - liSize;
            $("#gallery #thumbsHolder ul").animate({
                'left': margin + 'px'
            });
        }
        return false;
    });
    
});
