function moveToPosition(elm,position) {
	document.getElementById(elm).childNodes[0].style.top = position+"px";
}

function assignMenuAnimations() {
	$("#m a").mouseover(function(){
	// animate forwards
		id = this.id;
		moveToPosition(id,-70);
		setTimeout("moveToPosition('"+id+"',-35)",30);
		setTimeout("moveToPosition('"+id+"',0)",60);
	});
	$("#m a").mouseout(function(){
	// animate backwards
		id = this.id;
		moveToPosition(id,-35);
		setTimeout("moveToPosition('"+id+"',-70)",30);
		setTimeout("moveToPosition('"+id+"',-105)",60);
	});
}

function d2h(d) {return d.toString(16);}
function h2d(h) {return parseInt(h,16);}
function cpt(v,a,lb,lt) { // compute: value, (+/-)amount, limit bottom, limit top
	v = v + a;
	if (v < lb) v = lb;
	if (v > lt) v = lt;
	return v;
}

function changeColor(c,hm) {
	cpart_r = d2h(cpt(h2d(c.substr(1,2)),hm,0,255));
	cpart_g = d2h(cpt(h2d(c.substr(3,2)),hm,0,255));
	cpart_b = d2h(cpt(h2d(c.substr(5,2)),hm,0,255));
	c = "#"+cpart_r+cpart_g+cpart_b;
	return c;
}

function hiliteObject(elm,color) {
	$(elm).css("background-color",color);
}

function makeAnimatedHover(elm,from,hms) {
	$(elm).hover(function(){
		hiliteObject(elm,changeColor(from,hms));
	},function(){
		hiliteObject(elm,from);
	});
}

function slideObject(elm) {
	$(elm).animate({width: 240,left: -10},700);
	setTimeout("hiliteObject('"+elm+" .smallBoxIn','#656567')",850);
	setTimeout("hiliteObject('"+elm+" .smallBoxIn','#707074')",900);
	setTimeout("makeAnimatedHover('"+elm+" .smallBoxIn','#707074',+50)",1000);
}

function slideRightBox() {
	$("#rightBox").animate({height: 436},1000);
}

function fadeIn(elm) {
	$(elm).css("display", "block");
	$(elm).fadeIn(400);
	$(elm).hover(function(){
			$(this).fadeTo(200,0.7);
	},function(){
			$(this).fadeTo(200,1);
	});
}

init = function() {
	
	$("a.newWin").click(function(){
		window.open(this.href);
		return false;
	});
	
	$("#m img").each(function(){
			src = $(this).attr("src");
			src = src.substring(0,(src.length-4)) + "-a.gif";
			$(this).css("top","-105px");
			$(this).attr("src",src);
	});
	
	assignMenuAnimations();
	
	if(document.getElementById('rightBox')) {
		document.getElementById('rightBox').style.height = '0px';
		slideRightBox();
	}	
	
	if(document.getElementById('so1')) {
		setTimeout("slideObject('#so1')",500);
		setTimeout("slideObject('#so2')",900);
		setTimeout("slideObject('#so3')",1300);
		if(document.getElementById('so4')) {
			setTimeout("slideObject('#so4')",1700);
		}
	}	
	
	if(document.getElementById('pid8')) {
		setTimeout("fadeIn('#pid1')",1000);
		setTimeout("fadeIn('#pid2')",1200);
		setTimeout("fadeIn('#pid3')",1400);
		setTimeout("fadeIn('#pid4')",1600);
		setTimeout("fadeIn('#pid5')",1800);
		setTimeout("fadeIn('#pid6')",2000);
		setTimeout("fadeIn('#pid7')",2200);
		setTimeout("fadeIn('#pid8')",2400);
	}

}

$(document).ready(init);
