$(function() {
	$('body').removeClass('no-JS');
	
	//Init Main Slider
	$('#slider').anythingSlider({
		"delay": 6000,
		"animationTime": 1500,
		"buildNavigation": false,
		"buildArrows": false
	});
	
	//Bind Controls to Main Slider
	$('#slider-next').click(function(e) {
		e.preventDefault();
		$('#slider').data('AnythingSlider').goForward();
		$('#slider').data('AnythingSlider').startStop(true);
	});
	$('#slider-prev').click(function(e) {
		e.preventDefault();
		$('#slider').data('AnythingSlider').goBack();
		$('#slider').data('AnythingSlider').startStop(true);
	});
	
	//Init News Slider
	$('#news-slider').anythingSlider({
		"animationTime": 400,
		"buildNavigation": false,
		"buildArrows": false,
		"autoPlay": false,
		"width": 554,
		"height": 339
	});
	
	//Bind Controls to News Slider
	$('#news-wrapper').find('.next').click(function(e) {
		e.preventDefault();
		$('#news-slider').data('AnythingSlider').goForward();
	});
	$('#news-wrapper').find('.prev').click(function(e) {
		e.preventDefault();
		$('#news-slider').data('AnythingSlider').goBack();
	});
	
	/* Fix for IE6 :hover on every other element than <a> */
	$('#menu').find('.menu-item').hover(function(e) {
		$(this).addClass('ie6-hover-fix');
	},
	function(e) {
		$(this).removeClass('ie6-hover-fix');
	});
	
	/* Forces last drop down menu to align to the right side of the menu container */
	var mc = $('#menu-container');
	var mc_x = mc.offset().left + mc.outerWidth();
	$('#menu').find('ul').each(function(i, v) {
		$(v).show();
		var ul_x = $(v).offset().left + $(v).outerWidth();
		if (ul_x > mc_x) {
			$(v).css({'right': '0', 'left': 'auto'});
		}
		$(v).css('display', '');
	});
	
	/* Add hover color to list item when hovering over the imagemap */
	$('area').hover(function(e) {
		var l = $(this).attr('href');
		$('#shopLinks').find('a[href="'+l+'"]').addClass('link-hover');
		console.log($('#shopLinks').find('a[href="'+l+'"]'));
	}, function(e) {
		var l = $(this).attr('href');
		$('#shopLinks').find('a[href="'+l+'"]').removeClass('link-hover');
	});
	
	/* Mark the dot on the map when hovering over the list item */
	$('#shopLinks').find('a').hover(function(e) {
		
		//Get coords of the area-element.
		var coords = $('area[href="'+$(this).attr('href')+'"]').prop('coords').split(',');
		
		//Create the image with the black dot
		var img = $('<img id="hoverImg" title="Yep" src="styles/images/black-dot.gif" />');
		
		//Get the offset of the map.
		var mapCoords = $('.main-image').offset();
		
		//Add image to the html body.
		img.appendTo('body');
		
		//Calc x and y
		var x = mapCoords.left + parseInt(coords[0]) - ($(img).width() / 2);
		var y = mapCoords.top + parseInt(coords[1]) - ($(img).height() / 2);
		if (navigator.appName == 'Microsoft Internet Explorer')  {
			var x = (mapCoords.left + parseInt(coords[0]) - ($(img).width() / 2))+3.5;
			var y = (mapCoords.top + parseInt(coords[1]) - ($(img).height() / 2))+3;
			}

		img.css({
			'left': x,
			'top': y
		});
		
	}, function(e) {
		$('#hoverImg').remove();
	});
	
});
