
jQuery.fn.anchorAnimate = function(settings) {

 	settings = jQuery.extend({
		speed : 1100
	}, settings);

	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")

			var destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}

jQuery.fn.menuList = function() {
	return this.each(function(){
		$(this).click(function (event) {
			event.preventDefault();
			$('#filter-category').val( $(this).attr('href') );
			$('#filter-category').change();
		})
	})
}

var hoverColour = "#FFF";

$(document).ready(function() {


	$('#filter-category').change(function() {
		var filterVal = $(this).val().toLowerCase() , destination = null , elementClick = null;

		switch(filterVal)
		{
			case '#webdesign':
				destination  = $('#web_anchor').offset().top;
				elementClick = '#web_anchor';
			break;
			case '#photografy':
				destination = $('#photo_anchor').offset().top;
				elementClick = '#photo_anchor';
			break;
			case '#photo':
				destination = $('#digital_anchor').offset().top;
				elementClick = '#digital_anchor';
			break;
		}

		if(destination){
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100, function() {
				window.location.hash = elementClick
			});
		}

		return false;
	});

	$('ul.menuList').slideUp('medium');
	$('ul.menuList a').menuList();

	$("a.anchorLink").anchorAnimate()

	$("a.hoverBtn").show("fast", function() {
		$(this).wrap("<div class=\"hoverBtn\">");
		$(this).attr("class", "");
	});

	//display the hover div
	$("div.hoverBtn").show("fast", function() {
		//append the background div
		$(this).append("<div></div>");

		//get link's size
		var wid = $(this).children("a").width();
		var hei = $(this).children("a").height();

		//set div's size
		$(this).width(wid);
		$(this).height(hei);
		$(this).children("div").width(wid);
		$(this).children("div").height(hei);

		$(this).children("a").hover(function(){

			$(this).parent().children("div")
				.stop()
				.css({"display": "none", "opacity": "1"})
				.fadeIn("fast");
		},function(){
			//fade out the background

			 $(this).parent().children("div")
				.stop()
				.fadeOut("slow");
		});

	});


	$('body').click(function(event) {
		 if($(event.target).is('.menuListBtn'))
		{
			$('ul.menuList').slideToggle('medium');
		}
		else
		{
			$('ul.menuList').slideUp('medium');
		}
		event.stopPropagation();
	});

});
