
var gallery_images;
var gallery_pegs;
var num_gallery_images;
var cur_gallery_image = 0;
var gallery_interval = 5000;

$(document).ready(function() {
    if($('#image_gallery').size()) { init_gallery(); }
});
function init_gallery() {
    gallery_images = $('#gallery_images img');
    gallery_pegs = $('.image_peg');
    num_gallery_images = $(gallery_images).size();
    setInterval(next_image, gallery_interval)
}
function next_image() {
    $(gallery_images[cur_gallery_image]).css('z-index', 20).fadeOut(400);
    cur_gallery_image++;
    if(cur_gallery_image == num_gallery_images) {
        cur_gallery_image = 0;
    }
    $('.image_peg.current').removeClass('current');
    $(gallery_pegs[cur_gallery_image]).addClass('current');
    $(gallery_images[cur_gallery_image]).css('z-index', 10).show();
    
}
function onSubmitCommentForm(form) {
    $('input[type="submit"]', form).attr('disabled', 'disabled');
    $('.comment_form_message', form).show().html('submitting...');
    var url = '/includes/comments.php?a1=leave-comment';
    var params = $(form).serialize();
    $.post(url, params, function(resp) {
    	if (resp == 'ok') {
    		$('.comment_form_message', form).html('Comment was submitted').delay(4000).fadeOut(1000);
    		form.reset();
    	}
    	else $('.comment_form_message', form).html(resp);
    	$('input[type="submit"]', form).removeAttr('disabled');
    });
}
$(document).ready(function() {
    if ($.browser.msie && parseInt($.browser.version, 10) < 9) {
        $('#logo').hover(function() { 
            $(this).css({ backgroundColor: '#f0f0f0' });
        }, function() {
            $(this).css({ backgroundColor: 'transparent' });
        });
    } else {
        $('#logo').hover(function() { 
            $(this).css({ opacity:0.7 });
        }, function() {
            $(this).css({ opacity:1 });
        });
    }
});

$(document).ready(function() {
    if($('#cat_drop').size()) {
        $('#cat_drop').hover(function() {
            $(this).addClass('hover');
        }, function() {
            $(this).removeClass('hover');
        });
    }
});

$(document).ready(function() {
    $('#ts_bigger').click(function() {
        var body_font_size = parseInt($('body').css('fontSize').substr(0, 2));
        if(body_font_size < 24) {
            $('body').css('fontSize', body_font_size + 1);
        }
    });
    $('#ts_smaller').click(function() {
        var body_font_size = parseInt($('body').css('fontSize').substr(0, 2));
        if(body_font_size > 10) {
            $('body').css('fontSize', body_font_size - 1);
        }
    });
});

$(document).ready(function() {
    $('a img').hover(function() { $(this).css('opacity', 0.8); }, function() { $(this).css('opacity', 1); });
});

$(document).ready(function() {
    var diff = $('#footer_outer').offset().top + $('#footer_outer').height() + parseInt($('#footer_outer').css('paddingBottom').replace('px', '')) - $(window).height();
    if (diff < 0) {
        $('#middle').height($('#middle').height() - diff);
    }
});
