jQuery.noConflict();

var id;
var cnt;
var fresh_project;
jQuery.fn.portSlide = function (settings) {
	settings = jQuery.extend({
		easeFunc: "easeInOutExpo",
		easeTime: 1250}, settings);
	return this.each(function() {
		var container = jQuery(this);		
		var pictEls = container.find("img").length;
		var stripViewerWidth = 547*pictEls;
		container.find("ul").css("width" , stripViewerWidth);
		container.css("width" , 547);
		container.css("height" , 296);
		jQuery("#bodytext ul li").hide();
		jQuery("#bodytext ul li:first").show();
		jQuery("#bodytext ul li").find("li").show();
		jQuery("#tabpad").append('<ul class="tabs"></ul>');
		jQuery(".body").find("img").each(function (i) { jQuery("#tabpad ul").append('<li><a href=".tab'+i+'" class=".tab'+i+'" /></a></li>'); });
		jQuery("#tabpad ul li:first").addClass("active");
		cls = jQuery("#bodytext ul li:first").attr('class');
		jQuery("[data-isfresh=1]").each( function() {
			if (jQuery(this).attr('class') == cls) {
				jQuery(".fresh_project").animate({'opacity': 0}, 750).animate({'opacity': 1}, 500, 'linear');
			}
		});
		jQuery("#tabpad").find("a").each(function () {
				jQuery(this).click(function (e) {
					e.preventDefault();
					id = jQuery(this).attr('class');

					pos = jQuery("#body " + id).position();
					cnt = -(pos.left);
					jQuery("#body ul").animate({'left': cnt}, settings.easeTime, settings.easeFunc);
					jQuery("#bodytext ul li").not("#bodytext ul li .features ul li").fadeOut('fast');
					jQuery(".fresh_project").animate({'opacity': 0}, 250, 'linear');
					jQuery("[data-isfresh=1]").each( function() {
						if ("."+jQuery(this).attr('class') == id) {
							jQuery(".fresh_project").animate({'opacity': 0}, 750).animate({'opacity': 1}, 500, 'linear');
						}
					});
					jQuery("#bodytext "+id).fadeIn(1000);
					jQuery(this).parent().addClass("active").parent().find("li.active").not(jQuery(this).parent()).removeClass("active");
					clearInterval(interval);
					interval = setTimeout('nextSlide()', 6000);
				});
		});
		jQuery(".loading").fadeOut(1000).remove();
		jQuery("#slider_wrap").fadeIn(800);
		var interval = setInterval('nextSlide()', 8000);				
	});
};

var currentItem;
var nextItem;
var totalItems;
function nextSlide() {
	totalItems = jQuery('#tabpad ul').children().length - 1;
	jQuery('.tabs').children().each(function (index) { 
		if (jQuery(this).hasClass("active")) { currentItem = index; } 
	});
	if (currentItem == totalItems) { nextItem = 0; } 
	else { nextItem = currentItem + 1; }
	jQuery('#tabpad ul').children().each(function (i) {
		if (i == nextItem) { jQuery(this).find("a").trigger("click"); }
	});
}

jQuery(window).bind('load', function () {
	jQuery("#body").portSlide();
});

jQuery(document).ready(function () {
	jQuery("ul#accordian .parent ul").prev().before("<span class='accordian-top'></span>");
	jQuery("ul#accordian .parent ul").after("<span class='accordian-bot'></span>");
	jQuery('#accordian li ul').css('display', 'none');
	jQuery('#accordian li a').not('#accordian li ul a').click(function() { 
		jQuery('#accordian li ul').not(jQuery(this).next()).slideUp();
		jQuery("#accordian * .active").not(jQuery(this).find("span")).removeClass("active"); 
		jQuery(this).find("span").toggleClass("active"); 
		jQuery(this).next().slideToggle(); 
		return false;
	});
	jQuery('#accordian li:first a').trigger('click');
});
