/*
 * tpad v3 global js
 * pglh 30/11/2009
 */

// Allows us to specify CSS rules that only take effect if JS is enabled
$('html').addClass('js-enabled');

mlfAnimating = false;

$(document).ready( function()
{
	// JQuery-enabled top and bottom navigation
	// --------------------------------------------------------------------------------------------

	$('.jquery-nav > li').click( function()
	{
		if(this.id == 'nav-index')
		{
			return true;
		}
		if(this.id != 'nav-login')
		{
			// Second click follows the link
			if( $("ul", this).css('display') == 'none' )
			{
				// Find active tab
				$("li", this.parentNode).each( function()
				{
					if( $("ul", this).css('display') != 'none' )
					{
						// Remove <strong> tag
						$("strong:first", this).replaceWith( $("strong:first", this).html() );

						// Wipe away sub-menu
						$("ul", this).stop(true, true).hide("slide",{},200);
					}
				});

				// Add <strong> tag
				$("a:first", this).wrap("<strong title=\"Selected\"></strong>");

				// Show this one's sub-menu
				$("ul", this).stop(true, true).show("slide",{direction:"right"},200);

				// Don't follow the link
				return false;
			}
			else
			{
				return true;
			}
		}
	});


	// Login box
	// --------------------------------------------------------------------------------------------

	$('#contact-us a').click(
		// Do not replace with toggle function
		function()
		{
			if(!mlfAnimating)
			{
				if( !$("#enq-form").size() )
				{
					$(this.parentNode).append('<div id="enq-form"><p><strong>CALL 0161 123 4567</strong></p><p>No matter what your online requirements may be, we can offer advise or solutions to suit your needs. Call or email us today.</p><form action="?form_id=Main" id="contact-form" method="post"><p><label for="contact-name">Your Name: </label><input id="contact-name" name="contact-name" value=""/></p><p><label for="contact-email">Email Address: </label><input id="contact-email" name="contact-email" type="text" value=""/></p><p><label for="contact-phone">Phone: </label><input id="contact-phone" name="contact-phone" type="text" value=""/></p><p id="contact-info"><textarea name="contact-info">Online Requirements</textarea></p><p><input type="submit" value="Send Details" class="small-submit"/></p></form><p>Please address mail to:<br/>Simonstone Business Park, Burnley, Lancs, BB12 7TW, United Kingdom</p></div>');
				}
				if( $("#enq-form").css('display') == 'none' )
				{
					mlfAnimating = true;
					$("#mlf-username").focus();
					$("#enq-form").slideDown("slow", function() { mlfAnimating = false; $("#mlf-username").focus(); });
				}
				else
				{
					mlfAnimating = true;
					$("#mlf-username").focus();
					$("#enq-form").slideUp("slow", function() { mlfAnimating = false; });
				}
			}
			return false;
		}
	);
});

function init(){
var inp=document.getElementsByTagName('input');
for(var i=0;i<inp.length;i++){
if(inp[i].type=='text'){
inp[i].setAttribute('rel',inp[i].defaultValue)
inp[i].onfocus=function(){
if(this.value==this.getAttribute('rel')){this.value='';}
else{return false;}}
inp[i].onblur=function(){
if(this.value==''){this.value=this.getAttribute('rel');}
else{return false;}}
inp[i].ondblclick=function(){this.value=this.getAttribute('rel')}
}}}
if(document.childNodes){window.onload=init}
