// JavaScript Document

$(document).ready(function(){
	
	///////// Navigation IE Fix  /////////////////
	 $("ul.dropdown li").hover(function(){
	   $(this).addClass("hover");
	   $('> .dir',this).addClass("open");
	   $('ul:first',this).css('visibility', 'visible');
	 },function(){
	   $(this).removeClass("hover");
	   $('.open',this).removeClass("open");
	   $('ul:first',this).css('visibility', 'hidden');
	 });
	 
	 
	 ///////// Button Style /////////////////
	 $(".fg-button:not(.ui-state-disabled)")
		.hover(
			function(){ 
				$(this).addClass("ui-state-hover"); 
			},
			function(){ 
				$(this).removeClass("ui-state-hover"); 
			}
		)
		.mousedown(function(){
				$(this).parents('.fg-buttonset-single:first').find(".fg-button.ui-state-active").removeClass("ui-state-active");
				if( $(this).is('.ui-state-active.fg-button-toggleable, .fg-buttonset-multi .ui-state-active') ){ $(this).removeClass("ui-state-active"); }
				else { $(this).addClass("ui-state-active"); }	
				
				
				
				
				// CODE FOR UPDATING RADIO BUTTONS
				var value = $(this).attr('name');
				
				var thingToUpdate = value+"CheckBox";
				//console.log(thingToUpdate);
				
				if ( $("#"+thingToUpdate).attr('checked') == true ) {
					//console.log('checked true');
					$('#'+thingToUpdate).attr("checked", false);
        		} else if ( $("#"+thingToUpdate).attr('checked') == false ) {
					//console.log('checked false');
					$('#'+thingToUpdate).attr("checked", true);
        		} else {
					//console.log('checked true');
					$('#'+thingToUpdate).attr("checked", false);
        		};
				// CODE FOR UPDATING RADIO BUTTONS END
				
				
				
		})
		.mouseup(function(){
			if(! $(this).is('.fg-button-toggleable, .fg-buttonset-single .fg-button,  .fg-buttonset-multi .fg-button') ){
				$(this).removeClass("ui-state-active");
			}
		});
		
		
		///////// Form Style /////////////////
		$('.FormStyle').find('input[type="text"]').addClass("idleField");
	
		$('.FormStyle').find('input[type="text"]').focus(function() {
			$(this).removeClass("idleField").addClass("focusField");
			if (this.value == this.defaultValue){ 
				this.value = '';
			}
			if(this.value != this.defaultValue){
				this.select();
			}
		});
		$('.FormStyle').find('input[type="text"]').blur(function() {
			$(this).removeClass("focusField").addClass("idleField");
			if ($.trim(this.value) == ''){
				this.value = (this.defaultValue ? this.defaultValue : '');
			}
		});

});
