$(document).ready(function() {
	$('#orderHistoryTable').tablesorter({ 
		headers: {
			5: { sorter: false }
		},
	    widgets: ['zebra'] 
	});
	$('#my_proposals').tablesorter({ 
	    widgets: ['zebra'] 
	});
	$('table.table-sorter').tablesorter({ 
	    widgets: ['zebra'] 
	});
	$('table.table-stripe').tablesorter({ 
	    widgets: ['zebra'] 
	});
//_________ end tablesorter _________\\
	$('div.resource-header-trigger').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});
//_________ end resource header hover _________\\
	$('#header_nav a.login-trigger').click(function(){
		var $loginBox = $('#login_box');
		var $loginPosition = $loginBox.position();
		if($loginPosition.left == 368){
			$('#remember_me').fadeOut(100);
			$loginBox.animate({
			      "right": "-185", "opacity": 0
			    }, 500, function(){
			});
		}
		else{
			$loginBox.animate({
			      "right": "215", "opacity": 1
			    }, 500, function(){
				$('#remember_me').fadeIn(500);
			}).addClass('open');
		}
		return false;
	});
//________ end login slider _________\\
	$('#desc_bg').css('opacity',0.6);
	if(jQuery().cycle) {
		$('#home_portfolio').cycle({
			fx:     'fade',
			speed: 2000,
			slideExpr: 'div.portfolio',
			timeout: 10000,
			next:   '#next', 
		 	prev:   '#prev',
			//pager:   '#pager',
			//pagerAnchorBuilder: pagerFactory,
			manualTrump:     false,
			before:  onBefore,
			after: onAfter
		});
	}
//________ end home cycle _________\\
	$('a.media').media({
		width:     300, 
		height:    225, 
		autoplay:  false, 
		flashvars: { width: 300, height: 225, bufferlength: 5}
	});
//_________ end media _________\\
//$('div.add-container').css({top:'50%',left:'50%',margin:'-'+($('div.add-container').height() / 2)+'px 0 0 -'+($('div.add-container').width() / 2)+'px'});

// $('div.add-container').center();
// $(window).bind('resize', function() {
//     $('div.add-container').center({transition:300});
// });
});
//_________ end doc ready _________\\
function pagerFactory(idx, slide) {
    var s = idx > 20 ? ' style="display:none"' : '';
    return '<li'+s+'><a href="#"><span>'+(idx+1)+'</span></a></li>';
};
var first = true;
function onBefore() {
	if (first) { // ignores the onBefore function the first time
		var title = $(this).find('span.portfolio-name').text();
		var caption = $(this).find('span.portfolio-blirb').text();
		$('#portfolio_name').html('<h2>'+title+'</h2>');
		$('#portfolio_blirb').html(caption);
		first = false; 
        return true; 
    }
	var title = $(this).find('span.portfolio-name').text();
	var caption = $(this).find('span.portfolio-blirb').text();
	$('#portfolio_name').fadeOut(1500, function(){
		$(this).html('<h2>'+title+'</h2>').delay(400).fadeIn(1000);
	});
	$('#portfolio_blirb').fadeOut(2000,function(){ $(this).find('span.portfolio-blirb').text(''); });
}
function onAfter() {
	$('#portfolio_blirb').text($(this).find('span.portfolio-blirb').text()).fadeIn(600);
}
$.fn.delay = function(time, callback){
    // Empty function:
    jQuery.fx.step.delay = function(){};
    // Return meaningless animation, (will be added to queue)
    return this.animate({delay:1}, time, callback);
}
