function get(el) {
  return document.getElementById(el);
}

$(document).ready(function(){
	// sorting URL's to add GET data
	
	$('a[@href*=q-and-a], a[@href*=tools-and-tips]').each(function(){
		$(this).attr("href", $(this).attr("href")+"?from=us");
	});
	
	//news items on the front page
	$('#news .item').each(function(){
		$(this).css("height", $(this).height());
	});
	$('#news .item').not(':first').hide();
	$('#news p').not('.item').css("cursor", "pointer");
	$('#news p').not('.item').click(function(){
		if($(this).next().css("display") == "none") {
			$('#news .item').slideUp('medium');
			$(this).next().slideDown('medium');
		}

	});
	
	//enquiry form intro message
	origVal = $('#query').val();
	$('#explain').hide();
	$('#what').click(function(){
		$('#explain').slideDown('medium');
	});
	
	$('#query').focus(function(){
		if($(this).val() == origVal) {
			$(this).val("");
		}
	});
	
	$('#query').blur(function(){
		if($(this).val() == "") {
			$(this).val(origVal);
		}
	});
	
	//email + phone validator
	
	email = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,9}\b/;
	phone = /.[\d\s]{6,}/;
	valid = false;
	
	$('#submit').click(function(){
		mess = $('#query').val();
		if($(this).html() == "Submit") {
			if(email.test(mess) == true || phone.test(mess) == true) {
				$('#submit').html("loading...");
				$.ajax({
					type:"POST",
					url:"/assets/aspx/process.aspx",
					data:"query="+mess,
					success: function(msg){
						$('#submit').html("Success!");
						$('#query').fadeTo(50, 0.2);
						setTimeout(function(){
							$('#submit').html("Submit");
							$('#query').fadeTo(50, 1);
						}, 2000);
					},
					error: function(){
						alert('Unfortunately there is an error processing the form. Please use the contact details to the right.');
					}

				});
				return false;
			} else {
				$('#status').html("Are you sure you've included a correct email address or telephone number? If not, please include one and then click proceed.");
				$('#submit').html("Proceed");
				return false;
			}
		} else if($(this).html() == "Proceed") {
			$('#status').html("");
			$('#submit').html("loading...");
			$.ajax({
				type:"POST",
				url:"/assets/aspx/process.aspx",
				data:"query="+mess,
				success: function(msg){
					$('#submit').html("Success!");
					$('#query').fadeTo(50, 0.2);
					setTimeout(function(){
						$('#submit').html("Submit");
						$('#query').fadeTo(50, 1);
						
					}, 2000);
				},
				error: function(){
					alert('Unfortunately there is an error processing the form. Please use the contact details to the right of the form.')
				}
			});
			return false;
		}
	});
	
	// rollovers for product overview
	
	$('#left .prod').css("cursor","pointer").hover(function(){
		$(this).css("background-position","top right");
	}, function() {	
		$(this).css("background-position","top left");
	}).click(function(){
		window.location = $(this).children(':eq(1)').children('h2').children().attr("href");
	});
	
	// product tabs 
	$('#prodWrap div:gt(0)').hide(); // hide all the paragraphs in prodwrap except the first
		
	$('#innerPRight ul').not('.innerList').children('li').each(function(n){ // for each list item in the tabs
		$(this).attr("arrayNo", n); // give it the attribute arrayNo, then a number (zero based)
	}).click(function(){ // on click
		$('#prodWrap div').hide(); // hide all paras in prodWrap
		$('#prodWrap div:eq('+$(this).attr("arrayNo")+')').show(); // show the para who's aray index matches the  arrayNo attribute  or the list item clikced 
		$('#innerPRight ul li').removeClass('on');
		$(this).addClass('on');
	}).hover(function(){
		$(this).css({cursor: "pointer"})
	}, function() {
		$(this).css({cursor: "default"})
		
	});
	
	//vee resource center slider
	
	$('dl dd').hide();
	$('dl dt').css("cursor", "pointer").click(function(){
		$('dl dd').slideUp("fast");
		$(this).next().slideDown("fast");
	});
	
	// downloads coming soon
	
//	$(".tipsDown[href='#']").html('coming soon');

	//subNav clean up

	$('#subNav li:last').css("border", "none");
	if(get('subNav')) {
		if($('#subNav').height() < $('#left').height()) {
			$('#subNav').height($('#left').height()-16);
		}
	}
});