// This hides/displays the top ribbon - start ---------------------------------------------
_spBodyOnLoadFunctionNames.push("IsAuthenticatedUser('s4-ribbonrow')");

/* anonymous users do not see a ribbon */
function IsAuthenticatedUser(obj){
	var el = document.getElementById(obj);
	if (typeof _spUserId=="undefined"){
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
		el.style.setAttribute("marginTop", '0');
	}
}
function toggle(obj){
	var el = document.getElementById(obj);
	if(el.style.display !='none') {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
		el.style.setAttribute("marginTop", '0');
	}
}
// This hides/displays the top ribbon - end -----------------------------------------------

// Move the background image - start --------------------------------------------------------
var scrollSpeed = 50;
var step = 1;
var current = 0;
var imageWidth = 2000;
var headerWidth = 960;
var moveLtoR = true;
var stopPosition = -(imageWidth - headerWidth);

function scrollBg(){
	if (moveLtoR){
		current -= step;
		if (current == stopPosition){
			moveLtoR = false;
		};	
		}else{
			current +=step;
			if (current == 0){
			moveLtoR = true;
		};
	}
		$('.welcome').css("background-position",current+"px 0");
	}
	var init = setInterval("scrollBg()", scrollSpeed);
	
$(function(){
			$("#slides").slides({
			play: 10000,
			effect: 'fade'
		});									
});
// Move the background image - end --------------------------------------------------------

// Contact Us Form - start ----------------------------------------------------------------
function SendEmailToNovotronix()
{
var errorMessage = "";
var fromName = $("input[name='textName']").val();
var fromCompany = $("input[name='textCompany']").val();
var fromTelephone = $("input[name='textTelephone']").val();
var fromMessage = $("textarea[name='TextMessage']").val();
var fromSubject = "WebSite Contact from Novotronix.com";
var recipientEmail = "info@novotronix.com";
var fromEmail = $("input[name='textEmail']").val();
var isValidInput = "true";

if (!isValidEmailAddress(fromEmail))
{
	isValidInput = "false";
	errorMessage = errorMessage + "Please enter a valid Email Address\n";
}
if (fromName == "")
{	
	isValidInput = "false";
	errorMessage = errorMessage + "Please enter your name\n";
}
if (fromTelephone == "")
{	
	isValidInput = "false";
	errorMessage = errorMessage + "Please enter your telephone number\n";
}
if (fromCompany == "")
{	
	isValidInput = "false";
	errorMessage = errorMessage + "Please enter your company name\n";
}
if (fromMessage == "")
{	
	isValidInput = "false";
	errorMessage = errorMessage + "Please enter a message\n";
}

if (isValidInput == "true")
{
	$(".contactForm").html("<img src='/company/_layouts/images/loading.gif' style='border:none'/>");
	var fullMessage = "&lt;h1&gt;Web Site Contact&lt;/h1&gt; \
	Name: &lt;h3&gt;" + fromName + "&lt;/h3&gt; \
	Email: &lt;h3&gt;" + fromEmail + "&lt;/h3&gt; \
	Company: &lt;h3&gt;" + fromCompany + "&lt;/h3&gt; \
	Telephone: &lt;h3&gt;" + fromTelephone + "&lt;/h3&gt; \
	Message: &lt;h3&gt;" + fromMessage + "&lt;/h3&gt;";

	var soapEnvelope = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
	  <soap:Body> \
	    <SendEmail xmlns='http://webservices.novotronix.com/'> \
	      <address>" + recipientEmail + "</address> \
	      <subject>" + fromSubject + "</subject> \
	      <message>" + fullMessage + "</message> \
	      <htmlformat>true</htmlformat> \
	    </SendEmail> \
	  </soap:Body> \
	</soap:Envelope>";

	$.ajax({
		url:'/company/_layouts/novotronix/webservice/emailservice.asmx',
		success: emailSuccess,
		error:emailError,
		type: 'POST',
		data: soapEnvelope,
		contentType: "text/xml; charset=\'utf-8\'",
		dataType: 'xml'
	});
}
else
{
	alert(errorMessage);
}
}

function emailSuccess(xData, status)
{
	location.href="/pages/Thank-You.aspx";
}

function emailError(xData, status)
{
	alert("Oops - we could not send your message. Please try again.\n If this happens again, please call 01902 424277");
	location.href="location.href";
}

function isValidEmailAddress(emailAddress) {  
//var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);  
var pattern = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/);
return pattern.test(emailAddress);  
} 
// Contact Us Form - end ----------------------------------------------------------------

$(document).ready(function(){ 

	//MOVE FOOTER TO CORRECT POSITION
	
	setTimeout( function() {
		var myPos = $("#mainPageArea").height();
		$(".footer").css('top', myPos);
		$(".footer").css('display', 'block');
	}, 200 );	

	
	//This highlights the current page in the pages list - must have the jquery.url.packed.js file attached to the masterpage
	function addBullet(){
		$page = jQuery.url.attr("path");
			if(!$page) {
				$page = 'default.aspx';
			}
		$('.pagesList li a').each(function(){
			var $href = $(this).attr('href');
			if ( ($href == $page) || ($href == '') ) {
				$(this).parent().addClass('bulletOn');
			} else {
				$(this).parent().removeClass('bulletOn');
			}
		});
	};
	
	addBullet();
	
	//Nudge page list items on hover - add bullet and colour text
	$('.pagesList li').hover(function() {
		$(this).stop().animate({
			marginLeft: '4px'
		}, 200);
		$(this).addClass('bulletOn');
	}, function() {
		$(this).stop().animate({
			marginLeft: 0
		}, 200);
		$(this).removeClass('bulletOn');
		addBullet();
	});
	

$(function() {
        $('.samplesWrapper a').lightBox({fixedNavigation:true});
    });




		
});
