// functions for showing product categories
function hide_all_product_categories() {
	for (i = 0; i < os_categories.length; i++) {
		var target_id = 'homepage_product_scrollbar_' + os_categories[i];
		var item_to_hide = document.getElementById(target_id);
		item_to_hide.style.display = 'none';
		var target_tab = 'product_scrollbar_tab_' + os_categories[i];
		var tab_to_change = document.getElementById(target_tab);
		tab_to_change.className = 'product_scrollbar_tab';
	}
}
function show_product_category(selected_category) {
	hide_all_product_categories();
	var target_id = 'homepage_product_scrollbar_' + selected_category; 
	var item_to_show = document.getElementById(target_id);
	item_to_show.style.display = 'block';
	var target_tab = 'product_scrollbar_tab_' + selected_category;
	var tab_to_change = document.getElementById(target_tab);
	tab_to_change.className = 'product_scrollbar_tab_selected';
	if (selected_category != current_product_os && selected_category != 'all') { 
		select_product(os_categories_default_products[selected_category], selected_category);
	}
}

// functions for showing product content
function select_product(product, product_os) {
	if (product != current_product) { // only perform actions if current product is not the same as the product selected
		// reset class styles for current product selection items
		document.getElementById('select_' + current_product + '_' + current_product_os).className = 'product_scroll';
		document.getElementById('select_' + current_product + '_all').className = 'product_scroll';
		// set class styles for selected product items
		document.getElementById('select_' + product + '_' + product_os).className = 'product_scroll_selected';
		document.getElementById('select_' + product + '_all').className = 'product_scroll_selected';
		// set animation settings
		animation_position_start = 384;
		animation_position_end = 0;
		animation_interval = 50;
		animation_time_index = 0;
		animation_duration = 400;
		// set z-index of new slide
		document.getElementById('content_slide_' + product).style.zIndex = content_slide_zindex;
		// call to animation
		animate_content_slide(product, current_product);
		// set current product and current product os values
		current_product = product;
		current_product_os = product_os;
	} 	
}
function animate_content_slide(product, old_product) {
	var current_position = Math.ceil(animation_position_start + (animation_position_end - animation_position_start) * Math.pow((animation_time_index/animation_duration), .25));
	document.getElementById('content_slide_' + product).style.top = current_position + 'px';
	if (current_position > 0) { //continue calling this function
		animation_time_index = animation_time_index + animation_interval;
		setTimeout("animate_content_slide('" + product + "', '" + old_product + "')", animation_interval);
	} else {
		content_slide_zindex = content_slide_zindex + 1;
		document.getElementById('content_slide_' + old_product).style.top = '384px';
		// reset animation time index
		animation_time_index = 0;
	}
}

// functions for scrolling product scrollbar
function scroll_left(os_to_scroll) {	
	var scrolling_element_offset;
	var offset_variable_name = 'offset_' + os_to_scroll;
	eval('scrolling_element_offset = ' + offset_variable_name + ';');
	var scrolling_element_min_offset;
	var min_offset_variable_name = 'min_offset_' + os_to_scroll;
	eval('scrolling_element_min_offset = ' + min_offset_variable_name + ';');
	if (scrolling_element_offset < 0) { // we can scroll this element
		var scrolling_element_id = 'scroll_content_area_' + os_to_scroll;
		// set animation settings
		animation_position_start = scrolling_element_offset;
		animation_position_end = scrolling_element_offset + 750;
		animation_interval = 25;
		animation_time_index = 0;
		animation_duration = 350;
		// call to animation
		animate_scrollbar(scrolling_element_id);
		// set offset to new offset
		eval(offset_variable_name + ' = animation_position_end;');
		// check to see if button states need to change
		if (animation_position_end == 0) { // we need to to disable the left scroll button
			var left_scroll_button_id = 'left_scroll_button_' + os_to_scroll;
			var left_scroll_button = document.getElementById(left_scroll_button_id);
			left_scroll_button.href = '#';
			left_scroll_button.className = 'left_scroll_button_disabled';
		}
		if (animation_position_end > scrolling_element_min_offset) { // we need to enable the right scroll button
			var right_scroll_button_id = 'right_scroll_button_' + os_to_scroll;
			var right_scroll_button = document.getElementById(right_scroll_button_id);
			right_scroll_button.className = 'right_scroll_button';
		}					
	}
}
function scroll_right(os_to_scroll) {
	var scrolling_element_offset;
	var offset_variable_name = 'offset_' + os_to_scroll;
	eval('scrolling_element_offset = ' + offset_variable_name + ';');
	var scrolling_element_min_offset;
	var min_offset_variable_name = 'min_offset_' + os_to_scroll;
	eval('scrolling_element_min_offset = ' + min_offset_variable_name + ';');
	if (scrolling_element_offset > scrolling_element_min_offset) { // we can scroll this element
		var scrolling_element_id = 'scroll_content_area_' + os_to_scroll;
		// set animation settings
		animation_position_start = scrolling_element_offset;
		animation_position_end = scrolling_element_offset - 750;
		animation_interval = 25;
		animation_time_index = 0;
		animation_duration = 350;
		// call to animation
		animate_scrollbar(scrolling_element_id);
		// set offset to new offset
		eval(offset_variable_name + ' = animation_position_end;');
		// check to see if button states need to change
		if (animation_position_end < 0) { // we need to to enable the left scroll button
			var left_scroll_button_id = 'left_scroll_button_' + os_to_scroll;
			var left_scroll_button = document.getElementById(left_scroll_button_id);
			left_scroll_button.href = '#';
			left_scroll_button.className = 'left_scroll_button';
		}
		if (animation_position_end == scrolling_element_min_offset) { // we need to disable the right scroll button
			var right_scroll_button_id = 'right_scroll_button_' + os_to_scroll;
			var right_scroll_button = document.getElementById(right_scroll_button_id);
			right_scroll_button.className = 'right_scroll_button_disabled';
		}		
	}
}
function animate_scrollbar(scrolling_element_id) {
	var current_position = Math.ceil(animation_position_start + (animation_position_end - animation_position_start) * Math.pow((animation_time_index/animation_duration), .25));
	document.getElementById(scrolling_element_id).style.left = current_position + 'px';
	if (current_position != animation_position_end) { //continue calling this function
		animation_time_index = animation_time_index + animation_interval;
		setTimeout("animate_scrollbar('" + scrolling_element_id + "')", animation_interval);
	} else {
		// reset animation time index
		animation_time_index = 0;
	}
}