/**
 * All toolbox functions wrapped in this object
 */
var Toolbox = {
	
	/**
	 * Initializes the toolbox
	 */
	init: function(){
	
		$('#toolbox #login>a').click( function(evt){
			$('#toolbox #sub1:visible, #toolbox #sub2:visible').length ? Toolbox.reset() : Toolbox.openLogin();
			return false;
		});
		
		$('#toolbox #cart>a').click( function(evt){
			$('#toolbox #sub3:visible').length ? Toolbox.reset() : Toolbox.openCart();
			return false;
		});

		$('#toolbox .close, #toolbox .cartclose').click(function(evt){
			Toolbox.reset();
			return false;
		});
		
	},
	
	/**
	 * Activates the login layer
	 */
	openLogin: function(){
		Toolbox.reset();
		$('#toolbox').addClass('loginActive');
		
		//if( '1' == document.location.params.loggedout ){
		if( $('body').hasClass("home") ){
			// is logged out
			$('#sub1').hide('fast');
			$('#sub2').slideDown('fast');
		} else {
			// is logged in
			$('#sub1').slideDown('fast');		
			$('#sub2').hide('fast'); 
		}
	},
	
	/**
	 * Activates the cart layer
	 */
	openCart: function(){
		Toolbox.reset();
		$('#toolbox').addClass('cartActive');
		$('#sub3').slideDown('fast');
	},
	
	/**
	 * Reset all layers
	 */
	reset: function(){
		$('#toolbox').removeClass('loginActive');
		$('#toolbox').removeClass('cartActive');
		$('#sub1').hide('fast');
		$('#sub2').hide('fast');
		$('#sub3').hide('fast');
	}
}

// init when document is ready
$(document).ready(function(e){
	Toolbox.init();
});

$(document).ready(function(e){
	$('#newsletterform input[type=text]').blur(function() {
		if( $(this).attr('value') == '' ) { $(this).attr('value', $(this).attr('name')); }
	});
	$('#newsletterform input[type=text]').focus(function() {
		$(this).attr('value', '');
	});
	$('a.info').colorbox({width:"550px", height:"400px", iframe: "true" });	
});
