// binds onmouseover and other events to item link
function bind_actions(i) {
	$('#menulink_'+i).bind('mouseover', function() {
		$('#ita'+i).attr('class', 'item_top');
		$('#itb'+i).attr('class', 'home_item');
		$('#itc'+i).attr('class', 'item_bottom');
	});
	
	$('#menulink_'+i).bind('focus', function() {
		$('#ita'+i).attr('class', 'item_top');
		$('#itb'+i).attr('class', 'home_item');
		$('#itc'+i).attr('class', 'item_bottom');
	});
	
	$('#menulink_'+i).bind('mouseout', function() {
		$('#ita'+i).attr('class', 'item_top_unselected');
		$('#itb'+i).attr('class', 'home_item_unselected');
		$('#itc'+i).attr('class', 'item_bottom_unselected');
	});
	
	$('#menulink_'+i).bind('blur', function() {
		$('#ita'+i).attr('class', 'item_top_unselected');
		$('#itb'+i).attr('class', 'home_item_unselected');
		$('#itc'+i).attr('class', 'item_bottom_unselected');
	});
}

// deselects currently selected item and selects a new one
function change_item(oldID, newID) {
	$('#ita' + oldID).attr('class', 'item_top_unselected');
	$('#itb' + oldID).attr('class', 'home_item_unselected');
	$('#itc' + oldID).attr('class', 'item_bottom_unselected');
	$('#menulink_' + oldID).attr('class', '');
	bind_actions(oldID);
	
	// select a new item
	$('#ita' + newID).attr('class', 'item_top');
	$('#itb' + newID).attr('class', 'home_item');
	$('#itc' + newID).attr('class', 'item_bottom');
	$('#menulink_' + newID).attr('class', 'current');
	$('#right_content').html($('#content_' + newID).html());
	$('#menulink_' + newID).unbind('mouseover');
	$('#menulink_' + newID).unbind('mouseout');
	$('#menulink_' + newID).unbind('focus');
	$('#menulink_' + newID).unbind('blur');
}

$(document).ready(function(){
	// bind onmouseover, onmouseout, onfocus and onblur to the 'I am' menu items
	// so we can change their backgrounds dynamically (they have rounded corners)
	// ... and start automatic home page items changing
	$('div').each(function () {
		if ($(this).attr('class') == 'menu_wrapper') {
			var i = this.id.substring(13);
			if ($('#ita'+i).attr('class') != 'item_top') {
				bind_actions(i);
			}
		}
	});

	// assign event listeners to all links, so when clicked, items are not being rotated anymore
	$('a').each(function () {
		if ($(this).attr('rel') == 'home_link') {
			$(this).bind('click', function() {
				var i = this.id.substring(9);
				change_item(last_item, i);
				last_item = i;
				return false;
			});
		}
	});

	last_item = 1;
});

all_items = $('#all_items').val();