$(function() {
	// ===============[ This is where you edit details for content inside the header ]===============
	// How to use:
	// Download and save this file as functions.js, do amends and reupload it, make sure you replace the old one
	
	// Header:
	
		// Left side:
		var lsLine1 = 'Call us today on';
		var lsLine2 = '01299 266 231';
		var lsLine3 = 'E-mail:';
		var lsLine4 = 'enquiries@wooldridgegaragedoors.co.uk';
		
		// Right side:
		var rsLine1 = '&pound;499 garage door special';
		var rsLine2 = 'Click here to get a new garage door, including frame, fitting, door installation, lock and VAT';
		
		// Logo details
		var homeURL = '/index.php?sid=36495&lang=en&act=page&id=145920';
		var linkTitle = 'Wooldridge Garage Doors';


	// ===============[ Don't alter lines below if you're not sure how it works ]===============
	
	// Building contact details in the header
	$('#header').prepend('<div id="headerLS"><strong>'+ lsLine1 +'</strong>'+ lsLine2 +'<strong>'+ lsLine3 +'</strong><a href="mailto:'+ lsLine4 +'">'+ lsLine4 +'</a></div>')
				.append('<div id="headerRS"><strong>'+ rsLine1 +'</strong><a href="/index.php?sid=36495&lang=en&act=page&id=164265">'+ rsLine2 +'</a></div>');

	// Wrapping logo with an anchor tag
	$('#siteMainDynHeaderImage1').wrap('<a href="'+ homeURL +'" title="'+ linkTitle +'" id="logoLink" />');
	
	// Subnav
	$('#header .sitemenu ul li ul').css({ height : 0 }).find('a').css({ opacity : 0 }).parent().parent().parent().addClass('subNav');
	
	$('#header .sitemenu ul li').hover(function() {
		$(this).addClass('hover');
		$('ul', this).stop().animate({ height : 37 }, { duration : 500, easing : 'swing' });
		$('ul li a', this).stop().animate({ opacity : 1 });
	}, function() {
		$(this).removeClass('hover');
		$('ul', this).stop().animate({ height : 0 }, { duration : 500, easing : 'swing' });
		$('ul li a', this).stop().animate({ opacity : 0 });
	});
	
	// Slider
	$('.sliderTarget').html($('#bgSlideshow'));
	
	// Pods
	var maxHeight = 0;
	$(".pod").each(function(){
	   if ($(this).height() > maxHeight) { maxHeight = $(this).height(); }
	});
	$(".pod").height(maxHeight);
	
	// Contact form
	function placeholder(el) {
		$(el).each(function() {
			var inputID = $(this).attr('id');
			var textVal = $('label[for="'+ inputID +'"]').text();
			$(this).val(textVal).css('color','#aaaaaa');
		});
	}
	placeholder($('input[type="text"], textarea'));
	
	$('input[type="text"], textarea').focus(function() {
		var inputID = $(this).attr('id');
		if ( $(this).val() == $('label[for="'+ inputID +'"]').text() ) {
			$(this).val('').css('color', '#4C4C4C');
		}
	}).blur(function() {
		var inputID = $(this).attr('id');
		if ( $(this).val() == $('label[for="'+ inputID +'"]').text() || $(this).val() == '' ) {
			placeholder($(this));
		}
	});
	
	$('input[type="reset"]').click(function() {
		placeholder($('input[type="text"], textarea'));
		return false;
	});
	
	$('#header').append('<div id="specialOffer"><a href="/index.php?sid=36495&lang=en&act=page&id=164265"><img src="/var/as/36495/591929-wooldridge-special-offer.png" /></a></div>');
	
	$('#specialOffer').animate({ width : 63, opacity : 1 }, 1500, 'easeOutQuint', function() {
		$(this).delay(2000).animate({ width : 0, opacity : 0 }, 1500, 'easeOutQuint');
	});
	
	setInterval(function() {
		$('#specialOffer').animate({ width : 63, opacity : 1 }, 1500, 'easeOutQuint', function() {
			$(this).delay(2000).animate({ width : 0, opacity : 0 }, 1500, 'easeOutQuint');
		});
	}, 5000);

});

$(window).load(function() {
	$('#slideOverlay').hide();
	$('#slide-3 img').wrap('<a href="/var/as/36495/495961-video.html" rel="fancybox" id="fancybox" />');
	$('#fancybox').fancybox();
});
