// JavaScript Document
// Shwizzle.com: article switcher

var globalPosX = 'null';
var globalPosY = 'null';

var changePortfolioArticle = function(articleName){
	var nextArticleID = (articleName+'_content');
	var currentArticleID = $('.active_article').attr('id');

	var panelName = window.location.hash.replace('#', '');
	if (panelName.length == 0){
		panelName = articleName;
	}
	//alert('current article is:'+currentArticleID);
	//alert(articleName)
	var currentPanel = 'panelContainer_'+articleName;
	if ($('#'+currentPanel).children().hasClass('panel')){
		var current = $('.currentPanel');
		(current).removeClass('currentPanel');
		$('#'+currentPanel+' div:first').addClass('currentPanel');
		var current = $('.currentPanel');
		var v = current.index();
		var setUpPanel = slidePanelsToV(v, articleName, 0);
	}
	
	if (nextArticleID != currentArticleID){
		var nextArticleHeight = ($('#'+nextArticleID).height());
		var currentArticleHeight = $('.active_article').outerHeight(true);
		var nextTabHeight = ($('#'+nextArticleID).height()+$('#portfolio_nav').outerHeight(true));
		var currentTabHeight = $('.active_tab').outerHeight(true);

		$('.active_article').animate({'opacity': 0},'fast', 'swing', function(){
			$('.active_article').removeClass('active_article');
			$('#'+nextArticleID).css('height',currentArticleHeight+'px');
			//$('.active_article').animate({height: nextArticleHeight+'px'}, 500, 'swing');
			$('.active_tab').animate({height: nextTabHeight+'px'}, 'fast', 'swing');
			$('#'+nextArticleID).addClass('active_article');
			$('#'+nextArticleID).addClass('active_article');
			$('.active_article').animate({'opacity': 1, 'height':nextArticleHeight},'fast', 'swing');
		});
	};
}
var animatePortfolioNavOver = function(menuItem, newPosX, newPosY){
	var menuItemID = ('#'+menuItem);
	globalPosX = $(menuItemID).css('background-position-x');
	globalPosY = $(menuItemID).css('background-position-y');
	//$(menuItemID).css( 'background-position-x', globalPosX );
	//$(menuItemID).css( 'background-position-y', globalPosY );
	$(menuItemID).css('border', '1px solid #ff6c00');
	$(menuItemID).animate({
		'background-position-x': newPosX,
		'background-position-y': newPosY
	}, 6000);
}

var animatePortfolioNavOut = function(menuItem){
	var menuItemID = ('#'+menuItem);
	//$(menuItemID).stop();
	$(menuItemID).css('border', '1px solid #000');
	$(menuItemID).animate({
		'background-position-x': globalPosX,
		'background-position-y': globalPosY
	}, 500, 'swing');
}
