var Local = {

    onCommentReply: function(id) {
		Comments.openReply(id);
	},

    onCancelReply: function(id) {
		Comments.closeReply();
	}

};

var wt = {}; // This is the setup for the webtools namespace

(function() { // This is where jQuery code can safely go without foobarring prototype
	var $ = jQuery
	
	$(document).ready(function() { // These functions get called on DOM ready
		$('a').click(function() { $(this).blur() }) // prevents outlines on links for IE
		wt.heroshots() // Crossfades hero shots if applicable
		$('.main,.sidebar').equalizeCols()
		$('.main,.archives').equalizeCols()
        $('table.zebra').each(function() {$(this).find('tr:odd').addClass('alt')});
	})
	
	$(window).load(function() { // These functions get called when everything has loaded
		
	})
	
	wt.formDefaults = function() { // Swaps default text form input values to blank on focus and back to default text on blur
		$('input:text,textarea').each(function() {
			var elem = $(this)
			var defaultText = elem.val()
			elem.focus(function(){
				if(elem.val() == defaultText) {
					elem.val('')
				}
			})
			elem.blur(function(){
				if(elem.val() == '') {
					elem.val(defaultText)
				}
			})
		})
	}

    wt.heroshots = function() {
    	var heroshots = $('.heroshots');
    	if(!heroshots.size()) { return; }

    	heroshots.each(function() {
    		var heroshot = $(this);
    		var frame = $(jQuery('<div class="frame"></div>'));
    		heroshot.prepend(frame);

    		if(!heroshot.find('input').size()) { return; }

    		var fade = heroshot.find('input[name=fadevalue]').val() * 1000;
    		var dur = heroshot.find('input[name=showvalue]').val() * 1000;
    		heroshot.find('input').remove();

    		var heroes = heroshot.find('img')

    		var images = heroshot.find('img');
    		if(images.size() < 2) { return; }
    		images.css({'display':'none'});
    		images.eq(0).show();
    		if(images.eq(0).parent('a').size()) {
    			frame.bind('click', function() {
    				window.location = images.eq(0).parent('a').attr('href');
    			}).css({'cursor':'pointer'});
    		}

    		setInterval(function(){
    			frame.unbind('click').css({'cursor':'default'});
    			var current = images.filter(':visible');
    			var next = current.parent('a').size() ? (current.parent('a').next('a,img').size() ? current.parent('a').next('a,img') : images.eq(0)) : (current.next('a,img').size() ? current.next('a,img') : images.eq(0));
    			if(next.parent('a').size()) {
    				frame.bind('click', function() {
    					window.location = next.parent('a').attr('href');
    				}).css({'cursor':'pointer'});
    			}
    			if(typeof next[0] != 'undefined' && next[0].nodeName.toLowerCase() == 'a') {
    				frame.bind('click', function() {
    					window.location = next.attr('href');
    				}).css({'cursor':'pointer'});
    				next = next.find('img');
    			}
    			current.fadeOut(fade);

    			next.fadeIn(fade);
    		}, fade + dur);
    	});
    }	

})();