/* Main Javascript file for InspiredMK.com */

// 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 to scroll window
// If having issues with Safari Mac OS and or opera, remove body or do if/else statement
function scrollWin(ele)
{
	$('html,body').animate({ scrollTop: $(ele).offset().top }, 3000);
}

// Function for switching images on mouseover event and a little shake
function vdc_SimpleSwap(el, which)
{
  el.src = el.getAttribute(which);
}

// Initial image swap page setup called from body.onload
function vdc_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("vdc_SimpleSwap(this, \'oversrc\');");
    x[i].onmouseout = new Function("vdc_SimpleSwap(this, \'origsrc\');");

    // save original src
    x[i].setAttribute("origsrc", x[i].src);
  }
}

// Open new centered window
function openCenteredWin(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(); }
}

// Simple function to submit form
function vdc_submit(form)
{
	var doc = document.getElementById(form);
	doc.submit();
}

// Function to fetch guild members
function fetchMembers(where)
{
	// Initiate ajax variable
	var ax_call = '';
	
	// Ensure no cache of ajax call and set global timeout
	$.ajaxSetup ({   
		cache: false,
		timeout: 5000
	});
			
	// Set ajax loader image and text
	var ajax_load = '<div style="position:relative;top:150px;left:190px;width:80px;height:60px;color:#bb0ab1;font-weight:bold;"><img style="margin:0px 0px 5px 21px;" src="images/loader.gif" alt="Please wait.." /><br />Please wait..</div>';
		
	// Set loader
	$("#membersPage").ajaxStart(function(){
		$(this).html(ajax_load); 
	});
	
	var url = 'members.php?where='+where;
	
	// Make ajax call
	ax_call = $('#membersPage').load(url);

}

// Function to blogs
function show_blogs(query, id, date)
{
	if (typeof date === 'undefined') { date = '0'; }
	
	// Initiate ajax variable
	var ax_call = '';
	
	// Ensure no cache of ajax call and set global timeout
	$.ajaxSetup ({   
		cache: false,
		timeout: 5000
	});
			
	// Set ajax loader image and text
	var ajax_load = '<div style="position:relative;top:70px;left:133px;width:80px;height:60px;color:#bb0ab1;font-weight:bold;"><img style="margin:0px 0px 5px 21px;" src="images/loader_front.gif" alt="Please wait.." /><br />Please wait..</div>';
		
	// Set loader
	$("#blog_list").ajaxStart(function(){
		$(this).html(ajax_load); 
	});
	
	var url = 'fetch_blogs.php';
	
	var args = 'query='+query+'&id='+id+'&date='+date;
	
	// Make ajax call
	ax_call = $.ajax({
		type: 'POST',
		url: url,
		data: args,
		success: function(data){
			$('#blog_list').html(data);
		 }
	});

}

// Function for contact page
function vdc_register()
{
	// Initiate ajax variable
	var ax_call = '';
	
	// Ensure no cache of ajax call and set global timeout
	$.ajaxSetup ({   
		cache: false,
		timeout: 5000
	});
			
	// Set ajax loader image and text
	var ajax_load = '<div style="position:relative;top:60px;left:140px;width:80px;height:60px;color:#bb0ab1;font-weight:bold;"><img style="margin:0px 0px 5px 21px;" src="images/loader_front.gif" alt="Please wait.." /><br />Please wait..</div>';
		
	// Set loader
	$("#contactForm").ajaxStart(function(){
		$(this).html(ajax_load); 
	});
	
	var url = 'http://www.theperfectweddingguild.co.uk/register/process.php';
	
	var name = $('input#full_name').val();
	var email = $('input#email_address').val();
	var tel = $('input#contact_number').val();
	var date = $('input#wedding_date').val();
	var location = $('input#wedding_location').val();
	var add = $('textarea#postal_address').val();
	var find = $('input#find_us').val();
	
	var args = 'form_tools_form_id=1&full_name='+name+'&email_address='+email+'&contact_number='+tel+'&wedding_date='+date+'&wedding_location='+location+'&postal_address='+add+'&find_us='+find;
	
	// Make ajax call
	ax_call = $.ajax({
		type: 'POST',
		url: url,
		data: args,
		success: function(data){
			$('#contactForm').html(data);
		 }
	});

}

// Function to add visitor feedback
function vdc_visitor_feedback()
{
	// Initiate ajax variable
	var ax_call = '';
	
	// Ensure no cache of ajax call and set global timeout
	$.ajaxSetup ({   
		cache: false,
		timeout: 5000
	});
			
	// Set ajax loader image and text
	var ajax_load = '<div style="position:relative;top:10px;left:100px;width:80px;height:60px;color:#bb0ab1;font-weight:bold;"><img style="margin:0px 0px 5px 21px;" src="images/loader_front.gif" alt="Please wait.." /><br />Please wait..</div>';
		
	// Set loader
	$("#feedbackForm").ajaxStart(function(){
		$(this).html(ajax_load); 
	});
	
	var url = 'http://www.theperfectweddingguild.co.uk/feedback_thankyou.php';
	
	var name = $('input#full_name').val();
	var email = $('input#email_address').val();
	var fb = $('textarea#feedback').val();
	var id = $('input#id').val();
	var logo = $('input#logo').val();
	
	var args = 'full_name='+name+'&email_address='+email+'&feedback='+fb+'&id='+id+'&logo='+logo;
	
	// Make ajax call
	ax_call = $.ajax({
		type: 'POST',
		url: url,
		data: args,
		success: function(data){
			$('#feedbackForm').html(data);
		 }
	});

}
