var firstActiveArSw;
var activeArSw;
var activeArNav;
var activeArHi;
var hE;
var hT;
var ahT;
var ahTt = 5000;
var pah;

jQuery(document).ready(
	function() {

		activeArSw = firstActiveArSw = jQuery('#application_ranges_switches a.active');
		var tmp = activeArSw.attr('id').split('_');
		activeArNav = jQuery('#arnav_'+tmp[1]);
		activeArHi = jQuery('div.arhi_'+tmp[1]);
		
		jQuery('#application_ranges_switches a').hover(
			function() {
				hE = this;
				hT = setTimeout(
					'application_ranges_switches_hover()',
					500
				);
				clearTimeout(ahT);
			},
			function() {
				clearTimeout(hT);
				hE = null;
			}
		);
		
		if(!pah) {
			ahT = setTimeout(
				'application_ranges_switches_hover_auto()',
				ahTt
			);
		}
		
		jQuery('#application_ranges').hover(
			function() {},
			function() {
				clearTimeout(hT);
				hE = null;
				if(pah) {
					if(activeArSw.attr('id') != firstActiveArSw.attr('id')) {
						activeArSw.removeClass('active');
						activeArSw.find('img.active').hide();
						activeArSw.find('img.inactive').show();
						activeArNav.fadeOut(100);
						activeArHi.fadeOut(100);
						firstActiveArSw.addClass('active');
						activeArSw = firstActiveArSw;
						activeArSw.find('img.active').show();
						activeArSw.find('img.inactive').hide();
						var tmp = activeArSw.attr('id').split('_');
						activeArNav = jQuery('#arnav_'+tmp[1]);
						activeArNav.fadeIn(500);
						activeArHi = jQuery('div.arhi_'+tmp[1]);
						activeArHi.fadeIn(500);
					}
				}
				else {
					ahT = setTimeout(
						'application_ranges_switches_hover_auto()',
						ahTt
					);				
				}
			}
		);
		
	}
);

function application_ranges_switches_hover_auto() {
	
	var switches = jQuery('#application_ranges_switches a');
	var index = switches.index(activeArSw);
	
	if(index < (switches.length-1)) {
		el = switches[(index+1)];
	}
	else {
		el = switches[0];
	}
	
	activeArSw.removeClass('active');
	activeArSw.find('img.active').hide();
	activeArSw.find('img.inactive').show();
	activeArNav.fadeOut(100);
	activeArHi.fadeOut(100);
	
	jQuery(el).addClass('active');
	activeArSw = jQuery(el);
	activeArSw.find('img.active').show();
	activeArSw.find('img.inactive').hide();
	var tmp = activeArSw.attr('id').split('_');
	activeArNav = jQuery('#arnav_'+tmp[1]);
	activeArNav.fadeIn(500);
	activeArHi = jQuery('div.arhi_'+tmp[1]);
	activeArHi.fadeIn(500);
	
	ahT = setTimeout(
		'application_ranges_switches_hover_auto()',
		ahTt
	);
	
}

function application_ranges_switches_hover() {
	var el = hE;
	if(activeArSw.attr('id') != jQuery(el).attr('id')) {
		activeArSw.removeClass('active');
		activeArSw.find('img.active').hide();
		activeArSw.find('img.inactive').show();
		activeArNav.fadeOut(100);
		activeArHi.fadeOut(100);
		jQuery(el).addClass('active');
		activeArSw = jQuery(el);
		activeArSw.find('img.active').show();
		activeArSw.find('img.inactive').hide();
		var tmp = activeArSw.attr('id').split('_');
		activeArNav = jQuery('#arnav_'+tmp[1]);
		activeArNav.fadeIn(500);
		activeArHi = jQuery('div.arhi_'+tmp[1]);
		activeArHi.fadeIn(500);
	}
}