// default

//
var tempHeight = 0;

//
$.postJSON = function (url, data, callback) {
	$.post(url, data, callback, 'json');
};

//
$(function(){

	// css navigation dropdown/flyout replacement for ie 6
	if($.browser.msie && $.browser.version < 7){
		$('#nav ul>li').hover(/*over*/function(){ $(this).children('ul:first').css({display:'block'})},/*out*/function(){ $(this).children('ul:first').css({display:'none'})});
		$('li>a').hover(/*over*/function(){$(this).parent('li').addClass('hover')},/*out*/function(){$(this).parent('li').removeClass('hover')});
	}
	
	// event tracker for outgoing links/file downloads
	$('a').each(function(){
		var path;
		
		if(path = $(this).attr('href')){
			var outgoing 	= /^(http|https)/i;
			var ext 		= /[^/].(?:doc|eps|jpg|jpeg|png|svg|xls|ppt|pdf|xls|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3|mp4)/i;
			
			if (path.match(outgoing) && !path.match(document.domain) ) {
				$(this).click(function(){
					// old ga code
					//pageTracker._trackEvent('Link', 'Outgoing', $(this).attr('href'));
					
					// new ga code
					_gaq.push(['_trackEvent', 'Link', 'Outgoing', $(this).attr('href')]);
				});
			} else if(path.match(ext)){
				$(this).click(function(){
					// old ga code
					//pageTracker._trackEvent('File', 'Download', $(this).attr('href'));
					
					// new ga code
					_gaq.push(['_trackEvent', 'File', 'Download', $(this).attr('href')]);
				});	
			}
		}
	});
	
	//
	$('#frame').cycle({ 
		fx:    'fade', 
		speed:	1000,
		timeout: 5000,
		pause:	1,
		pauseOnPagerHover: 1,
		pager: '#area-buttons',
		pagerAnchorBuilder: function(idx, slide) { 
                return '<li><a href="#">' + slide.title +'</a></li>';
        },
		updateActivePagerLink: function(container, slide) {
			$(container+'>li').removeClass('current');
			$(container+'>li:eq('+slide+')').addClass('current');	
		}
	});
	
	$('#q').focus(function(){
		if($(this).val() == 'search our site'){ $(this).val(''); }
	}).blur(function(){
		if($(this).val() == ''){ $(this).val('search our site'); }
	});
	
	$('#form').ajaxForm({
        beforeSubmit:  	function(formData, form, options){
							$('input.warning,textarea.warning,checkbox.warning,select.warning').removeClass('warning');
							$('.validate').slideUp();
							return true;
						}, 
        success:       	function(data, status, xhr, form){
							if(data.success == true){
								$('.validate>p').html(data.thank_you);
								$('.validate').slideDown();
								$('html, body').animate({ scrollTop: 100 }, 1000);
								form.slideUp();
							} else {
								$('.validate>p').html('');
								
								for (var i in data.error){
									$('.validate>p').append(data.error[i] + '<br />');
								}
								
								for (var i in data.error){
									$('[name=' + data.name[i] + ']').addClass('warning');
								}
								
								$('html, body').animate({ scrollTop: 100 }, 1000, function(){$('.validate').slideDown();});
							}
						},
		type:			'post',
		dataType:		'json'
	});
	
	$('#survey').ajaxForm({
        beforeSubmit:  	function(formData, form, options){
							$('input.warning,textarea.warning,checkbox.warning,select.warning').removeClass('warning');
							$('.validate').slideUp();
							return true;
						}, 
        success:       	function(data, status, xhr, form){
							if(data.success == true){
								$('#validate>p').html(data.thank_you);
								var form_offset = $('#validate').offset();
								$('html, body').animate({ scrollTop: form_offset.top}, 1000, function(){$('#validate').slideDown();});
								form.slideUp();
							} else {
								$('#validate>p').html('');
								for (var i in data.error){
									$('#validate>p').append(data.error[i] + '<br />');
									$('[name=' + data.name[i] + ']').addClass('warning');
								}
								var form_offset = $('#validate').offset();
								$('html, body').animate({ scrollTop: form_offset.top}, 1000, function(){$('#validate').slideDown();});
								
							}
						},
		type:			'get',
		dataType:		'jsonp'
	});
	
	$('#employment').tablesorter({  
        sortList: [[0,0]], 
		widgets: ['zebra']
    });
	
	$('.moreLink,.moreBtn').click(function(){
		$(this).siblings('.moreTxt').show('slow', function(){ $(this).css({'display':'inline'})});
		$(this).siblings('.moreBtn').hide();
	});
	
	//
	$('.newsbox').each(function(){
		if($(this).height() > tempHeight ){ tempHeight = $(this).height(); }
	});
	
	$('.newsbox').height(tempHeight);
	
	//
	$('.panorama').panorama({tone: 16});
	
	//windowshade
	$('.windowshade').each(function(){
		$(this).find('.string').bind('click', function(){
			$(this).parent('p').siblings('.shade').slideToggle();
			return false;
		});
	});
	
	//
	$('.hide').hide();
	
});

function slideBio(id){
	$(id).slideToggle();
	$('.slide:not('+id+')').slideUp();
}
