OH_portfolio = {
	
	TagToName : new Array(),
	Features : new Array(),
	pageWidth : 768,
	numPages : 2,
	numPerPage : 8,
	
	load : function(id) {
	
	if(this.Current == id)
		return false;
		
	if(this.Current != undefined)
		$(".portfolioitem").animate({"opacity":"0.65"},250);
			
		//Set Page
		this.CurrentPage = $("#folio"+id).attr("page");
		OH_hash.set("Page", this.CurrentPage);
		
		//Set Project Id
		OH_hash.set("Project", id);
		this.Previous = this.Current;
		this.Current = id;
			
		//If we aren't on the same portfolio item
		if(this.Previous != this.Current) {
			$("#folio"+this.Current+" .portfolioitem").animate({"opacity":"1"},250);
			$("#portfoliostage .content").animate({
				opacity : 0
			}, 250, function(){
				OH_hash.read();
				OH_portfolio.goToPg(OH_hash.hash.Page)
				OH_portfolio.select();
				//Load the content for this item
				Obj = {Method: "GetOne", Class : "Object", Query : {Id : id}};
				Obj.Query = $.toJSON(Obj.Query);
				
				$.post(OH_config.jsonPath, Obj, function(json) {
					OH_portfolio.create(json);
				}, "json");
			});
		}
		
	},
	
	create : function(json) {
		//Set height of div for animation
		OH_object.GetTypeByTag(json.Results.Type, OH_portfolio.getTagName);
		//Features
		OH_portfolio.Features = new Array();
		OH_portfolio.Features = json.Results.Properties.features.split(",");
		txt = "<div class=\"browser\" style=\"background: transparent url('"+json.Results.Properties.image+"') no-repeat;\"></div>";
		txt += "<div class=\"rightcol\">";
		txt += "<h2 class=\"cufon din\">"+json.Results.Properties.name+"</h2>";
		//txt += "<p>Category: "+json.Results.Properties.Category+"</p>";
		txt += "<a href=\""+json.Results.Properties.url+"\" target=\"_blank\" id=\"launchsite\"></a>";
		txt += json.Results.Properties.description;
		txt += "<h2 class=\"cufon din\">Features</h2>";
		txt += "<ul id=\"siteFeatures\"></ul>";
		txt += "</div>";
		txt += "<div class=\"clear\"></div>";
		$("#portfoliostage .content").html(txt);
		Cufon.refresh();
		setTimeout("OH_portfolio.changeHeight($(\"#portfoliostage\").height());",350);
		
	},
	
	changeHeight : function(h){
		r = h%4;
		while(r!=0) {
			h++;
			r = (h%4);
		}
		
		$("#portfoliostage .content").animate({opacity : 1},250);
		$("#portfolio_wrap").animate({height: h}, 100);
	},
	
	getTagName : function(json) {
		OH_portfolio.TagToName = new Array();
		for(i=0;i<json.Results[0].Properties.features.Enums.length;i++) {
			OH_portfolio.TagToName[json.Results[0].Properties.features.Enums[i].Tag] = json.Results[0].Properties.features.Enums[i].Name
		}
		
		txt = "";
		for(i=0;i<OH_portfolio.Features.length;i++) {
			txt += "<li>"+OH_portfolio.Features[i]+"</li>";
		}
			
			
		$("#siteFeatures").html(txt);
		
	},
	
	select : function() {
		pos = $("#folio"+this.Current).position();
		pos.left = pos.left - ((OH_hash.hash.Page - 1) * OH_portfolio.pageWidth);
		$("#portfolio_hover2").animate({"marginLeft": pos.left+"px"});
		$("#portfolio_hover2").fadeTo(100, 1);
	},
	
	nextPg : function(){
		OH_hash.read();
		pg = ++OH_hash.hash.Page;
		if(pg <= OH_portfolio.numPages)
			OH_portfolio.goToPg(pg);
			
		//Select first item on next pg
		$("#inner li[page="+pg+"]:first").each(function(){
			id = $(this).attr("id").substr(5);
			OH_portfolio.load(id);
		});
	},
	
	prevPg : function(){
		OH_hash.read();
		pg = --OH_hash.hash.Page;
		
		if(pg > 0)
			OH_portfolio.goToPg(pg);

		//select last item on pg
		$("#inner li[page="+pg+"]:last").each(function(){
			id = $(this).attr("id").substr(5);
			OH_portfolio.load(id);
		});
	},
	
	goToPg : function(pg){
		$("#portfolio_hover2").fadeTo(0, 0.6);
		pos = (pg-1) * parseInt(OH_portfolio.pageWidth);
		$('#carousel #inner').animate({marginLeft: -pos}, "slow");
	}

}