/*
 * NAME: jqpe.js for jQ Photographer's Exchange
 * AUTHOR: Jay Blanchard
 * DATE: 2011-03-05
 * BUSINESS RULE:   <if applicable>
 *
 * REVISION:    a20110305jb
 * STATUS:      open
 * USAGE:       call from web pages to provide gooey interactive goodness                        
 *
 * NOTES:       Background Resizer
 * 				<!-- This gets positioned absolutely so place it anywhere. -->
 *				<div id="bodyBackground"><img src="yourBackgroundImage.jpg" alt="bg"></div>
 *				$("#bodyBackground").ezBgResize(); 
 *
 * REVISION HISTORY
 * 
 * a20110305jb  - create initial jQuery
 *
 */

/*	110611rdc3 	necessary for no conflict w/$ var	*/

/*	$.noConflict();	*/

/*	110611rdc3 	necessary for no conflict w/$ var	*/

  jQuery(document).ready(function($) {

/*	110611rdc3 	necessary for no conflict w/$ var	*/

$(document).ready(function() {
	/* Background Resizer */
	$("#bodyBackground").ezBgResize();
	
	/* modal windows */
	$('a.modal').click(function() {
        var modalID = $(this).attr('rel'); // get the name of the modal
        
        /* fade in the modal window and add a close button to it */
        $('#' + modalID).fadeIn().prepend('<a href="#" class="close"><img src="grfx/close_button.png" class="close_button" title="Close Window" alt="Close" /></a>');
        /* 
         * define the margins so that the modal is centered properly on the screen
         * we add 80px to the height/width to accomodate for the padding and border
         * width defined in the css
         */
        var modalMarginTop = ($('#' + modalID).height() + 80) / 2;
        var modalMarginLeft = ($('#' + modalID).width() + 80) / 2;
        /* apply the margins to the modal window */
        $('#' + modalID).css({
            'margin-top' : -modalMarginTop,
            'margin-left' : -modalMarginLeft
        });

        /* fade in the shade! (tired of the cheesy jokes yet?) */
        $('body').append('<div id="modalShade"></div>'); // add the shade layer to bottom of the body
        $('#modalShade').css('opacity', 0.7).fadeIn(); // set the opacity with jQuery to avoid all of the nasty CSS needed for IE
        return false; // keep the link from acting naturally
    });

    /*
     * close the modal and pull down the shade
     */
    $('a.close, #modalShade').live('click', function() { // clicking on the close or shade layer
    	var thisModalID = $('a.close').parent().attr('id');
        $('#modalShade, #'+thisModalID).fadeOut(function() {
            $('#modalShade, a.close').remove();  // remove the shade and the close button
        });
        return false;
    });
    
    /* new user name check 				DONT't NEED THIS		*/
    $('#penewuser').blur(function() {
    	var newName = $(this).val();
    	$.post('inc/peregister.php',
    		{formName: 'register', 
    		penewuser: newName}, 
    		function(data){
    			var usernameCount = data;
    			if(1 == usernameCount){
    				$('#usernameError').css('display', 'inline');
    			} else {
    				$('#usernameError').css('display', 'none');
    			}
    		}, 'html');
    });
    
    
    	/* forgotten password */
	$('#forgottenForm').submit(function(e) {
		e.preventDefault();
		//	var formData = $(this).val();
				
	var $form = $( this ),
        formData = $form.find( 'input[name="usernamemail"]' ).val();
     //	how to do this??   formName = $form.find( 'input[name="usernamemail"]' ).val();
		
		$.post('login/forgotten.php', 
		
		{
			usernamemail: formData,
			forgotten: 'forgotten'
		}
		
		, function(data) {	
		
		  //		$('#result').html(data);
		  
		  //		var content = $( data ).find( '#content' );
		  $( "#result" ).empty().html( data );

		
		}, 'html');
	});


    	/* details modal 	122311rdc3	WHY IS THIS ONLY WORKING ON FIRST LINK		*/
/*	$('#details').click(function(e) {
		e.preventDefault();

		//var event_id_val = $(this).attr("event_id");
		
		var event_id_val = $('#details').attr("event_id");
		
		$.post('wp-content/themes/SimplePress/reg_details.php', 
		
		{
			event_id: event_id_val
		}
		
		, function(data) {	
		
		 // $( '# + event_id_val ).html( data );

		
		}, 'html');
	});
*/

  
	/* UI dialog method			var event_id_val = $(this).attr("event_id"); 
	
	$(function() {
		$( "#dialog" ).dialog({
			autoOpen: false
			modal: true
		});

		$( "#opener" ).click(function() {
			$( "#dialog" ).dialog( "open" );
			return false;
		});
	});
*/


/* UI dialog method	
var openDialog = function(){

   $('#dialog').dialog('option', 'buttons',{
      "Cancel":function(){
         $('#dialog').dialog('close');
         var event_id_val = $(this).attr("event_id");
        // alert("woof"+ event_id_val);

          
      }
  });



 $('#dialog').dialog('open');

};

$(function() {
    $( "#dialog" ).dialog({

        autoOpen: false,
        show: "blind",
        hide: "explode"
    });
  $('#opener').click(openDialog);
});

*/


/* UI dynamic Dialog stable 122411rdc3	*/

$(function() {
    $("#details_display").dialog({
        width: 800,
        autoOpen: false,
        modal:true
    });

    $('a.details').click(function() {
        var url = $(this).attr('href');
       $('#details_display').load(url, function() {
            $('#details_display').dialog('open');
        });
        return false;
    });
});  


$(function() {
    $("#desc_display").dialog({
        width: 800,
        height:400,
        autoOpen: false,
        modal:true
    });

    $('a.desc').click(function() {
        var url = $(this).attr('href');
       $('#desc_display').load(url, function() {
            $('#desc_display').dialog('open');
        });
        return false;
    });
});  

$(function() {
    $("#forgot_display").dialog({
        width: 800,
        autoOpen: false,
        modal:true
    });

    $('a.forgot_details').click(function() {

            $('#forgot_display').dialog('open');

        return false;
    });
});  

/* UI dynamic Dialog stable 122411rdc3	*/
    
});
});

