$(function() {
	// define page elements
	var email = 'leisurequipltd@btconnect.com';
	
	var logo = $('#siteMainDynHeaderImage1');
	var trigger = $('#content .sitemenu ul li');
	var subMenu = $('#content .sitemenu > ul > li > ul');
	var slideshow = $('#bgSlideshow');
	var contactDetails = '<div id="headerDetails"><p>tel: <span>01428 771 439</span><br /><span>020 7477 2254</span><br />e-mail: <span><a href="mailto:'+ email +'" title="E-mail Us">'+ email +'</a></span></p></div>';
	var footerDetails = '<div class="footerColumn">tel: <span class="lightBlue">01428 771 439</span><br />e-mail: <a href="mailto:'+ email +'" title="E-mail Us">'+ email +'</a></div><div class="footerColumn lightBlue">Longwood House, Barley Mow Hill<br />Headley, Bordon<br />Hampshire, GU35 8AG</div>';
	
	var $bloggerURL = 'http://tylo-sauna-steam.blogspot.com/';
	var $facebookURL = 'https://www.facebook.com/pages/Leisurequip/241963812495131?sk=app_208195102528120';
	var $youtubeURL = 'http://www.youtube.com/user/saunas4you';
	var $tyloPricesURL = 'http://www.tylo-sauna-steam.com/var/ao/28125/513655-Tyl%C3%B6%20Price%20List%202011%20reduced.pdf';
	
	$bookmarks = '<div id="bookmarks"><a href="' + $tyloPricesURL + '" title="Tylo Price List" id="tyloPircelist"><span>Check the Tylo price list</span></a><a href="' + $facebookURL + '" title="Follow us on Facebook" id="facebook" class="socialIcon">Leisurequip on Facebook</a><a href="' + $youtubeURL + '" title="Leisurequip on Youtube" id="youtube" class="socialIcon">Leisurequip Videos</a><a href="' + $bloggerURL + '" title="Leisurequip Blog" id="blog" class="socialIcon">Leisurequip Blog</a></div>';
	
	$('#menuWrapper li a').text( function(){
		return $(this).text().replace( /(SR)\s/, '' );
	});
	
	/* =====[ custom functions ]==== */
	
	// wrap logo with an anchor tag
	$(logo).wrap('<a href="/index.php?sid=28125&lang=en&act=page&id=108886" id="logoLink" title="Leisurequip Ltd" />');

	// add class to the triggers
	$(subMenu).parent().addClass('subNavTrigger');
	
	// dropdown menu
	$(subMenu).hide();
	
	$(trigger).hover(function(){
		$('ul', this).delay(200).fadeIn(400);
	},
	function(){
		$('ul', this).delay(200).hide().clearQueue();
	});
	
	// bookmarks
	$('#header').append($bookmarks);
	
	$('#bookmarks a').not('#tyloPircelist').css('opacity', '0.5');
	
	$('#bookmarks a').not('#tyloPircelist').hover(
	function() {
		$(this).stop().animate({
			opacity: 1.0
		});
	}, 
	function() {
		$(this).stop().animate({
			opacity: 0.5
		});
	});
	
	$('#tyloPircelist').hover(function() {
		$(this).stop().animate({ marginTop : '-17px' }, { duration : 100, queue : false, complete :
			function() {
				$(this).animate({ marginTop : '-11px' }, { duration : 100, queue : false });
			}
		});
	}, function() {
		$(this).stop().animate({ marginTop : '-17px' }, { duration : 100, queue : false, complete :
			function() {
				$(this).animate({ marginTop : '-11px' }, { duration : 100, queue : false });
			}
		});
	});
	
	if ( $('#bgSlideshow').length == 1 ) { 
		$('address').hide(); 
	}
	
	// move slideshow
	$('.slideshowTarget').append(slideshow);
	
	// append contact details in the header
	$('#header').append(contactDetails);
	
	
	
	// append contact details in the footer
	$('#footer').append(footerDetails);
	
	// move CTA inside .wideImage
	$('.wideImage').append($('address'));
	
	// Additional slider navigation
	$('.controlSlider').each(function () {
		var attr = $(this).attr('rel');
		$(this).bind('click', function() {
			$('.btnNav[rel='+attr+']').trigger('click');
		});
	});
	
	

});

$(window).load(function() {
	function timeouter(el, time){
		setTimeout(function() {
			$(el).fadeOut(500);
		},time);
	}
	$('li.current.subNavTrigger ul').show(0, function() {
		timeouter(this, 5000);
	});
});
