if(!jsFrontend) { var jsFrontend = new Object(); }

jsFrontend = {
	debug: false,
	
	init: function() {
		jsFrontend.controls.init();
		jsFrontend.layout.init();
		jsFrontend.commentSettings();
	},

	// default filled in comment settings (author, email, website) are hidden
	commentSettings: function() {
		$('#editCommentSettings a').bind('click', function(event) {
			event.preventDefault();
			$('.alignBlocks').show();
			$('#editCommentSettings').hide();
		});
	},
	
	eof: true
}

jsFrontend.controls =
{
        init: function()
        {
                $('.toggleId').click(function()
                {
                        var self = $(this);
                        var target = $(self.attr('rel'));

                        target.fadeToggle();
                });
        },

        eoo: true
}

jsFrontend.layout = {
	init: function() {
		// updates is a fucked up element, we need to position it with JS
		if($('#sidebar').length > 0) {
			jsFrontend.layout.positionUpdates();
			$(window).resize(jsFrontend.layout.positionUpdates);
		}

		// IE fixes, cause Microsoft's developers suck and can't handle PNG32 the PNGhack is used for IE
		if($('body').hasClass('ie6')) {
			// PNG hack
			DD_roundies.addRule('header, header h1 a, header h2, '+
								'#subHeader, #subHeader h2, '+
								'#content, #content h2, '+
								'#sidebar h2, #updates li span, #sidebar li a, '+
								'#wood, #wood h2, #shelf, #wood .books img, #wood .sites, '+
								'footer, footer a.logo, '+
								'.downloadLarge, .downloadMedium, .button');
		}
		
		// IE-people need to see my rounded corners! It will slow down the browser, muhaha
		if($('body').hasClass('ie')) { DD_roundies.addRule('a.button', '5px'); }
	},
	
	// position the updates
	positionUpdates: function() {
		// calculate left-position
		var left = parseInt($('#main .center').offset().left) + 950 - $('#sidebar').width();
		$('#sidebar').css('left', left);

		// init some vars
		var height = $('#sidebar').height();
		var minHeight = $('#content').height();

		// height
		var documentHeight = $(document).height();
		var usedHeight = parseInt($('header').height()) + parseInt($('#main').height());

		var extraHeight = 0;
		if(usedHeight < documentHeight) { extraHeight = parseInt(documentHeight - usedHeight); }
		
		// calculate height
		var otherBlocks = parseInt($('#wood').height()) + parseInt($('footer').height());
		if($('#subHeader').length > 0 && !$('#subHeader').hasClass('fullWidth')) otherBlocks += parseInt($('#subHeader').height());
		
		if((height - otherBlocks) > minHeight) {
			var newHeight = parseInt(height - otherBlocks - 3 + extraHeight);
			if(jQuery.browser.webkit) { newHeight -= 21 };
			
			// set height
			$('#content').height(newHeight);
		}
		
		// updates should get a new height
		else {
			var newHeight = parseInt(minHeight + otherBlocks + extraHeight); 
			if(jQuery.browser.webkit) { newHeight += 21 };

			if(extraHeight > 0) $('#content').height(minHeight + extraHeight);
			
			// set height
			$('#sidebar').height(newHeight);
		}
		
		if($('#subHeader').length > 0 && $('#subHeader').hasClass('fullWidth')) $('#sidebar').css('top', parseInt($('#subHeader').height() + 51));
	},

	eof: true
}

$(document).ready(function() { jsFrontend.init(); });

