$(document).ready(function(){
	$('.expand').tipsy({gravity: 's'});  //z
	$('.download').tipsy({gravity: 's'});  //x
      
      
      /*
      
    /** AREAMAP Custom  **/
    $('.download').click(function(e){        
        window.open(this.href);
        e.preventDefault();
    })
    
	$('#flashmap').flash({    
        swf: '/swfs/plants-projects/midrex_pp.swf', 
		height: 900,
		width: 960,
        wmode: 'transparent',   
        flashvars: {   name1: 'jQuery'   }
    })
	
	$('#flashcontent').flash({    
        swf: '/swfs/timeline4.swf', 
		height: 400,
		width: 600,
        wmode: 'transparent',   
        flashvars: {   name1: 'jQuery'   }
    })
	
	$('.expand').click(function (e) {
		$('#basic-modal-content').modal({
			containerCss:{
				height:650,
				width:850
			}
		});		
		e.preventDefault();
	});
	
	listingTable.init();
	//listingTable.sort();
	fieldToggle.init();	
	tabBoxes.init();
	
	$('.confirm').click(function(){
		return confirm('Are you sure you wish to delete this item?');
	})

	$('.reset').click(function(){
		resetForm($('.container form'));
		return false;
	});
	
	$('#inst_type select').change(function(){
		//alert($(this).val());
		if($(this).val() == 'Member Institute Samples'){
			$('#inst_sample').removeClass('hidden');
		}else{
			$('#inst_sample').addClass('hidden');
		}
	})	
});

var listingTable = {};
var fieldToggle = {};
var tabBoxes = {};

listingTable.init= function(){
	$('.listing').attr('cellspacing','0');
	$('.listing tbody').each(function(){
		$('tr:odd',this).addClass('alt');
	});	
	
	$('.listing tbody').each(function(){
		$('tr',this).hover(
			function(){$(this).addClass('hover')},
			function(){$(this).removeClass('hover')}
		);
	});	
	
}
/*
listingTable.sort = function(){
	$(".listing.sortable").tablesorter({widgets:['clearLastColumn']}); 
	$(".listing.sortable").bind("sortEnd",function() {
		$('.listing.sortable tbody').each(function(){
			$('tr',this).removeClass('alt');
			$('tr:odd',this).addClass('alt');
		});	
	});	
}
*/
function resetForm(el){
	$(':input',el).not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');
	$('select').each(function(){
		$('option:first',this).attr('selected','selected');
	});
}

fieldToggle.init = function(){
	$('#fieldToggle input[type=radio]').click(function(){
		var div = '#'+$(this).attr('id')+'_fields';
		if($(this).attr('checked')){
			$('#document_fields').hide();
			$('#url_fields').hide();
			$('#detail_fields').hide();	
			$(div).slideDown('normal',function(){$(div).effect("highlight", {}, 1000);});
		}else{
			$(div).slideUp();
		}
	});
}



tabBoxes.init = function(){
	$('.tabs a').click(function(){
		var tab = '.tab_' + $(this).attr('id');
		$('.tabs a').removeClass('selected');
		$(this).addClass('selected');
		
		$('.tab_container div').hide();
		$(tab).show();
		return false;		
	});
}
