// BEGIN LOAD FUNCTIONS
RDJ.attachEvent( window, 'load', function() {
	// HEADER SCRIPTS
	
	var hi = RDJ.$('header-image');
        if( !hi ) return;
	var his = hi.src;
	
	var tw = null;
	var wwa = RDJ.$('nr-aboutus-link');
	var wws = RDJ.$('who-we-are-subnav');

    var to = null;
	var oha = RDJ.$('nr-parties-link');
	var ohs = RDJ.$('our-happenings-subnav');

	var ws = null;
	var wsa = RDJ.$('nr-weeks-link');
	var wss = RDJ.$('weekly-selections-subnav');
	
	function clearTime() {
		clearTimeout( ws ); 
		clearTimeout( tw ); 
		clearTimeout( to );
	}
	
	function showUs() {
		clearTime();
		
		hi.src = 'http://www.newreleasenewyork.net/images/site/elements/header-who.png';
		
		wws.style.visibility = 'visible'; 
		ohs.style.visibility = 'hidden'; 
		wss.style.visibility = 'hidden';
	}
	
	function hideUs() {
		tw = setTimeout( function() { wws.style.visibility = 'hidden'; }, 100 );
		
		hi.src = his;
	}

	RDJ.attachEvent( wwa, 'mouseover', showUs );
	RDJ.attachEvent( wws, 'mouseover', showUs );
	RDJ.attachEvent( wwa, 'mouseout', hideUs );
	RDJ.attachEvent( wws, 'mouseout', hideUs );
	
	function showParty() {
		clearTime();
		
		hi.src = 'http://www.newreleasenewyork.net/images/site/elements/header-parties.png';
		
		ohs.style. visibility = 'visible'; 
		wws.style.visibility = 'hidden'; 
		wss.style.visibility = 'hidden';
	}
	
	function hideParty() {
		to = setTimeout( function() { ohs.style.visibility = 'hidden'; }, 100 );
		
		hi.src = his;
	}
	
	RDJ.attachEvent( oha, 'mouseover', showParty );
	RDJ.attachEvent( ohs, 'mouseover', showParty );
	RDJ.attachEvent( oha, 'mouseout', hideParty );
	RDJ.attachEvent( ohs, 'mouseout', hideParty );

	function showWeek() { 
		clearTime();
		
		hi.src = 'http://www.newreleasenewyork.net/images/site/elements/header-weeks.png';
		
		wss.style. visibility = 'visible'; 
		wws.style.visibility = 'hidden'; 
		ohs.style.visibility = 'hidden';
	}
	
	function hideWeek() { 
		ws = setTimeout( function() { wss.style.visibility = 'hidden'; }, 100 );
		
		hi.src = his;
	}
	
	RDJ.attachEvent( wsa, 'mouseover', showWeek );
	RDJ.attachEvent( wss, 'mouseover', showWeek );
	RDJ.attachEvent( wsa, 'mouseout', hideWeek );
	RDJ.attachEvent( wss, 'mouseout', hideWeek );

	// MAILING LIST BOX
	var lbb = RDJ.$( 'lightbox-background' );
	
	RDJ.attachEvent( RDJ.$( 'lightbox-close-link' ), 'click', 
		function() { 
			lbClose();
			
			RDJ.$( 'nr-signup-field' ).value = "";
			
			//RDJ.detachEvent( window, 'resize' );
			
			return false; 
		} 
	);
	
	var lbo = false;
	
	function lbResize() {
		if( lbo == false ) return;
		
		var win = RDJ.getPageSize();
		RDJ.setSize( RDJ.$( 'lightbox-background' ), win[ 'w' ], win[ 'h' ] );

		if( RDJ.isIE6() ) {
                var lb = RDJ.$( 'mailinglist' );
                var scroll = RDJ.getScroll();
                var win = RDJ.getWindowSize( lb );
                if( scroll['y'] ) lb.style.top = ( win[ 'h' ] / 4 )  +  scroll['y'] - ( lb.style.height  );
                if( scroll['x'] ) lb.style.left = ( win[ 'w' ] / 2 ) + scroll['x'];

        }
	};

	function lbClose() {
		if( lbo != true ) return;
		lbo = false;
		
		RDJ.toggleDisplay( RDJ.$( 'mailinglist' ), 'block' ); 
		RDJ.toggleDisplay( lbb, 'block' );
	};
	
	function lbOpen() {
		if( lbo == true ) return;
		lbo = true;
		
		RDJ.toggleDisplay( RDJ.$( 'mailinglist' ), 'block' );
		RDJ.toggleDisplay( lbb, 'block' );
		
		lbResize();
		
		RDJ.attachEvent( window, 'resize', lbResize );
		
		try {
			RDJ.$( 'mailinglist-email' ).focus();
		} catch( e ) {}}

	RDJ.attachEvent( RDJ.$( 'nr-signup-link' ), 'click', lbOpen );

	RDJ.attachEvent( window, 'scroll', lbResize );
	RDJ.attachEvent( window, 'resize', lbResize );
	
	RDJ.attachEvent( RDJ.$( 'lightbox-submit-button' ), 'click', 
		function() { 
			RDJ.$( 'mailinglist-form' ).submit();
			/*
var RDA = new RDAjax( 'POST' );
			var form = RDJ.$( 'mailinglist_form' );
			
			if( RDJ.$( 'mailinglist-email' ).value == '' ) {
				alert( 'You must enter your email address!' );
				return false;
			}
			
			if( !RDJ.$( 'nr-check' ).checked && !RDJ.$( 'msn-check' ).checked ) {
				alert( 'You must select at least one mailing list to subscribe!' );
				return false;
			}
						
			if( RDJ.$( 'nr-check' ).checked ) {
				RDJ.$( 'mailinglist-list' ).value = 'newrelease';
				RDA.submitRequestFromForm( 'mailinglist_form', false );
			}
			
			if( RDJ.$( 'msn-check' ).checked ) {
				RDJ.$( 'mailinglist-list' ).value = 'msn';
				RDA.submitRequestFromForm( 'mailinglist_form', false );
			}

			if( RDJ.$( 'sb-check' ).checked ) {
				RDJ.$( 'mailinglist-list' ).value = 'sundaybest';
				RDA.submitRequestFromForm( 'mailinglist_form', false );
			}
			
			lbClose();
			
			return false; 
*/
		}
	);
	
	if( RDJ.getURLValueForKey( 'action' ) == 'signup' ) {
		lbOpen();
		RDJ.$( 'fields_email' ).value = RDJ.getURLValueForKey( 'email' );
	}
	
	if( RDJ.$( 'contact_form' ) != null ) {
		// Remove more info & directions
		RDJ.$( 'message' ).value = RDJ.$( 'message' ).value.replace( /\/\/ more info/, '' ).replace( /\/\/ directions/, '' );
			
		RDJ.attachEvent( RDJ.$( 'contact_form' ), 'submit', function() {
			// Is there a personal message?
			if( RDJ.$( 'personal' ).value != '' ) {
				RDJ.$( 'message' ).value = RDJ.$( 'message' ).value.replace( /msgkey/, "%0AHere's a personal message from foo:%0A%0A" + RDJ.$( 'personal' ).value );
			} else {
				RDJ.$( 'message' ).value = RDJ.$( 'message' ).value.replace( /msgkey/, '' );
			}
			
			// Setup the email link
			RDJ.$( 'message' ).value = RDJ.$( 'message' ).value.replace( /emailkey/, escape( RDJ.$( 'to' ).value ) );
			
			// Replace foo with user's name
			RDJ.$( 'message' ).value = RDJ.$( 'message' ).value.replace( /foo/g, RDJ.$( 'name' ).value );
		});
	}

// END LOAD FUNCTIONS
});

function stripClass( e, c ) {
	var obj = RDJ.createElement( 'div' );
	obj.innerHTML = e.innerHTML;
	RDJ.removeChildren( RDJ.getElementsByClassName( obj, c, e ) );
	
	return obj;
};