/* Main Javascript file for Sharnbrook Wedding Show */

// Delay function for jquery
$.fn.delay = function(time, callback){
    // Empty function:
    jQuery.fx.step.delay = function(){};
    // Return meaningless animation, (will be added to queue)
    return this.animate({delay:1}, time, callback);
}

// Function for switching images on mouseover event
function shws_SimpleSwap(el,which) 
{
  el.src=el.getAttribute(which || "origsrc");
}

// Initial image swap page setup called from body.onload
function shws_SimpleSwapSetup() 
{
  var x = document.getElementsByTagName("img");
  for (var i = 0; i < x.length; i++)
  {
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image -
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src = oversrc;

    // set event handlers
    x[i].onmouseover = new Function("shws_SimpleSwap(this,\'oversrc\');");
    x[i].onmouseout = new Function("shws_SimpleSwap(this);");

    // save original src
    x[i].setAttribute("origsrc", x[i].src);
  }
}

// Open new centered window
function openwin(theURL, Name, popW, popH, scroll, resizable, tool, menu) 
{
var winleft = (screen.width - popW) / 2;
var winUp = (screen.height - popH) / 2;
var winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizable='+resizable+',toolbar='+tool+',menubar='+menu+''
var Win = window.open(theURL, Name, winProp)
if (parseInt(navigator.appVersion) >= 4) { Win.window.focus(); }
}

// ajax login
function login(un, pw, sd)
{
	// Ensure no cache of ajax call
	$.ajaxSetup ({   
		cache: false  
	});
	
	// Set ajax loader image
	var ajax_load = '<div class=\"loginLoader\"><img src=\"../images/loader.gif\" alt=\"Loading...\" /><br /><br />Loading..</div>';
	
	// Set loader
	$("#admin_login").ajaxStart(function(){
		$(this).html(ajax_load); 
	});
	
	// Make ajax call
	$.ajax({
		type: "POST",
		url: "ajax_calls/login.php",
		data: "un=" + un + "&pw=" + pw + "&submitted=" + sd,
		success: function(data){
			$("#admin_login").html(data);
		 }
	});
	
	return false;
}

function shws_enquiry()
{	
	var name = $('input#name').val();   
	var email = $('input#email').val(); 
	var message = $('textarea#msg').val();
	
	// Ensure no cache of ajax call
	$.ajaxSetup ({   
		cache: false  
	});
	
	// Set ajax loader image
	var ajax_load = '<div class=\"enquiryLoader\"><img src=\"../images/loaderMain.gif\" alt=\"Loading...\" /><br /><br />Loading..</div>';
	
	// Set loader
	$("#enquiry_box").ajaxStart(function(){
		$(this).html(ajax_load); 
	});
	
	// Make ajax call
	$.ajax({
		type: "POST",
		url: "register/process.php",
		data: "form_tools_form_id=1" + "&name=" + name + "&email=" + email + "&msg=" + message,
		success: function(data){
			$("#enquiry_box").html(data);
		 }
	});
}