/**
 * @author kchevalier@suntouchdesign.com
 * june2009
 */


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

var Common = {
	
	goodBrowser: true,
	
	init: function() {
		
		// detect good browsers
		if (document.all && !window.opera && !window.XMLHttpRequest) {
			Common.goodBrowser = false;
		}
		
		// remove submit text
		$('.notext input').val('');
		
		// login form
		$('a.loginLink').bind( 'click', function(e) {
			if ( Common.goodBrowser ) {
				e.preventDefault();
				Common.showLogin( e );	
			}
		} );
		$('#closeLogin').bind( 'click', function(e) {
			Common.closeLogin( e );
		} );
		
		// popups
		$('.newWindow').bind( 'click', function(e){
			e.preventDefault();
			Common.newWindow( e, $(this) );
		} );
		
		// breadcrumb dropdown
		if ( Common.goodBrowser ) {
			$('#breadcrumb li ul').css( {  opacity: 0 } );
			$('#breadcrumb').children('li').hover( 
				function() {
					$(this).children('a.topLevel').css( { opacity: 0.8 } );
					$(this).children('ul').animate( { opacity: 0.8 }, 200 );
				},
				function() {
					$(this).children('a').css( { opacity: 1 } );
					$(this).children('ul').css( { opacity: 0 }, 0 ).stop();
				} );
		}
		
		// animate main nav buttons
		$('ul#nav li').css( { backgroundPosition: '0 0' } );
		$('ul#nav li a').bind( 'mouseover', function(e) {
			Common.buttonsSlideUp( e, $(this) );
		} );
		$('ul#nav li a').bind( 'mouseout', function(e) {
			Common.buttonsSlideDown( e, $(this) );
		} );
			
		// IE hacks
		$('#content .purchase tbody img').css( { display: 'block' } );
		
	},
	
	buttonsSlideUp: function( e, obj ) {
		$(obj).css( { height: '29px' } ).parent().stop().css( { backgroundPosition: '0 -45px' } ).animate( { height: '43px', marginTop: '2px' }, 200 );
	},
	
	buttonsSlideDown: function( e, obj ) {
		$(obj).css( { height: '26px' } ).parent().stop().css( { backgroundPosition: '0 0' } ).animate( { height: '40px', marginTop: '5px' }, 150 );
	},

	showLogin: function() {
		$('#content').append( '<div id="darken"></div>' );
		$('#darken').css( 'opacity', 0.5 );
		$('#darken').fadeIn();
		$('#login').fadeIn();
	},
	
	closeLogin: function() {
		$('#login').fadeOut();
		$('#darken').fadeOut();
	},
	
	newWindow: function( e, obj ) {
		window.open( $(obj).attr( 'href' ) );
	}
	
};

