$(document).ready(function()
{
	// remove/insert 'search' text on searchbox
 	$("#search_box").each(function()
	{
		document['def_'+$(this).attr('name')] = $(this).attr('value');
		$(this).focus(function()
		{
			if($(this).attr('value') == document['def_'+$(this).attr('name')]) $(this).attr('value','');
		});
		$(this).blur(function()
		{
			if($(this).attr('value') == '') $(this).attr('value',document['def_'+$(this).attr('name')]);
		});
	});
	
	
	// drop down menus
	$('.menu ul li').each(function(){
		$(this).find('ul').hide();
		
		$(this).hover(function()
			{
				$(this).find('ul').show();
				
				$(this).find('ul li').hover(function()
					{
						$(this).css({'background-color':'#999','cursor':'pointer'});
						$(this).find('a').css({'color':'#fff'});
					}, function()
					{
						$(this).css({'background-color':'#fff'});
						$(this).find('a').css({'color':'#000'});
					}
				);
			},function()
			{
				$(this).find('ul').hide();			
			}
		);
		
		// if you click on a list, it will be as if you've pressed the link
		$(this).click(function(){
			window.location = $(this).find('a').attr('href');
		});

	});
	
	$('.expanding').each(function(){
		// get elements (set as local var)
		var ex = $(this);
		var p = ex.find('p');
		// hide paragraphs as standard
		p.hide();
		
		expanding(ex, p, 'h3');
		expanding(ex, p, '.icon');
		
	});
	
	logmein('.tab_3');
});

function expanding(ex, p, search) {
	// on click, test to see if it's visible and show/hide
	ex.find(search).css('cursor','pointer').click(function(){
		if(p.is(':visible') == true) {
			p.slideUp();
			ex.find('.icon').removeClass('minus');
			ex.find('.icon').addClass('plus');
		}	else {
			p.slideDown();
			ex.find('.icon').removeClass('plus');
			ex.find('.icon').addClass('minus');
		}
	});
}

function logmein(trigger) {
	// get code from page and remove original
	var html = $('.logmein123').html();
	$('.logmein123').remove();
	
	// add lightbox to code
	html = '<div class="lightbox"><div class="logmein123">'+html+'</div></div>';

	// when you've selected trigger add lightbox and animate in
	$(trigger).click(function(ev) {
		ev.preventDefault();
		$(document).find('body').prepend(html).find('.lightbox').height($(document).height()).animate({opacity: 1}, 500, function() {	
			
			$(this).find('.logmein123').animate({top: $(window).scrollTop()}, 500);
			
			// once your done, clicking close will animate out and remove it
			$(this).find('.close').click(function() {
				$(document).find('.lightbox').animate({opacity: 0}, 500, function() {
					$(this).remove();
				});
			});
		});
	});
}
