/*/ Copyright (c) 2008 David Cramer http://www.homegel.co.za
/* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
/* SegmentSlider for Dais
/* Version: 0.1 (20 May, 2008)
/* Requires: jQuery 1.2+
/*/
 
(function($) {

	$.fn.segmentSlider = function(options) {
	$.fn.segmentSlider.defaults = {
		motion: 'easeInOutSine',
		duration: 800
	};

		var arg = $.extend({}, $.fn.segmentSlider.defaults, options);
		var sliderWidth = 0;
		var sliderHeight = 0;
		var multiplier = 1;
		$(this).find(".slideControl").each(function(i){
			//alert($('.'+$(this).attr('title')).html());
			$('.'+$(this).attr('title')).appendTo(arg.slider);
			$('.'+$(this).attr('title')).addClass("sliderItem");
			sliderWidth = sliderWidth+$('.'+$(this).attr('title')).width();
			//if($('.'+$(this).attr('title')).height() > sliderHeight){
			//	sliderHeight = $('.'+$(this).attr('title')).height();
			//}
			multiplier++;
			//$('.'+$(this).attr('title')).remove();
			$(this).click(function(){
				//Tabs select
				$(".slideControl").removeClass("active_tablink");
				$(".slideControl").removeClass("active_tablink_start");
				$(".slideControl").removeClass("active_tablink_end");
				if($(this).attr('ref') == 'base'){
					$(this).addClass("active_tablink");
				}else{
					$(this).addClass("active_tablink_"+$(this).attr('ref'));					
				}
				
				//Motion
				if(arg.motion == 'static'){
					$(arg.slider).css({
						marginLeft: "-" + (i * $('.'+$(this).attr('title')).width()) + "px"
					});
				}else{
					tmpHeight = $('.'+$(this).attr('title')).height();
					$(arg.slider).animate({
						  marginLeft: "-" + (i * $('.'+$(this).attr('title')).width() + "px")
					}, { duration: arg.duration, easing: arg.motion, queue: false});
					//, complete: function(){
					
					$(arg.slider).animate({
					//	  height: tmpHeight + "px"
					}, { duration: arg.duration, easing: arg.motion, queue: false});

				//}});

				}
			});
		});
		sliderWidth = sliderWidth*multiplier;
		//alert(sliderHeight);
		$(".sliderWindow").css({
			position:"relative",
			//height: sliderHeight+"px",
			overflow: "hidden"
		});
		$(arg.slider).css({
			position:"relative",
			width: sliderWidth+"px",
			//height: sliderHeight+"px",
			overflow: "hidden"
		});
		$('.sliderItem').css({
			visibility: "visible",
			position:"relative",
			background: "inherit",
			width: $(".sliderWindow").width()+1+"px",
			//height: sliderHeight+"px",
			"float":"left"
		});
	};
	
})(jQuery);
