//var $ = jQuery.noConflict();
 
$(document).ready(function(){   

    // Get browser  
    $.each($.browser, function(i) {
        $('body').addClass(i);
        return false;  
    });
    
    // Get OS
    var match = navigator.userAgent.toLowerCase().match(/(win|mac|linux)/);
    if (match) {
        $('body').addClass(match[0]);
    }


	//home page : news / events feed
	$("#news-events-title h2 a").click ( function(){
		$("#news-events-title h2 a").removeClass().addClass("inactive");
		$(this).removeClass().addClass("active");
		var feed = "#" + $(this).attr('id') + "-feed";
		$("#news-feed, #events-feed").css({'display': 'none'});
		$(feed).css({'display': 'block'});
	});
	
    $("#news-events #title a").click ( function() {
		$("#news-events #title a").removeClass();
		$(this).addClass("active").show();
		var posts = "#" + $(this).attr('id') + "-posts";
		$("#news-posts, #events-posts").css({'display': 'none'});
		$(posts).css({'display': 'block'});
		
		//delete this
		$("#news-event-post").hide();
	});
    
	$('#search-bar input').focus(function(){
        $(this).data('field_value', $(this).val());
        $(this).val('');
    }).blur(function(){
        if($(this).val() == ''){
            $(this).val($(this).data('field_value'));
        }
    });

    // Check the URL to see if we should open the Events section of News & Events
    var urllocation = window.location.href;
    if (urllocation.indexOf('#') > -1) {
      var urlComps = urllocation.split('#');
      if (urlComps[1] !== undefined && urlComps[1] != '') {
        $("#" + urlComps[1]).trigger("click");
      }	
    }
    
    $('#contact label').perfectForm();
});

jQuery.fn.perfectForm = function(options)
{
    var settings = {
        overlap: true,
        ignore: ''             
    }

    if(options) {
        jQuery.extend(settings, options);
    };

    this.not(settings.ignore).each(function(){
        var input = $(this).next('input, textarea');
        var label = $(this);
        
        // first check all inputs for values, then hide it's label if it has a value
        if( settings.overlap ) {
            label.addClass('overlap');
        }
        
        if( settings.overlap && input.val() != '' ) {
            label.hide();
        }
        
        label.click(function(){
            label.hide();
            input.focus();
        }, function(){
            if( input.val() == '' ) {
                label.show();
            }
        });
        
        // then add a focus event to all inputs to hide their labels when focused on, 
        // and remain hidden on blur if a value is entered
        input.focus(function(){
            label.hide();
        }).blur(function(){
            if( $(this).val() == '' ) {
                label.show();
            }
        });
    });
}

