function change_type(type) 
{
	_this = $("#type_"+type);
	_line = $("#type_"+type).siblings("div.active_line");
	_this.children("span").animate({"top": "0px"}, { "duration": 1000, "queue": false, "easing": "easeInOutExpo" });
	_this.siblings("a.button").children("span").animate({"top": "58px"}, { "duration": 1000, "queue": false, "easing": "easeInOutExpo" });
	
	if (type == 1)
	{	
		$("#listing_1 .inactive").hide(0);
		$("#listing_2 .inactive").show(0);
		_line.animate({"width": "270px"}, { "duration": 1000, "queue": false, "easing": "easeInOutElastic" });
		$("#listing_3").slideUp(800);
		$("#listing_3").prev(".delimetr").hide(0);
		unchange_points(2);
		unchange_points(3);
		change_point(1, true);
		change_price();
	}
	
	if (type == 2)
	{	
		$("#listing_1 .inactive").hide(0);
		$("#listing_2 .inactive").hide(0);
		_line.animate({"width": "480px"}, { "duration": 1000, "queue": false, "easing": "easeInOutElastic" });
		$("#listing_3").slideUp(800);
		$("#listing_3").prev(".delimetr").hide(0);
		unchange_points(3);
		change_point(1, true);
		change_point(11, true);
		change_price();
	}
	
	if (type == 3)
	{	
		$("#listing_1 .inactive").hide(0);
		$("#listing_2 .inactive").hide(0);
		_line.animate({"width": "690px"}, { "duration": 1000, "queue": false, "easing": "easeInOutElastic" });
		$("#listing_3").slideDown(800);
		$("#listing_3").prev(".delimetr").show(0);
		change_point(1, true);
		change_point(2, true);
		change_point(11, true);
		change_point(12, true);
		change_point(21, true);
		change_point(22, true);
		change_price();
	}
}

function change_point(type, oneway) 
{
	_this = $("#point_"+type);
	
	if (_this.hasClass("yes") && !oneway)
	{
		_this.children("span").slideUp({ "duration": 500, "queue": false });
		_this.removeClass("yes");
		
		if (type == 1)
		{	
			unchange_points(1);
			unchange_points(2);
			unchange_points(3);
			$("#listing_1 .inactive").show(0);
			$("#listing_2 .inactive").show(0);
			$("div.active_line").animate({"width": "150px"}, { "duration": 1000, "queue": false, "easing": "easeInOutElastic" });
			$("a.button span").animate({"top": "58px"}, { "duration": 1000, "queue": false, "easing": "easeInOutExpo" });
		}
		
		if (type == 11)
			$("#type_1").trigger('click');		
			
		if (type == 21)
			$("#type_2").trigger('click');	
	}
	else
	{
		_this.children("span").slideDown({ "duration": 500, "queue": false });
		_this.addClass("yes");
	}
}

function unchange_points(type) 
{
	$("#listing_"+type+" a.checkbox span").slideUp({ "duration": 500, "queue": false });
	$("#listing_"+type+" a.checkbox").removeClass("yes");
}

function change_price() 
{
	_this = $("#price_bar");
	_line = _this.siblings("div.active_line");
	
	_total = 0;
	
	$("a.checkbox").each(function(e){ 

		_box = $(this);
		
		if (_box.hasClass("yes"))
		{
			_em = _box.siblings("em").text();
			_em = _em.replace(/\s/g, '');
			_quantity = _box.siblings("span.quantity").children("input").val();
	
			if (!_quantity || _quantity < 0 || isNaN(_quantity)) _quantity = 1;
			
			_total = _total + _em * _quantity;
		}
	});
	
	$("#price_bar em").text(_total);
	
	if (_total == 0)
	{
		_this.children("span").animate({"top": "58px"}, { "duration": 1000, "queue": false, "easing": "easeInOutExpo" });
		_this.animate({"right": 420+"px"}, { "duration": 1000, "queue": false, "easing": "easeInOutElastic" });		
		_line.animate({"width": 150+"px"}, { "duration": 1000, "queue": false, "easing": "easeInOutElastic" });
		return false;
	}
	
	_num = _total - 15000;
	_num = _num * 6 / 1000;
	
	_right = 420 - _num;
	if (_right < 0) _right = 0;
	
	_left = 784 - _right - 93;
	_this.children("span").animate({"top": "0px"}, { "duration": 1000, "queue": false, "easing": "easeInOutExpo" });
	_this.animate({"right": _right+"px"}, { "duration": 1000, "queue": false, "easing": "easeInOutElastic" });
	
	_line.animate({"width": _left+"px"}, { "duration": 1000, "queue": false, "easing": "easeInOutElastic" });
}

$.fn.ValidNumeric = function(){
	$(this).bind('keyup', function(e){
		value = $(this).val();
		$(this).val(value.replace(new RegExp("[^0-9]",'g'), ""));
	});
	$(this).bind('blur', function(e){
		value = $(this).val();
		if (!value) 
		{ 
			$(this).val("1");
		}
	});
}

$(function(){
	
	$(".quantity input").ValidNumeric();
	$(".quantity input").change(function(){
		change_price();
	});
	
	$("a.about").mouseenter(function(e){

		tiptext = $(this).next(".about_text").html();
		$("#canvas-container").append("<div id='tip_wrapper'><div class='top'>"+tiptext+"</div><div class='bottom'></div></div>");

		tiptx = $(this).offset().left;
		tipty = $(this).offset().top - $("#tip_wrapper").height();
		
		vartop = tipty - 0;
		varleft = tiptx - 148 + 11;
		
		$("#tip_wrapper")
			.css("top", vartop + "px")
			.css("left", varleft + "px")
			.css("height", "auto")
			.slideUp(0)
			.slideDown(300);
				
    }).mouseout(function(){
 		$("#tip_wrapper").remove();
    });
	
});
