$(document).ready(function(){
	/* The following code is executed once the DOM is loaded */

  /* Subscribe Form */
  $('#subscribe-form').submit(function() {
    $.ajax({
      url: 'subscribe.php',
      data: $(this).serialize(),
      success: function(msg) {
        alert(msg);
      }
    });

    return false;
  });
  /* End Subscribe Form */

  /* Sponsors */
	$('.sponsorFlip').bind("click",function(){
    if ($.browser.msie && $.browser.version == 6) {
      window.open($(this).parents('.sponsor').find('.sponsorURL a').attr('href'), '_blank');
      return;
    }

		// $(this) point to the clicked .sponsorFlip element (caching it in elem for speed):
		var elem = $(this);

		// data('flipped') is a flag we set when we flip the element:
		if(elem.data('flipped')) {
			// If the element has already been flipped, use the revertFlip method
			// defined by the plug-in to revert to the default state automatically:

			elem.revertFlip();

			// Unsetting the flag:
			elem.data('flipped',false)
		}
		else {
			// Using the flip method defined by the plugin:

			elem.flip({
				direction:'lr',
				speed: 350,
				onBefore: function(){
					// Insert the contents of the .sponsorData div (hidden
					// from view with display:none) into the clicked
					// .sponsorFlip div before the flipping animation starts:

					elem.html(elem.siblings('.sponsorData').html());
				}
			});

			// Setting the flag:
			elem.data('flipped',true);
		}
	});
  /* End Sponsors */

});

/* Popups */
function CloseMyPopup() {
  document.getElementById("mypopup").style.display="none";
}
  function fireMyPopup2() {
  //Due to different browser naming of certain key global variables, we need to do three different tests to determine their values
  // Determine how much the visitor had scrolled

  var scrolledX, scrolledY;
  if( self.pageYOffset ) {
    scrolledX = self.pageXOffset;
    scrolledY = self.pageYOffset;
  } else if( document.documentElement && document.documentElement.scrollTop ) {
    scrolledX = document.documentElement.scrollLeft;
    scrolledY = document.documentElement.scrollTop;
  } else if( document.body ) {
    scrolledX = document.body.scrollLeft;
    scrolledY = document.body.scrollTop;
  }

  // Determine the coordinates of the center of browser's window

  var centerX, centerY;
  if( self.innerHeight ) {
    centerX = self.innerWidth;
    centerY = self.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight ) {
    centerX = document.documentElement.clientWidth;
    centerY = document.documentElement.clientHeight;
  } else if( document.body ) {
    centerX = document.body.clientWidth;
    centerY = document.body.clientHeight;
  }

    var leftOffset = scrolledX + (centerX - 245) / 2;
    var topOffset = scrolledY + (centerY - 250) / 2;

    document.getElementById("mypopup2").style.top = topOffset + "px";
    document.getElementById("mypopup2").style.left = leftOffset + "px";
    document.getElementById("mypopup2").style.display = "block";
  }



  function fireMyPopup() {
  // Due to different browser naming of certain key global variables, we need to do three different tests to determine their values

  // Determine how much the visitor had scrolled

  var scrolledX, scrolledY;
  if( self.pageYOffset ) {
    scrolledX = self.pageXOffset;
    scrolledY = self.pageYOffset;
  } else if( document.documentElement && document.documentElement.scrollTop ) {
    scrolledX = document.documentElement.scrollLeft;
    scrolledY = document.documentElement.scrollTop;
  } else if( document.body ) {
    scrolledX = document.body.scrollLeft;
    scrolledY = document.body.scrollTop;
  }

  // Determine the coordinates of the center of browser's window

  var centerX, centerY;
  if( self.innerHeight ) {
    centerX = self.innerWidth;
    centerY = self.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight ) {
    centerX = document.documentElement.clientWidth;
    centerY = document.documentElement.clientHeight;
  } else if( document.body ) {
    centerX = document.body.clientWidth;
    centerY = document.body.clientHeight;
  }

    var leftOffset = scrolledX + (centerX - 640) / 2;
    var topOffset = scrolledY + (centerY - 600) / 2;

    document.getElementById("mypopup").style.top = topOffset + "px";
    document.getElementById("mypopup").style.left = leftOffset + "px";
    document.getElementById("mypopup").style.display = "block";
  }
/* End Popups */
