/* Original Reference: http://blog.freelancer-id.com/index.php/2009/03/26/scroll-window-smoothly-in-jquery

Modified by Pieris Christou, enables the specified element to be used as an anchor */

/* Allows initial heading to have changing/alternating colours when user clicks on the 'To_top' links */
var altPulse = false;

/* Prevents user from entering multiple clicks upon scrolling */
var scrolling = false;

function scrollWin(anchor){
if(scrolling == false){
scrolling = true;
$('html,body').animate({scrollTop: $('#'+anchor).offset().top}, 400, "linear", function(){scrolling = false;} 
);

	}
} 

function alternate_top()
{


/* Allows the alternating colours when the 'home' or 'back to top' links are clicked*/
if(altPulse == false){

altPulse = true;
    	pulsate("msg","#247edd","#FFFFFF"); 
	pulsate("welcome","#247edd","#000000");
} else {

altPulse = false;
	pulsate("msg","#f3b100","#000000"); 
	pulsate("welcome","#f3b100","#FFFFFF");
}

}

/* Upon mouseup, light up the heading in the specified colour, in this case - orange (#f3b100) 
   Decided to go for a slightly darker orange than the border so its not too bright */
function pulsate(heading, pulsatedColour, afterColour){
	$('#'+heading).animate({ color: pulsatedColour }, { queue:true, duration:800 } );
    $('#'+heading).animate({ color: afterColour }, { queue:true, duration:400 } );
    
}


/* Scroll to the desired section of the site before pulsating the heading */
$(document).ready(function() {
    $("#homeButton").mouseup(function(){
	scrollWin('top_anchor');

	alternate_top();
    });

    $("#aboutButton").mouseup(function(){
	scrollWin('about');
    		pulsate("aboutheading","#247edd","#ffffff");

    });


    $("#workButton").mouseup(function(){
	scrollWin('work');
    		pulsate("workheading","#247edd","#ffffff");

    });


    $("#contactButton").mouseup(function(){
	scrollWin('contact');
    		pulsate("contactheading","#247edd","#ffffff");

    });

    $(".top").click(function(){
	scrollWin('top_anchor');

alternate_top();

    });
/******** End pulsating event handlers ********/


/* Returning false prevents a stutter/flash when a button is pressed and the smooth scroll is invoked */

   $("#homeButton").click(function(){
	return false;
    });

    $("#aboutButton").click(function(){
	return false;

    });

    $("#workButton").click(function(){
	return false;

    });


    $("#contactButton").click(function(){
	return false;
    });

    $(".top").click(function(){
	return false;
    });

/******** End return false section ********/


});
