window.addEvent('domready', function(){
	
	if ($$('.tab')) {
		var tabs = $$('.tab');
		
		tabs.each(function(tab){
			tab.addEvents({
			'click': function(e) {
				e = new Event(e).stop();
				var ref = $('cloud').getProperty('value');
				
				if (tab.hasClass('taboff')) {
					if ($$('.tab').hasClass('tabon')) {
						$$('.tab').removeClass('tabon');
						$$('.tab').addClass('taboff');
					}
					
					tab.removeClass('taboff');
					tab.addClass('tabon');
					
					if (ref == 'tag') {
						$('cloud_dest').removeClass('cloudoff');
						$('cloud_dest').addClass('cloudon');
						
						$('cloud_tag').removeClass('cloudon');
						$('cloud_tag').addClass('cloudoff');
						
						ref = 'dest';
						$('cloud').setProperty('value', 'dest');
					} else {
						$('cloud_tag').removeClass('cloudoff');
						$('cloud_tag').addClass('cloudon');
						
						$('cloud_dest').removeClass('cloudon');
						$('cloud_dest').addClass('cloudoff');
						
						ref = 'tag';
						$('cloud').setProperty('value', 'tag');
					}
				}
				}
			});
		});
	}
	
});

