function LaunchSong (song) {
	x7 = 40
	y7 = 25
	var msgWindow=open(song,'player','width=460,height=200,menubar=no,scrollable=no,resizable=no,status=no,scrollbars=no,left='+x7+',top='+y7);
	msgWindow.focus();
}
function LaunchVideo (video) {
	x7 = 40
	y7 = 25
	var msgWindow=open(video,'player','width=460,height=450,menubar=no,scrollable=no,resizable=no,status=no,scrollbars=no,left='+x7+',top='+y7);
	msgWindow.focus();
}
function OpenBigImage(biggerImage, alt) 
{
	imageWindow = open("","displayWindow","width=450,height=600,left=10,top=10");

	// open new document 
	imageWindow.document.open();

	// Text of the new document
	// Replace your " with ' or \" or your document.write statements will fail
	imageWindow.document.write("<html><title>SuperSize Picture</title>");
	imageWindow.document.write("<body bgcolor=\"#000000\">");
	imageWindow.document.write("<center><IMG SRC=" + biggerImage + " ALT='" + alt + "' BORDER=0></center>");
	imageWindow.document.write("</body></html>");

	// close the document
	imageWindow.document.close(); 
	imageWindow.focus();
}
function OpenWideImage(biggerImage, alt) 
{
	imageWindow = open("","displayWindow","width=700,height=475,left=10,top=10");

	// open new document 
	imageWindow.document.open();

	// Text of the new document
	// Replace your " with ' or \" or your document.write statements will fail
	imageWindow.document.write("<html><title>SuperSize Picture</title>");
	imageWindow.document.write("<body bgcolor=\"#000000\">");
	imageWindow.document.write("<center><IMG SRC=" + biggerImage + " ALT='" + alt + "' BORDER=0></center>");
	imageWindow.document.write("</body></html>");

	// close the document
	imageWindow.document.close(); 
	imageWindow.focus();
}

// ---- this is the image magic part: preloading and swapping -------

function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function FP_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}

// ---------- email & text validation stuff --------------
function getNextGig()
{ 
  var xhr; 
  try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
  catch (e) 
  {
	  try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
	  catch (e2) 
	  {
		try {  xhr = new XMLHttpRequest();     }
		catch (e3) {  xhr = false;   }
	  }
   }

  xhr.onreadystatechange  = function()
  { 
	   if(xhr.readyState  == 4)
	   {
			if(xhr.status  == 200) {
			   document.getElementById("topMarquee").innerHTML = xhr.responseText + latestNews;
			}
			else 
			  alert("Error code " + xhr.status);
	   }
  }; 

 xhr.open('GET', "ajax_services.php?action=1",  true); 
 xhr.send(null); 
}       

function showMailingList()
{
  $("#mailinglist_loading").hide();
  $("#mailinglist_response").slideUp("fast", function(){
    $("#mailinglist").slideDown("fast");
  });
}

function submitMailingListForm()
{
  var email = $.trim($("#mailinglist_email").val());
  var validated = true;
  var errormsg = "";
  var regEx = /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/;
  
  if (email == "" || email.toLowerCase() == "enter your email address") {validated = false; errormsg = "Email required";}
  else if (!regEx.test(email)) {validated = false; errormsg = "Invalid email address";}
  
  if (validated)
  {  
    $("#mailinglist").slideUp("fast", function(){
      $("#mailinglist_loading").show();
      $.ajax({
        type: "GET",
        timeout: 5000,
        url: "ajax_services.php?action=2&data=" + email,
        dataType: "html",
        data: "", // don't need this with GET
        success: function(msg){
          setTimeout("processMailingListResponse('" + msg + "')", 1000);
        },
        error: function(object, error, exception){
          $("#mailinglist_loading").hide();
          $("#mailinglist_response").html("<p class=\"bold centered\">Unfortunately, an error has occurred.</p><p class=\"centered\"><a href=\"#\" onclick=\"showMailingList(); return false;\">Try again</a></p>").show();
          /*if (window.console && window.console.error) {
              console.error(arguments);
          }*/
        }
      });
    });
  }
  else
  {
    $("#mailinglist_validation").html(errormsg);
  }
}

function processMailingListResponse(response)
{
  $("#mailinglist_loading").hide();
  $("#mailinglist_response").html(response).show();
}

function showShoutboxForm()
{
  $("#shoutbox_link").hide();  
  $("#shoutbox_form").slideDown("fast");
}

function submitShoutboxForm()
{
  var name = $.trim($("#shoutbox_name").val());
  var message = $.trim($("#shoutbox_message").val());
  var validated = true;
  var errormsg = "";
  var regEx = /<\D+>/;
  
  if (name == "" || name.toLowerCase() == "enter your name") {validated = false; errormsg = "Name required";}
  else if (message == "" || message.toLowerCase() == "enter your message") {validated = false; errormsg = "Message required";}
  else if (regEx.test(name) || regEx.test(message)) {validated = false; errormsg = "Tags not allowed";}
  else if (message.length > 100) {validated = false; errormsg = "100 character limit";}
  
  if (validated)
  {
    $("#shoutbox").slideUp("fast", function(){
      $("#shoutbox_loading").show();
      $.ajax({
        type: "POST",
        timeout: 5000,
        url: "/shoutbox",
        dataType: "html",
        data: "shoutbox_type=ajax&shoutbox_name=" + name + "&shoutbox_message=" + message,
        success: function(msg){
          if (msg == "" || msg == "error") {setTimeout("$('#shoutbox_loading').hide(); $('#shoutbox_error').show();", 1000);}
          else {setTimeout('refreshShoutbox("' + msg + '")', 1000);}
        },
        error: function(object, error, exception){
          $("#shoutbox_loading").hide();
          $("#shoutbox_error").show();
        }
      });
    });
  }
  else
  {
    $("#shoutbox_validation").html(errormsg);
  }
}

function refreshShoutbox(posts)
{
  if (posts != null) $("#shoutbox_posts").html(posts);
  $("#shoutbox_loading").hide();
  $("#shoutbox").slideDown("fast");
}

function clearInput(object, defaultValue)
{
  if ($.trim(object.value) == defaultValue) {object.value = "";}
}

function checkInput(object, defaultValue)
{
  if ($.trim(object.value) == "") {object.value = defaultValue;}
}
