// changes how many items to display on item display
function displayAmount(amount) {
	currentLocation = '' + window.location;

	// this is kind of gross?
	// i could probably replace both of these with a -really- good written regexp but eh.
	/*
		*/
		
	if (!currentLocation.match(/page=/)) { // ugggh check for fancy urls
		if (currentLocation.match('/limit/([0-9]*)')) { // is it in the middle?
			newLocation = currentLocation.replace(/\/limit\/([0-9]*)*/, '/limit/' + amount + '');
			window.location = newLocation;
		} else {
			// no existing limit parameter, just tack it on
			slash = '';
			if (!currentLocation.match(/\/$/)) { // hey does this have a trailing slash or what
				slash = '/';
			}
			window.location = window.location + slash + 'limit/' + amount + '/';
		}		
	} else {
		if (currentLocation.match('limit=.*&')) { // is it in the middle?
			newLocation = currentLocation.replace(/limit=.*&/, 'limit=' + amount + '&');
			window.location = newLocation;
		} else if (currentLocation.match('limit=.*$')) { // is it at the end?
			newLocation = currentLocation.replace(/limit=.*$/, 'limit=' + amount);
			window.location = newLocation;
		} else {
			window.location = window.location + '&limit=' + amount;
		}		
	}
		

}

function updateCartTotal(amount) {
	if(String(amount).substring(0,1) == '-' || String(amount).substring(0,1) == '+') {
		// is this a string with + or -
		var totalCartItems = parseInt($('topBarCartAmount').innerHTML);

		if (isNaN(totalCartItems)) {
			totalCartItems = 0;
		}

		totalCartItems = eval(totalCartItems + amount);

	} else {
		// accept a direct integer
		totalCartItems = parseInt(amount);

	}

	if (totalCartItems <= 0 || isNaN(totalCartItems)) {
		$('topBarCartAmount').innerHTML = 'no';
		$('topBarItemWord').innerHTML = 'items';
	} else if (totalCartItems == 1) {
		$('topBarCartAmount').innerHTML = totalCartItems;
		$('topBarItemWord').innerHTML = 'item';
	} else {
		$('topBarCartAmount').innerHTML = totalCartItems;
		$('topBarItemWord').innerHTML = 'items';
	}

}

function dropLogin() {
	Effect.SlideDown('loginBox');
	//Effect.BlindDown('loginBox');
}

function raiseLogin() {
	Effect.SlideUp('loginBox');
	//Effect.BlindUp('loginBox');
}

/*
John Resig's cross-browser event handler code
It is a lifesaver.
URL: http://ejohn.org/projects/flexible-javascript-events/
*/
function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}
function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
}


function sizeSelect(index) {
	if (index != 'bonk') {
		window.location = '/size/' + index + '/';
	}
}

