function liveHide(a){
		$('#'+a).hide();
}

function liveShow(a){
		$('#'+a).show().empty();
}

function swapPanels(a,b,c,d,e,f){
	
		$('#'+a).removeClass('pasTabCont').addClass('actTabCont');
		$('#'+a).children().removeClass('pasTab').addClass('actTab');
		
		$('#'+b).removeClass('actTabCont').addClass('pasTabCont');
		$('#'+b).children().removeClass('actTab').addClass('pasTab');
		
		$('#'+c).removeClass('actTabCont').addClass('pasTabCont');
		$('#'+c).children().removeClass('actTab').addClass('pasTab');
	
//      $('#go_to_live_demo').html($('div.actTabCont a').eq(0).text() + ' Demo');		
        $('#go_to_live_demo').empty();		
		
		$('#'+d).show();
		$('#'+e).hide();
		$('#'+f).hide();
}

function swapPanelsShort(a,b,c,d,e,f,g,h){
   
		$('#'+a).removeClass('pasTabCont').addClass('actTabCont');
		$('#'+a).children().removeClass('pasTabShort').addClass('actTabShort');
		
		$('#'+b).removeClass('actTabCont').addClass('pasTabCont');
		$('#'+b).children().removeClass('actTabShort').addClass('pasTabShort');
		
		$('#'+c).removeClass('actTabCont').addClass('pasTabCont');
		$('#'+c).children().removeClass('actTabShort').addClass('pasTabShort');
		
		$('#'+d).removeClass('actTabCont').addClass('pasTabCont');
		$('#'+d).children().removeClass('actTabShort').addClass('pasTabShort');

//      $('#go_to_live_demo').html($('div.actTabCont a').eq(0).text() + ' Demo'); 
	  $('#go_to_live_demo').empty();	  
		
		$('#'+e).show();
		$('#'+f).hide();
		$('#'+g).hide();
		$('#'+h).hide();

}



function go_to_live_demo(){
   jQuery('#go_to_live_demo').attr('href', jQuery('div.actTabCont a').attr('rel'));
}

function show_download_form() {
	if(!$('form :animated').size()) {
	   if ($('.body:visible').size()) {
	      $('.body').slideUp('slow', function(){
	         $('form img').animate({
	            width: '0px',
	            height: '1px'
	         }, 'slow', 'swing')
	      })
			$('.body button').hide()
			$('.body .interaction_pane').hide()
			$('.download h2').removeClass('activated')
	   }
	   else {
	      $('form img').css('display', 'block').animate({
	         width: '625px',
	         height: '1px'
	      }, 'slow', 'swing', function(){
	         $('.body').slideDown('slow', function(){
					$('.body button').show()
					$('.body .interaction_pane').show()
				})
	      })
			$('.download h2').addClass('activated')
	   }
	}
} 
function animate_progress() {
	$('.progressbar').css('background-position', '0 -305px').animate({
		backgroundPosition: '(-480px -305px)'
	}, 20000, 'linear', animate_progress)
} 

/* floating ads example handlers */
function flad_handler(ifr) {
	$(ifr).closest('.orbit_flad_outer').show()
	$(ifr).closest('.orbit_flad').animate({right: '13%'}, 2000)
	var cls = $(ifr).next().children()
	setTimeout(function(){
		try {
			cls.css({display: 'block'})
			ifr.contentWindow.show_close_button()
		} 
		catch (e) {
		}
	}, 5000)
}
function flad_close(cls){
	$(cls).closest('.orbit_flad_outer').hide()
}

jQuery(function($){
	$('body').removeClass('nojs').addClass('js')
	$('div.download h2 a').click(show_download_form)

	// download form's behavior
	$('.download form').submit(function(){
			if ($(this).hasClass('disabled')) 
				return false
			$.ajax({
				url: $(this).attr('action'),
				type: 'POST',
				data: $(this).serialize(),
				dataType: 'xml',
				beforeSend: function() {
					if($('.download form').is('.sent') && $('.download form').data('previous_email') == $('#aslite_email').val())
						return false
					$('.download form').data('previous_email', $('#aslite_email').val())
					$('.interaction_pane').find('.progressbar').show().end().find('.response').hide();
					animate_progress()
				},
				error: function() {
					$('.interaction_pane .response').html('<div class="error">Connection error. Check your internet connection and try again.</div>')
				},
				success: function(data){
					if($('response',data).children().first().is('error')) {
						$('.interaction_pane .response').html($.makeArray($('error',data).map(function(){return '<div class="error">'+$(this).text()+'</div>'})).join(''))
					}else{
						$('.interaction_pane .response').html('<div class="success">'+$('success',data).text()+'</div>')
						$('.download form').addClass('sent')
					}
				},
				complete: function(data, status) {
					$('.interaction_pane').find('.progressbar').css('background-position', '0 0').stop().hide().end().find('.response').show();
				}
				
			})
			return false
		})
	.bind('focus keydown keyup keypress mouseover', function(e){
			if ($(this).find(".field input:not([value!=''])").size()) 
				$(this).addClass('disabled')
			else 
				$(this).removeClass('disabled')
			if (e.keyCode == 13) 
				$(this).submit()
		})
	.find(".field input:not([value!='']):first").focus()
	.end().find('button').click(function(){
			$(this).closest('form').submit()
			return false
		})

	/* placeholders behavior */
	$('label.placeholder[for]')
	.each(function(i, el){
		$('#' + $(el).attr('for'))
		.focus(function(){
			$('label.placeholder[for=' + $(this).attr('id') + ']').hide()
		})
		.blur(function(){
			if($(this).val() == '')
				$('label.placeholder[for=' + $(this).attr('id') + ']').show()
		})
		.blur()
	})

	/* CPA Demo Schedule From behavior */
	$('form#demoschedule').submit(function(){
		if ($(this).hasClass('disabled')) 
			return false
		$.ajax({
			url: $(this).attr('action'),
			type: 'POST',
			data: $(this).serialize(),
			dataType: 'xml',
			success: function(data){
				if($('response',data).children().first().is('error')) {
					$('.interaction_pane .response').html($.makeArray($('error',data).map(function(){return '<div class="error">'+$(this).text()+'</div>'})).join(''))
				}else{
					$('.interaction_pane .response').html('<div class="success">'+$('success',data).text()+'</div>')
					$('form#demoschedule').get(0).reset()
				}
			}
		})
		return false
	})
	
	/* Field filling from hash */
	try{
		if(location.hash) {
			$.each(location.hash.substr(1).split('&'), function(i, elem){
				$('#' + elem.split('=')[0]).val(unescape(elem.split('=')[1]))
			})
		}
	}catch(e){}

})

