// 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 vdc_SimpleSwap(el,which) 
{
  el.src=el.getAttribute(which || "origsrc");
}

// 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);");

    // save original src
    x[i].setAttribute("origsrc", x[i].src);
  }
}
// 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 }, 2500);
}

// Function to view bride and groom
function vdc_view_couple()
{
	var pin = $('#pin').val();
	var couple = $('#bride_groom').val();
	
	if(pin == '') 
	{  
		alert('Please enter the pin number');
		$('#pin').css({'backgroundColor' : '#ffd7d7'});
		$('#pin').focus();
		return;
	}
	if(couple == '') 
	{  
		alert('Please select the bride and groom');
		$('.ddTitle,.ddChild').css({'borderColor' : '#cc0000'});
		return;
	}

	$.ajax({
	   type: "POST",
	   url: root_url+"/ajax_calls/view_couple.php",
	   data: "pin=" + pin + "&couple=" + couple,
	   success: function(data){
			vdc_viewable_checked(data);
		}
	});
}

function vdc_viewable_checked(data)
{
	var str = data.split(",");
	var ans = str[0];
	var couple = str[1];
	
	if(ans == 'yes')
	{
		window.location = root_url+"/bride.php?bride_groom="+couple;
	}
	else
	{
		alert('The pin was entered incorrectly, please try again.');
		$('#pin').css({'backgroundColor' : '#ffd7d7'});
		$('#pin').focus();
		return;
	}
}
