$(document).ready(function() {

/* Default Popup Functions Start
--------------------------------------------------------------------------------------------------------------- */
//When you click on a link with class of poplight and the href starts with a # 
$('a.poplight[href^=#]').click(function() {
    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define size

    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="http://alonzowest.com/~hosting/~pornsiteads.com/images/close_pop3.png" width="50" height="50" class="btn_close" title="Close Window" alt="Close" border="0" /></a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

    return false;
});

//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  //fade them both out
    });
    return false;
});
/* Default Popup Functions Stop
--------------------------------------------------------------------------------------------------------------- */



/* Ajax Popup Functions Start
--------------------------------------------------------------------------------------------------------------- */
$('a.popajax').click(function() {
    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define url
    var popSIZE = $(this).attr('size'); //Get Popup size	
	
    //Pull Query & Variables from href URL
    var query= popSIZE.split('x');
    var popWidth = query[0]; //Gets the first query string value
    var popHeight = query[1]; //Gets the second query string value

	//Fade in the Popup and add close button.
	$('#' + popID).fadeIn().prepend('<div id="ajaxcontent" style="width:'+ popWidth +'px; height:'+ popHeight +'px; overflow:auto;"></div>');
    //$('#' + popID).fadeIn().prepend('<a href="#" class="closeajax"><img src="http://alonzowest.com/~hosting/~pornsiteads.com/images/close_pop3.png" width="50" height="50" class="btn_close" title="Close Window" alt="Close" border="0" /></a>');
	
    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height()) / 2;
    var popMargLeft = ($('#' + popID).width()) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    $('body').append('<div id="fade2"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade2').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

	// Make Ajax Request and Process the data.
	$('#ajaxcontent').html('<table width="100%" height="100%"><tr><td align="center" valign="middle"><img src="http://www.pornsiteads.com/images/ajax-loader.gif"></td></tr></table>');
	$.ajax({
	  url: popURL +'?cmd=ajax',
	  cache: false,
	  success: function(data) {
		$('#ajaxcontent').empty();
		$('#ajaxcontent').html(data);
	  }
	});
	
    return false;
});


//Close Popups and Fade Layer
$('a.closeajax, #fade2').live('click', function() { //When clicking on the close or fade layer...
    $('#fade2, .popup_block, #ajaxcontent').fadeOut(function() {
		$('#fade2, .popup_block, #ajaxcontent').hide();
        $('#fade2, a.closeajax, #ajaxcontent').remove();  //fade them both out
    });
	
    return false;
});
/* Ajax Popup Functions Start
--------------------------------------------------------------------------------------------------------------- */

});
