function filterSet() {
	$('search-light-filter').observe('click', function() {
		$('types-option').name = 'types[' + $('select-types-option').value + ']';
		$('regions-option').name = 'regions[' + $('select-regions-option').value + ']';
		$('types-option').value = $('regions-option').value = 'on';
	});
}

function tabSelect() {
	var showed = false;
	$$('#subcat-filter input[type="checkbox"]').each(function(checkbox) {
		if (showed != true && checkbox.checked == true) {
			$(checkbox.className).show();
			if ($('for-' + checkbox.className)) {
				$('for-' + checkbox.className).addClassName('active');
			}
			showed = true;
			$$('.subcats_tabs li a').each(function(tabs) {
				tabs.removeClassName('acitve2');
			});			
		}
	});
	
/*	
	var showSubcatId;
	$$('.subcats_tabs li a').each(function(element) {
		element.observe('click', function(el) {
			$$('.filter-subcats').each(function(filter) {
				filter.hide();
			});
			$$('.subcats_tabs li a').each(function(tabs) {
				tabs.removeClassName('active').removeClassName('acitve2');
			});
			element.addClassName('active');
			showSubcatId = element.id.split('-');
			$(showSubcatId[1]).show();
		});
	});
*/
	
	if ($('ch_other_lands')) {
		if ($('ch_other_lands').checked == true) makeHiddenLandInputs();
		$('ch_other_lands').observe('click', function(el) { makeHiddenLandInputs(); });
	}
}

function makeHiddenLandInputs() {
	if ($('other_lands').innerHTML == '') {
		for (var i=1; i <= 7; i++) {
			if (i != 2) {
				$('other_lands').insert('<li><input type="hidden" name="types[3]['+i+']" value="on" /></li>');
			}
		}
	} else {
		$('other_lands').update('');
	}
}

function gallerySlideShow() {
	var time = 2500;
	var interval = '';
	var button = $$('#controls .play')[0];
	
	button.observe('click', function() {
		if (interval) {
			clearInterval(interval);
			interval = 0;
			
			button.className = 'play';
				
			return;
		}
		
		var thumbs = $$('#small_imgs li img');
		var index = 1;
		
		button.className = 'pause';
		
		interval = setInterval(function() {
			if (index >= thumbs.length) {
				index = 0;
			}
			
			var img = $('main_img');
		
			img.hide();
			img.src = thumbs[index++].src.replace('_th200', '');
			img.appear({ duration: 1.5 });
		}, time);
	});
}

function popupButton() {
	$('hp-text').observe('mouseover', function() {
		new Effect.Move($('hp-image-btn'), { x: 469, y: 178, mode: 'absolute', transition: Effect.Transitions.spring });
	});
	$('hp-text').observe('mouseout', function() {
		new Effect.Move($('hp-image-btn'), { x: 469, y: 189, mode: 'absolute', transition: Effect.Transitions.spring });
	});	
}

function checkOther(checkbox) {
	var checkOtherId = checkbox.id.split('-');
	var checkThis = $('checkThis-'+checkOtherId[1]);
	checkThis.checked = checkbox.checked;
}

function scrollBar() {
// vertical slider control
			var slider1 = new Control.Slider('handle1', 'track1', {
				axis: 'vertical',
				onSlide: function(v) { scrollVertical(v, $('scrollable1'), slider1);  },
				onChange: function(v) { scrollVertical(v, $('scrollable1'), slider1); }
			});
			
			// scroll the element vertically based on its width and the slider maximum value
			function scrollVertical(value, element, slider) {
				element.scrollTop = Math.round(value/slider.maximum*(element.scrollHeight-element.offsetHeight));
			}
			
			// disable vertical scrolling if text doesn't overflow the div
			if ($('scrollable1').scrollHeight <= $('scrollable1').offsetHeight) {
				slider1.setDisabled();
				$('track1').hide();
			}	
}

window.onload = function() {
	if ($('types-option')) filterSet();
	if ($('subcat-filter')) tabSelect();
	if ($('controls')) gallerySlideShow();
	if ($('hp-text')) popupButton();
	if ($('hp-text')) scrollBar();
};
