// yFactorial JS

$(document).ready(function(){
	
	if ($(".projectDetail")) {		
		
		var features = $(".projectDetail");
		
		for ( j=0; j<features.length; j++) {
			
			var id = parseInt(features.get(j).id);
			
			var len = $("#" + id + "feature div").length;
			
			for (i=1; i<=len; i++) {
				
				if (i!=1) { 
					var feat = "#" + id + "feat"+i;
					if($(feat).get(0)) $(feat).get(0).style.marginLeft = '-300px';
					if($(feat)) $(feat).hide();
					if ($(feat).get(0)) $(feat).get(0).style.display = 'none';
				}
				
				if(i==len) document.getElementById(id + "feature").style.visibility = "visible";
				
			}
			
			var port = "#" + id + "port";
			
			if ($(port+"1").get(0)) $(port+"1").get(0).href= "javascript:slider('1', '" + id + "');";
			if ($(port+"2").get(0)) $(port+"2").get(0).href= "javascript:slider('2', '" + id + "');";
			if ($(port+"3").get(0)) $(port+"3").get(0).href= "javascript:slider('3', '" + id + "');";
			if ($(port+"4").get(0)) $(port+"4").get(0).href= "javascript:slider('4', '" + id + "');";
			
			slider = function(num, id){
					
					if($("#" + id + "feat"+num).get(0).style.marginLeft) {
						
						$("#" + id + "feature div.portFeat").animate({ 
							marginLeft: "-300px",
							opacity: 0.0
						}, 300, function() {
							$("#" + id + "feature div.portFeat").hide();
							$("#" + id + "feat" + num).show();
							$("#" + id + "feat"+num).get(0).style.display = 'block';
						});
						
						$("#" + id + "feat" + num).animate({ 
							marginLeft: "0",
							opacity: 1.0
						}, 500 );
						
						$("#" + id + "feature div.thumbs a").removeClass("on");
						$("#" + id + "port" + num).addClass("on");
					}
			};
			
			$("#" + id + "feature").get(0).style.height = $("#" + id + "feature").get(0).offsetHeight + "px";
		}
	}
	
	 if ($("#feature").get(0)) {
		
		var len = $("#feature div").length;
		
		for (i=1; i<=len; i++) {
			
			if (i!=1) { 
				var feat = "#feat"+i;
				if($(feat).get(0)) $(feat).get(0).style.marginLeft = '-300px';
				if($(feat)) $(feat).hide();
				if ($(feat).get(0)) $(feat).get(0).style.display = 'none';
			}
			
			if(i==len) document.getElementById("feature").style.visibility = "visible";
			
		}
		
		var port = "#port";
		
		if ($(port+"1").get(0)) $(port+"1").get(0).href= "javascript:sliderHome('1');";
		if ($(port+"2").get(0)) $(port+"2").get(0).href= "javascript:sliderHome('2');";
		if ($(port+"3").get(0)) $(port+"3").get(0).href= "javascript:sliderHome('3');";
		if ($(port+"4").get(0)) $(port+"4").get(0).href= "javascript:sliderHome('4');";
		
		sliderHome = function(num){
				
				if($("#feat"+num).get(0).style.marginLeft) {
					
					$("#feature div.portFeat").animate({ 
						marginLeft: "-300px",
						opacity: 0.0
					}, 300, function() {
						$("#feature div.portFeat").hide();
						$("#feat" + num).show();
						$("#feat"+num).get(0).style.display = 'block';
					});
					
					$("#feat" + num).animate({ 
						marginLeft: "0",
						opacity: 1.0
					}, 500 );
					
					$(".mainIntro li a").removeClass("on");
					$("#port" + num).addClass("on");
				}
		};
	}
});