// setup rel='external' to handle '_blank' style links
function externalLinks() {   
 if (!document.getElementsByTagName) return;   
 var anchors = document.getElementsByTagName("a");   
 for (var i=0; i<anchors.length; i++) {   
   var anchor = anchors[i];   
   if (anchor.getAttribute("href") &&   
	   anchor.getAttribute("rel") == "external")   
	 anchor.target = "_blank";   
 }   
}   
window.onload = externalLinks;	

// function for popup windows
function popUp(pURL,pWidth,pHeight) {
	window.open(pURL,"","width=" + pWidth + ",height=" + pHeight + ",resizable=yes,scrollbars=yes");	
}


$(window).load(function(){
	
	//setup rollovers
	$('.rollover').hover(
		function() { this.src = this.src.replace('-off','-on') },
		function() { this.src = this.src.replace('-on','-off') }
	);
	
	
	function resetMenu() {
		$('#menu ul li a').css('color','white');
		$('#menu ul li').css('background-image','none');
		$('.tab').stop(true,true).fadeOut('fast');
	}

	$('body').bind('click',function(){resetMenu();});
	
	$('#menu .menurollover').not('#btn-home').hover(
		function(){
			resetMenu();
			$(this).css('background-image','url(/images/menu-bg-on.png)');
			$("a",this).css('color','yellow');
		},
		function(){
			resetMenu();
		}
	);
	
	// setup rolling quotes if it is there
	if ($('#quotes').length >0) {
		$('#quotes').cycle({
			speed:1500,
			timeout:10000,
			before: function() { $(this).jTypeWriter(); }				   
		});
	}
	
	// setup form boxes, clear and change colour on focus
	$('.frmtext,.frmtextarea').focus(function(){
		if ($(this).val() == $(this).attr("defaultValue")) {
			$(this).css('color','black');
			$(this).val('');
		}
	});
	$('.frmtext,.frmtextarea').blur(function() {
		if ($(this).val() == '') {
			$(this).css('color','grey');
			$(this).val($(this).attr("defaultValue"));
		}
	});
	
	
	$('#menu-office a').mouseover(function(){
		$('#menu ul li a').css('color','white');
		$('#menu ul li').css('background-image','none');
		$('.tab').not('#tab-officelet').stop(true,true).hide();
		
		$("a",this).css('color','yellow');
		$('#menu-office').css('background-image','url(/images/menu-bg-on.png)');
		var pos = $(this).parent().offset().left;
		$('#tab-officelet').css('left',pos + 'px');
		$('#tab-officelet').slideDown('fast');
	});

	$('#menu-ind a').mouseover(function(){
		$('#menu ul li a').css('color','white');
		$('#menu ul li').css('background-image','none');
		$('.tab').not('#tab-indlet').stop(true,true).hide();

		$("a",this).css('color','yellow');
		$('#menu-ind').css('background-image','url(/images/menu-bg-on.png)');
		var pos = $(this).parent().offset().left;
		$('#tab-indlet').css('left',pos + 'px');
		$('#tab-indlet').slideDown('fast');
	});

	$('#menu-freehold a').mouseover(function() {
		$('#menu ul li a').css('color','white');
		$('#menu ul li').css('background-image','none');
		$('.tab').not('#tab-feehold').stop(true,true).hide();
		
		$('a',this).css('color','yellow');
		$('#menu-freehold').css('background-image','url(/images/menu-bg-on.png)');
		var pos = $(this).parent().offset().left;
		$('#tab-freehold').css('left',pos + 'px');
		$('#tab-freehold').slideDown('fast');
	});

	$('#menu-about a').mouseover(function(){
		$('#menu ul li a').css('color','white');
		$('#menu ul li').css('background-image','none');
		$('.tab').not('#tab-about').stop(true,true).hide();

		$("a",this).css('color','yellow');
		$('#menu-about').css('background-image','url(/images/menu-bg-on.png)');
		var pos = $(this).parent().offset().left + $(this).width() + 14;
		pos = pos - $('#tab-about').width();
		$('#tab-about').css('left',pos + 'px');
		$('#tab-about').slideDown('fast');
	});
	
	
});

