/* Main Javascript file for Ultimate Visuals */

// 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 UV_SimpleSwap(el,which) 
{
  el.src=el.getAttribute(which || "origsrc");
}

// Initial image swap page setup called from body.onload
function UV_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("UV_SimpleSwap(this,\'oversrc\');");
    x[i].onmouseout = new Function("UV_SimpleSwap(this);");

    // save original src
    x[i].setAttribute("origsrc", x[i].src);
  }
}

// Open new centered window
function UV_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(); }
}

// Used to display ajax loading
function UV_showLoading()
{
	var content = '<div style="width:31px;height:31px;margin-right:auto;margin-left:auto;">';
	content += '<img src="images/loading2.gif" width="31" height="31" alt="Loading" border="0" />';
	content += '</div>';
	
	var ele = $('formCont');
	ele.innerHTML = content;
}

// Used to display ajax response
function UV_showSuccess(transport)
{
	var response = transport.responseText;
	
	var content = '<span class="bl">Successful</span>';
	content += '<br /><br />';
	content += 'Thank you, ';
	content += response;
	content += ' your submission has been recieved, we will be in contact with you shortly.';
	content += '<br /><br />';
	content += 'Ultimate Visuals';
	
	var ele = $('formCont');
	ele.innerHTML = content;
}

// Used to display ajax response
function UV_showFailure(transport)
{
	var content = '<span class="bl">Un-successful</span>';
	content += '<br /><br />';
	content += 'We are sorry but the submission failed.';
	content += '<br /><br />';
	content += '<a href="javascript:history.go(-1);">Please click</a> here to try again.';
	
	var ele = $e('formCont');
	ele.innerHTML = content;
}

// Re-write css and image for background in relation to screen width
function UV_checkScreenWidth()
{
	if (screen.width <= 1024)
	{
		return true;
	}
	else
	{
		return false;
	}

}