/* EFFECTS*/
$(document).ready(function(){
/* tooltipp */
	$('a[rel=tooltip]').mouseover(function(e) {
		var tip = $(this).attr('title');	
		$(this).attr('title','');
		$(this).append('<div id="tooltip"><div class="tipBody">' + tip + '</div></div>');		
		$('#tooltip').fadeIn('500');
	}).mousemove(function(e) {
		var parentpos = $(this).offset();
		$('#tooltip').css('top', e.pageY - parentpos.top + 18);
		$('#tooltip').css('left', e.pageX - parentpos.left - 45);
	}).mouseout(function() {
		$(this).attr('title',$('.tipBody').html());
		$(this).children('div#tooltip').remove();
	});


/* Text Conversion */
	$('.tunebigText').hover(function(){
		$('.bm',this).stop().animate({"opacity": "1"}, "fast");
		$('.eng',this).stop().animate({"opacity": "0"}, "fast");
	}, function() {
            $('.bm',this).stop().animate({"opacity": "0"}, "fast");
            $('.eng',this).stop().animate({"opacity": "1"}, "fast");
	});
	
	$('#home_tunebig').hover(function(){
		$('h3',this).animate({backgroundPosition:'0px -50px'},{queue:false,duration:200});
	});
	
	$('#about_tunebig').hover(function(){
		$('h3',this).animate({backgroundPosition:'0px -50px'},{queue:false,duration:200});
	});
	
	$('#about_tunebig2').hover(function(){
		$('h3',this).animate({backgroundPosition:'0px -50px'},{queue:false,duration:200});
	});

	$('#contact_tunebig').hover(function(){
		$('h3',this).animate({backgroundPosition:'0px -50px'},{queue:false,duration:200});
	});


//function to be called whenever the window is scrolled or resized
	function Move(){ 
		var pos = $window.scrollTop(); //position of the scrollbar
		windowHeight = $window.height();
		var bodyHeight = $('body').height();
		if($homeBG.hasClass("inview")){
            $homeBG.animate({'backgroundPosition': newPos(50, 0, pos, 0, 0.1)},{queue:false,duration:300});
            chameleon.animate({'backgroundPosition': newPos(50, 0, pos, 0, 0.3)},{queue:false,duration:300});
            bubbles.animate({'backgroundPosition': newPos(50, 0, pos, 0, 1.2)},{queue:false,duration:200});
            $('#menu').addClass('inAnimation').animate({"left": "0", "width": "450px"},{queue:false,duration:300,complete:function(){$(this).removeClass('inAnimation')}});
		} else {
            $('#menu').addClass('inAnimation').animate({"left": "450px", "width": "510px"},{queue:false,duration:300,complete:function(){$(this).removeClass('inAnimation')}});
        }
		if($workBG.hasClass("inview")){
		}
		if($aboutBG.hasClass("inview")){
            aboutSmokeSmall.animate({'backgroundPosition': newPos(50, 0, pos, 0, -0.6)},{queue:false,duration:200});
            aboutSmokeBig.animate({'backgroundPosition': newPos(50, 0, pos, 0, -0.2)},{queue:false,duration:800});
			$('#menu').animate({backgroundPosition:'0px -50px'},{queue:false,duration:50});
		} else { 
			$('#menu').animate({backgroundPosition:'0px 0px'},{queue:false,duration:50});
        }
		if($contactBG.hasClass("inview")){
			var maxDogBottom = bodyHeight-windowHeight;
			var maxDogBottomTop = windowHeight - 650;
			dog.animate({'backgroundPosition': newPosBottom(50, maxDogBottom, pos, maxDogBottomTop, 0.5)},{queue:false,duration:200});
            contactNoise.animate({'backgroundPosition': newPos(50, 0, pos, 0, 10.0)},{queue:false,duration:1000});
		}
    }

	RepositionNav(); //Reposition the Navigation to center it in the window when the script loads
	$window.resize(function(){ //if the user resizes the window...
		Move(); //move the background images in relation to the movement of the scrollbar
		RepositionNav(); //reposition the navigation list so it remains vertically central
	});		
	$window.bind('scroll', function(){ //when the user is scrolling...
		Move(); //move the background images in relation to the movement of the scrollbar
	});
});

