var InitTimer;

function LaunchPopup(element,Pos){
	$('#'+element).stop().animate(
		{backgroundPosition:"(0 "+Pos+")"},{duration:200}
	)
}

function LaunchImageAdd(){	
	 Shadowbox.open({
        content:    'http://upload.artspaceonline.org/UploadImage.asp',
        player:     "iframe",
        title:      "Upload an image to the ArtWall.",
        height:     450,
        width:      552
    });
}

var BGTimer;
var OutTimer;
var OutTicks=0;
var MoveReady=true;
var XPos;
var XposLast;
var HomingX;
var WobbleState=0;
var WobbleArray = new Array();
var GlowOffset=699;



$(document).ready(function() {
	$("#NavBarBG").stop().css({left: (HomingX-700)+'px'});
	var menupos=$('#Logo').offset();
	//alert(menupos.left+' '+menupos.top);
	var SwirlPos=(HomingX)-20;
	$("#MenuTopSwirl").css({left: (SwirlPos-15)+'px', top: '51px'});
	$("#MenuBottomSwirl").css({left: SwirlPos+'px', top: '84px'});
	$('#MenuTopSwirl').css( {backgroundPosition: "0 0"} );
	$('#MenuBottomSwirl').css( {backgroundPosition: "0 -15"} );	
	AnimateSwirls();
	$('#NavHolder').mousemove(function(e){
		OutTicks=0;
		XPos=(e.pageX-this.offsetLeft-700);
		XPosLast=XPos;
		if(MoveReady){	
			clearTimeout(BGTimer);
			BGTimer=setTimeout('MoveBackground('+XPos+')',20);
			MoveReady=false;
		}
	})
	.mouseleave(function(){
		OutTicks=0;
		clearTimeout(BGTimer);
		$("#NavBarBG").stop().animate({left: (HomingX-700)+'px'},700,'easeOutBack',function(){MoveReady=true;});		
	});
		
})		

function AnimateSwirls(){
	$('#MenuTopSwirl').css( {backgroundPosition: "0 0"} ).stop().animate(
							{backgroundPosition:"(0 -20)"},{duration:400});
	$('#MenuBottomSwirl').css( {backgroundPosition: "0 -15"} ).stop().animate(
							{backgroundPosition:"(0 0)"},{duration:400});
}

function MoveBackground(XPos){
	clearTimeout(BGTimer);
	$("#NavBarBG").stop().animate({left: (XPos)+'px'},400,
		function(){
			MoveReady=true;
			if (XPosLast!=XPos){
				BGTimer=setTimeout('MoveBackground('+XPosLast+')',20);
				MoveReady=false;
			}
		}
	);
}

function GlowReset(){
	clearTimeout(OutTimer);
	OutTicks++;
	if (OutTicks>=14){
		WobbleState=0;
		OutTicks=0;
		alert('Reset');
	}
	else if(OutTicks>=5 && OutTicks<14){		
		if (WobbleState>8){WobbleState=8;}
			$("#NavBarBG").animate({
				left: parseInt(WobbleArray[WobbleState])+'px'
			},200,function(){
				OutTimer=setTimeout(GlowReset(),3);
			});
		WobbleState++;		
	}
	else {
		OutTimer=setTimeout(GlowReset(),200);
	}
}

Cufon.replace('h1');
Cufon.replace('h1', {textShadow: '2px 2px rgba(51, 51, 51, 0.6)'});				
Cufon.replace('h2');
Cufon.replace('h2', {textShadow: '2px 2px rgba(51, 51, 51, 0.6)'});		
Cufon.replace('#NavBar ul li');
Cufon.replace('h3');