var Portfolio = 
{
	init: function()
	{
		Portfolio.systemurl = $("#system_url").val();

		$(".lightbox").lightbox({
			fitToScreen: true,
			imageClickClose: false,
			fileLoadingImage : Portfolio.systemurl + 'images/public/loading.gif',
			fileBottomNavCloseImage : Portfolio.systemurl+'images/public/closelabel.gif',
			filePrevImage : Portfolio.systemurl+'images/public/prev.png',
			fileNextImage : Portfolio.systemurl+'images/public/next.png',
			filePrevNoImage : Portfolio.systemurl+'images/public/prev-no.png',
			fileNextNoImage : Portfolio.systemurl+'images/public/next-no.png'
		});
	}
}

var Clients = 
{
	init: function()
	{
		$("#clientgrid li img").css('margin-top', function()
		{
			var liheight = $(this).parent("li").height();
			var imgHeight = $(this).height();
			return ((liheight - imgHeight)/2);
		});
	}
}

var Accordion = 
{
	current:Object,
	minwidth:Number,
	
	init:function()
	{
		$("#accordion .accordion").mouseover(Accordion.over);
		$("#accordion .section").hide();
	},
	
	over:function()
	{
		if(Accordion.current != this)
		{
			$(Accordion.current).children(".section").fadeOut(100);
		}
		
		Accordion.minwidth = 0;
		Accordion.current = this;
		$("#accordion .accordion").each(function() 
		{
			if(this == Accordion.current)
			{
				//alert("current");
			}
			else
			{
				Accordion.minwidth += $(this).children("a").children("img").width();
				$(this).stop().animate({width:$(this).children("a").children("img").width()},700);//,"easeOutCubic"
			}
		});
		$(Accordion.current).stop().animate({width:960-Accordion.minwidth}, 700, Accordion.showSection);//, "easeOutCubic"
	},
	
	showSection:function()
	{
		$(Accordion.current).children(".section").fadeIn(200);
	}
}

var Feature =
{
	current:Object,
	currentID:String,
	indicatorY:Number,
	index:Number,
	
	init:function()
	{
		$(".overlay").css({opacity:0.6});
		
		Feature.current = $("#features li:first");
		Feature.changefeature(Feature.current);
		
		$("#feature").children(".featureBox").not(":first").hide();
		$("#features li").click(Feature.tabclick);
	},
	
	tabclick:function()
	{
		Feature.changefeature(this);
	},
	
	changefeature:function(object)
	{
		Feature.current = object;
		
		$("#features li").each(function()
		{
			currentID = $(this).attr("id");

			if(currentID == $(Feature.current).attr("id"))
			{
				index = $(this).attr("index");	
				indicatorY = 70 * index + 17;
				$("#indicator").stop().animate({top:indicatorY},700,"easeOutCubic");
										
				$(this).addClass('selected');
				$("#"+currentID+"-image").fadeIn(200);
				$("#"+currentID+"-info").fadeIn(200);
			}
			else
			{
				$(this).removeClass('selected');
				$("#"+currentID+"-image").fadeOut(200);
				$("#"+currentID+"-info").fadeOut(200);
			}
		});
	}
}

var Scroller =
{
	totalWidth:Number,
	leftMost:Number,
	itemWidth:Number,
	currentPosition:Number,
	leftPos:Number,
	
	init:function()
	{
		Scroller.itemWidth = 100;
		Scroller.leftMost = 0;
		Scroller.totalWidth = $("#scrollContent").children("li").size() * Scroller.itemWidth;
		$("#scrollContent").width(Scroller.totalWidth);
		//alert(Scroller.totalWidth);
		// Vertically center the images
		$("#scrollContent li img").css('margin-top', function()
		{
			var liheight = $("#scrollFrame").height();
			var imgHeight = $(this).height();
			return ((liheight - imgHeight)/2);
		});
		
		Scroller.leftPos = -(Scroller.leftMost*Scroller.itemWidth);
		$("#scrollContent").css("left",Scroller.leftPos);
		
		// Add Events
		$("#leftArrow").click(Scroller.leftClick);
		$("#rightArrow").click(Scroller.rightClick);
	},
	
	rightClick:function()
	{
		if(Scroller.leftMost < $("#scrollContent").children("li").size()-2)
		{
			Scroller.leftMost++;
			//alert(Scroller.leftMost);
			Scroller.leftPos = -(Scroller.leftMost*Scroller.itemWidth);

			$("#scrollContent").stop(true).animate({ 
				  left:Scroller.leftPos
				}, 400, "easeOutCubic" );
		}
	},
	
	leftClick:function()
	{
		if(Scroller.leftMost > 0)
		{
			Scroller.leftMost--;
			
			Scroller.leftPos = -(Scroller.leftMost*Scroller.itemWidth);
			
			$("#scrollContent").stop(true).animate({ 
				  left:Scroller.leftPos
				}, 400, "easeOutCubic" );
		}
	}
}

var SubNav =
{
	init: function()
	{
		$("#subNav li:first-child a").addClass("subNavTop");
		$("#subNav li:last-child a").addClass("subNavBottom");
		$("#subNav li:only-child a").removeClass();
	}
}
