/* $Id: product_all_menu.js 30 2007-11-29 14:31:11Z edin.coralic $ */

var ProductAllMenu = {
	run: function() {
		if (!$('filter') || !$('expand_option') || $('page_container').hasClassName('partner')) {
			return;
		}

		$('expand_option').style.display = 'block';
		ProductAllMenu.set_expand();
		ProductAllMenu.set_collapse();

		if (ProductAllMenu.is_expand_box_opened()) {
			$('expand_link').hide();
		} else {
			$('filter_expand').hide();
			$('collapse_link').hide();
		}
	},

	set_expand: function() {
		Element.observe('expand_link', 'click', function(event) {
			ProductAllMenu.expand();
			event.stop();
		});
	},
	expand: function() {
		$('filter_opened').value = '1';
		Effect.BlindDown('filter_expand', {
			afterFinish: function() {
				$('expand_link').hide();
				$('collapse_link').show();
				$('filter_expand').style.height = '';
			}
		});
	},

	set_collapse: function() {
		Element.observe('collapse_link', 'click', function(event) {
			ProductAllMenu.collapse();
			event.stop();
		});
	},
	collapse: function() {
		$('filter_opened').value = '0';
		Effect.BlindUp('filter_expand', {
			afterFinish: function() {
				$('collapse_link').hide();
				$('expand_link').show();
			}
		});
	},

	is_expand_box_opened: function() {
		var href = location.href;
		var start_location = href.search('opened=');
		if (start_location == -1) {
			return false;
		} else {
			var opened = href.substr(start_location+7, 1);
			if (opened == 1) {
				return true;
			} else {
				return false;
			}
		}
	}

}

new StartUp(ProductAllMenu);