function sw() {
	var $a=$('#slideshow IMG.active');
	var $n=$a.next().length?$a.next():$('#slideshow IMG:first');
	$a.addClass('last-active');
	$n.css({opacity:0.0}).addClass('active').animate({opacity:1.0},1000,function() {
		$a.removeClass('active last-active');
	});
}
function vat(vs) {
	$("input[name='os0']").val(vs?'1 user (with VAT)':'1 user (no VAT)');
	$('#vatstatus').val(vs?'VAT charged at 17.5%':'No VAT will be charged');
}
$(function()
{
	if ($('#slideshow').length > 0 && $('#slideshow IMG:first').length > 0)
		setInterval("sw()",3000);
	var $cc='gb';
	if (google.loader.ClientLocation && google.loader.ClientLocation.address) {
		$cc=google.loader.ClientLocation.address.country_code.toLowerCase();
	}
	$("select#country").val($cc);
	var $tabs=$('#tabs').tabs();
	$("a[href='#tabdownload']").click(function(){
		$tabs.tabs('select',3);
		return false;
	});
	$("body#contact div#contactbox").removeClass("formbox");
	$(".formbox").dialog({autoOpen:false,width:700,modal:true});
	$('.formbox input[type=reset]').click(function() {
		$("select#country").val($cc);
		$(this).parents('.formbox').dialog("close");
		return false;
	}).val('Cancel');
	$('form.ajaxform').ajaxForm({
		success: function(response,status,xhr,$form){
			if ($form.find("input[name='TAG']").is("[value*='download']")) {
				$.get('http://dl.wlcsoftware.com/wlce/',{r:true,e:$form.find("input[name='EMAIL']").val()},function(data){alert(data);},'jsonp');
			} else {
				alert('Thank you - please watch your Inbox, or email enquiries@wlcsoftware.com if you don\'t hear from us soon!');
			}
			$form.parents('.formbox').dialog("close");
		}
	});
	$("ul.features a.lightbox").hide().first().show();
	$("ul.features li").hover(function(){ $("ul.features a.lightbox").hide(); $(this).children('a.lightbox').show(); });
	$("a.lightbox").lightBox();
	$("a[href='/contact/']").not("ul#nav a").click(function() {
		var $title=$(this).attr('title');
		$title=$title?$title:$(this).html();
		if ($title=='Request invoice') {
			$('#contactbox form label').not(':last').addClass('required');
			$("#contactbox form textarea[name='NOTE']").val('Number of licenses required, VAT number if applicable');
		}
		if ($title.indexOf('download')!=-1) {
			$(".formbox textarea[name='NOTE']").hide().prev().hide();
			$('.formbox form').submit(
				function(){
					$(this).find('input[name=COMPLETE_URL]').val('http://dl.wlcsoftware.com/wlce/?r=1&e='+encodeURIComponent($('#email').val()));
				});
		}
		$('#contactbox').dialog('option','title',$title).dialog("open",
		{
			autoOpen:false,
			minWidth:600,
			modal:true
			}).children('form').append('<input type="hidden" name="TAG" value="'+$title+'" />');
			return false;
		}
	);
	document.body.style.display='';
	if (location.hash && location.hash=='#register') {
		var $title='Register and download the latest version';
		$(".formbox textarea[name='NOTE']").hide().prev().hide();
		$('#contactbox').dialog('option','title',$title).dialog("open",	{
			autoOpen:false,
			minWidth:600,
			modal:true
			}).children('form').append('<input type="hidden" name="TAG" value="'+$title+'" />').submit(
				function(){
					$(this).find('input[name=COMPLETE_URL]').val('http://www.wlcsoftware.com/wlce/?r=1&e='+encodeURIComponent($('#email').val()));
				});
	}
	$("div#paypaldiv").dialog({autoOpen:false,title:'Pay online (Paypal or card)'}).children('form').attr('target','paypal');
	$('#paypalvat').hide();
	$("select[name='vatregime']").change(function(){
		if ($(this).val()=='eu') {
			$('#paypalvat').show();
			$("input[name='os1']").change();
		} else {
			$('#paypalvat').hide();
			vat($(this).val()=='gb');
		}
	});
	$("input[name='os1']").change(function(){
		var vatnum=/^([a-z]{2})([0-9a-z]+)$/.exec($(this).val().toLowerCase());
		if (vatnum==null || vatnum[1]=='gb') {
			vat(true);
			return;
		}
		$('#vatstatus').val('Checking...');
		$.getJSON('http://isvat.appspot.com/'+vatnum[1]+'/'+vatnum[2]+'/?callback=?',
			function(data) {
				vat(!data);
			});
	});
	$("a[href$='#buyonline']").click(function(){$("div#paypaldiv").dialog('open');});
	vat(true);
});
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-16081694-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['_trackPageLoadTime']);

 (function() {
   var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
   ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
   var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
 })();

