$(document).ready(function() {
	// hide URL bar on mobile, note: only works on 'Go' not on refresh
	window.scrollTo(0,1);
	
	// TOP NAV ANIMATIONS
	$('#nav-main ul li')
		.mouseover(function(){
			$(this).stop().animate({
				backgroundPosition: '50% -50px'
				}, 500, "easeOutCubic");
			$(this).find('a').stop().animate({
				color: "#002e51"
				});
		})
	$('#nav-main ul li')
		.mouseout(function(){
			$(this).stop().animate({
				backgroundPosition: '50% 0px'
				}, 500, "easeOutCubic");
			$(this).find('a').stop().animate({
				color: "#ffffff"
				});
		})
	
	
	// SEARCH FIELD
	var el = $('input[type=text], textarea');
    el.focus(function(e) {
        if (e.target.value == e.target.defaultValue)
            e.target.value = '';
    });
    el.blur(function(e) {
        if (e.target.value == '')
            e.target.value = e.target.defaultValue;
    });
	
});


(function($){
 $.fn.extend({
 
 	customStyle : function(options) {
	  if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
	  return this.each(function() {
	  
			var currentSelected = $(this).find(':selected');
			$(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">'+currentSelected.text()+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
			var selectBoxSpan = $(this).next();
			var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));			
			var selectBoxSpanInner = selectBoxSpan.find(':first-child');
			selectBoxSpan.css({display:'inline-block'});
			selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
			var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
			$(this).height(selectBoxHeight).change(function(){
				// selectBoxSpanInner.text($(this).val()).parent().addClass('changed');   This was not ideal
			selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('changed');
				// Thanks to Juarez Filho & PaddyMurphy
			});
			
	  });
	  }
	}
 });
})(jQuery);


$(function(){
	$('select.styled').customStyle();
});
