$(function(){
	var selected, count;
	$(".select").click(function(){
		$(this).find(".options").slideToggle(400);
		(count == 1) ? $(this).find("span.select_arrow").html("&raquo;") : $(this).find("span.select_arrow").html("&laquo;");
		(count == 1) ? count = 0 : count = 1;			
		selected = $(this);
	});
	
	$(".option_item").click(function(){
		$(selected).find(".selected").html($(this).find(".item_value").html());
		$(selected).prev().val($(this).find(".item_value").html());
		prodId = $(this).find(".value").html();
		if(prodId != null) Redireciona(prodId);
	}).hover(function(){
		$(this).find(".item_value").stop().fadeTo("slow",1);
	}, function(){
		$(this).find(".item_value").fadeTo("slow",0.6);
	});
	
	// Scroll
	$(".scroll_bar").draggable({ axis: "y" });
	
	// Corrige o max e min size da scroll bar
	$(document).mousemove(function(){
		_top = $(".scroll_bar").css("top");
		_top = _top.substr(0,_top.length-2);
		if(_top <= 0) $(".scroll_bar").css("top",0);
		if(_top >= 320) $(".scroll_bar").css("top",320);
	});
	
	_limitSize = ($(".item_limit").find(".option_item").size() * 10);
	$(".item_limit").css("height",_limitSize);
	
	
	__top = $(".options").css("top");
	//alert(__top);
	
	$(".scroll_bar").hover(function(){
		$(this).fadeTo("slow",1);
	}, function(){
		$(this).fadeTo("slow",1);
	}).bind( "drag", function(event, ui){
		_y = $(this).css("top");
		_y = _y.substr(0,_y.length-2);
		_y = (_limitSize * (_y/100)) - 20;
		$(".item_limit").css("top",-_y+"px");
		//$(".item_limit").animate({"top":-_y+"px"}); //bind "dragstop"
	});
	
	$(".select").bind("mousewheel",function(){return false;});
	
	$(".scroll_down").click(function(){
		return false;
	});
});
