function moveMenuBg(href, pos, diff) {
	var a = $('div#menu table a[href='+href+']:first');
	if(a) {
		if(a.attr('class') && a.attr('class').match(/curr/)) {
			// Skip
		} else {
			if(!a.attr('class') || !a.attr('class').match(/hover/)) {
				a.css('background-position','0 '+pos+'px');
				a.addClass('hover');
			}
			var new_bp = pos + diff;
			if(new_bp>=23 && new_bp<=29) {
				a.css('background-position','0 '+new_bp+'px');
				if(new_bp>23 && new_bp<29) {
					setTimeout('moveMenuBg("'+href+'", '+new_bp+', '+diff+')', 50);
				}
			} else if (new_bp>29) {
				$(this).removeClass('hover');
				a.css('background-position','0 29px');
			}
		}
	}
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) { expires = expires * 1000 * 60 * 60 * 24; }
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}
function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) { return ''; }
	if ( start == -1 ) return '';
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

$(function() {
	var fname = document.location.href.replace(/^.*\//,'');
	if(fname && fname!='') {
		$('div#menu table a[href='+fname+']').addClass('curr');
	} else {
		$('div#menu table a[href=index.html]').addClass('curr');
	}
	$('div#menu table a').hover(
		function() { moveMenuBg($(this).attr('href'), 29, -1); },
		function() { setTimeout('moveMenuBg("'+$(this).attr('href')+'", 23,  1)',300); }
	);

	// alert(fname);
	if(fname == 'adult.html') {
		Set_Cookie('portfolio', 'adult', 1, '/');
	} else if(fname == 'portfolio.html') {
		Set_Cookie('portfolio', 'normal', 1, '/');
	}
	if(Get_Cookie('portfolio') && Get_Cookie('portfolio')=='adult') {
		$('div#menu table a[href=portfolio.html]').attr('href', 'adult.html');
	}
});

