// JavaScript Document
$(document).ready( function(){

	// replace standard form input types with nicer ones ( only for radios and checkboxes )
	// no need to do this for safari, since that's where I stole the images from anyway
	if( ! $.browser.safari ){
		
		// iterate all checkboxes - replace with image
		$("input[@type=checkbox]").each( function(){
			// add default image / offstate image									  
			$(this).before('<img src="_images/checkbox-off.gif" width="16" height="16" alt="" style="position: relative; top: 4px; border: 0;" />');
			// clicking on a sibling image triggers a click in sibling input
			$(this).siblings("img").mousedown( function(){ $(this).siblings("input").trigger( "click" ); } );
			// clicking on this input triggers path change of sibling image
			$(this).click( function(){
				var path;
				if( this.checked ){
					path = "_images/checkbox-off.gif";
				}else{
					path = "_images/checkbox-on.gif";
				}
				$(this).siblings( "img" ).attr( "src" , path );
			} );
			// run an off-on or on-off if they are already set
			if( this.checked ){ $(this).trigger( "click" ).trigger( "click" ); }
			// hide checkbox
			$(this).hide();
		} );
		
		// iterate all radios - replace with image
		$("input[@type=radio]").each( function(){
			// add default image / offstate image									  
			$(this).before('<img src="_images/radio-off.gif" width="16" height="16" alt="" style="position: relative; top: 4px;" />');
			// clicking on a sibling image triggers a click in sibling input
			$(this).siblings("img").mousedown( function(){ $(this).siblings("input").trigger( "click" ); } );
			// clicking on this input triggers path change of sibling image
			$(this).click( function(){
				$(this).siblings( "img" ).attr( "src" , "_images/radio-on.gif" );
				// if this is checked, turn off all radios with the same name in document
				$(this).addClass( "ignoreme" );
				$("input[@name=" + $(this).attr( "name" ) + "]").not(".ignoreme").each( function(){
						$(this).siblings("img").attr( "src" , "_images/radio-off.gif" ); 																		 
				});
				$(this).removeClass( "ignoreme" );
			} );
			// if it's already checked, run a click
			if( this.checked ){ $(this).trigger( "click" ); }
			// hide radio
			$(this).hide();
		} );
		
		// turn off label matching
		$("label").click( function(){ return false; } );
		
	}

} );