jQuery.fn.clearDefault = function(options) {       
    
    settings = jQuery.extend({
        highlightClass: "highlight"
    }, options);
    
    return this.each(function() {
        jQuery(this).focus(function() {
            if( this.value == this.defaultValue )
                jQuery(this).attr("value", "").addClass(settings['highlightClass']);
        }).blur(function() {
            if( !this.value.length )
                jQuery(this).attr("value", this.defaultValue).removeClass(settings['highlightClass']);
        });        
    });
};
 

$(function() {
	$('.eventcal-link').remove();
	$('.loggedin .logout,.section-nav a,.more,button[type="submit"],button[type="reset"],.subnav a,.sitemap > li > a,.submenu a,.site-nav a').wrapInner('<span></span>').append('&nbsp;&raquo;').addClass('raquo');
	$('.nav > li > a').append('<span>&nbsp;+</span>');
    $('.recent .pagination ul a:first').css('border-left','none');
	$(".search input.searchInput, .login input.userInput, .login input.passInput, .newsletters input.email").clearDefault();
	$('.featured-story').append('<div class="pager" rel="generated"></div>');
	if( $.browser.safari ){ $('.search input.submitBtn').css({'width':'37px', 'height':'21px'}); }
 	$('.footer').append('<a class="toggle" rel="generated" href="#">View&nbsp;Sitemap&nbsp;<span>+</span></a>');
	$('.footer ul').hide();
	$('.footer .toggle').click(function(event){
		event.preventDefault();
		$('.footer ul').toggle('fast',function(){
			if( $('.footer ul').css('display') == 'none' ){
				$('.toggle span').html('+');
			}else{
				$('.toggle span').html('-');
			}
		});
	});
	$('.partners ul').cycle({
		fx:'fade'
		
	});
	
	

	$('.subnav li:last').css('border-bottom','none');
	
	$('.cal').eventCalendar('/events.json',{
		daysShort: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']
	}).before('<h2 class="eventcalendar-head">Events Calendar</h2>');

	$('.eventcalendar-cal a.close').live('click', function(event){
		event.preventDefault();
		$(this).closest('.eventcalendar-popup').css('display','none').removeClass('popup-visible');
	});
	$('.eventcalendar-cal span > a').live('click', function(event){
		event.preventDefault();
		if( $.browser.msie && $.browser.version < 7 ){
			$('.eventcalendar-ie6popup').remove();
			$('.eventcalendar').after( '<div class="eventcalendar-ie6popup">' + $(this).siblings('.eventcalendar-popup').html() + '</div>' );
		}else{
			if( $(this).siblings('.popup-visible').length == 0 && $(this).closest('td').attr('class') == 'eventcalendar-hasevent' ){
				$('.popup-visible').css('display','none').removeClass('popup-visible');
				$(this).siblings('.eventcalendar-popup').append('<div class="eventcalendar-caret"></div>').css({
					'top': (-($(this).siblings('.eventcalendar-popup').height()+22))+"px",
					'left': '-200px',
					'display': 'block'
				}).addClass('popup-visible');
			}else{
				$('.eventcalendar-popup').css('display','none').removeClass('popup-visible');
			}	
		}
	});
	
});