$( function(){ 
	$('#menu').find( 'li.current' ).removeClass( 'current' ).end().find( 'a.currentpage').parent().addClass( 'current' );
	$('#menu li.activeparent').addClass( 'current' );
	$('#menu ul:first').addClass( 'lavaLampBottomStyle' ).attr( 'id', 'mainNav' );
	$('#header').innerfade({ speed: 'slow', timeout: 8000, type: 'sequence', containerheight: '147px' });
	$("#mainNav").lavaLamp({ fx: "backout", speed: 700 });
	$(".haccordion").haccordion(); 
	/*
	$('#otwayvideo').flash(
		{ src: 'otway.swf',
		  width: 400,
		  height: 224,
		  version: 6 }
	);
	*/
	$( '#otwayvideo' ).css('width','0').innerfade({ speed: 'slow', timeout: 5000, type: 'sequence', containerheight: '244px' });
	$( '#facts ul a' ).prepend( '&raquo; ');
	$( '#facts ul' ).css( 'overflow', 'hidden').addClass( 'leftlist' ).parent().append( '<ul class=rightlist style="overflow:hidden"></ul>' );
	$( '#facts ul li:gt(10)' ).remove().appendTo("#facts ul.rightlist");
	$( '#rot_header' ).innerfade({ speed: 'slow', timeout: 5000, type: 'sequence', containerheight: '174px' });
	$( '#walk_feature ul,#region_feature ul, #edu_feature ul, #head_feature ul' ).each(function(){
        var rightlist = $( this ).css( 'overflow', 'hidden' ).addClass( 'leftlist' ).parent().append( '<ul class=rightlist style="overflow:hidden"></ul>' ).find( 'ul.rightlist' );
        $( 'li:gt(6)', this ).remove().appendTo( rightlist );
        $( 'li a:not(:contains("»"))', $(this).parent() ).prepend( '&raquo; ');
    });
    $( '#content_wrap h2.headline').each( function(){
       var words = $(this).text().split(' ');
       var newString = '';
       $.each( words, function( i, val ){
           i == 0 ? newString += '<span id="firstWord">' + val + '</span>' : newString += ' ' + val;
       });
       $(this).html(newString);
    });
    
    // handle the subscription field
    $("form#frm_subscribe input[type=text]")
    	.focus( function(){ 
    		if ( $(this).val() == 'Your name' || $(this).val() == 'Your email address'  )
    		{
    			$(this).val( '' ); 
    		}
    	})
    	.blur( function() {
    		if ( $(this).val() == '' )
    		{
    			if ( $(this).attr( 'name' ) == 'name' )
    				$(this).val( 'Your name' );
    			if ( $(this).attr( 'name' ) == 'email' )
    				$(this).val( 'Your email address' );
    		}
    	});
	
	$("form#frm_subscribe").submit(function(){
		
		if ( $( 'input[name=name]', this).val() == 'Your name' || $( 'input[name=name]', this).val() == '' )
		{
			alert( 'Please provide your name in the field provided' );
			$( 'input[name=name]', this).focus();
			return false;
		}
		
		if ( $( 'input[name=email]', this).val() == 'Your email address' || $( 'input[name=email]', this).val() == '' || (!is_valid_email( $( 'input[name=email]', this).val() )))
		{
			alert( 'Please provide your email address in the field provided' );
			$( 'input[name=email]', this).focus();
			return false;
		}	

		$( "#frm_subscribe_submit" ).hide( "fast" );
		$( "img.processing", this ).show( "fast" );
		$.post("/xtra/subscribe.php", $("form#frm_subscribe").serialize(), function( html ) {
			$("form#frm_subscribe").html( html );
		});
		return false;
		
	});
	
}); 

function winPop(sLocation,sWidth,sHeight,sScrollbars)
{
	window.open(sLocation, '', 'toolbar=0,resizable=1,scrollbars=' + sScrollbars + ',left=2,top=2,width=' + sWidth + ',height=' + sHeight);
}

function is_valid_email( address )
{
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	if( !emailReg.test( address ) )
		return false;
	else
		return true;
}