 $(document).ready(function() {
    //call function to replace select box with styled dropdown
   get_selects();
 });

/********************************************* Javascript drop down selects *********************************************/
//this function takes the below defined elements and converts any select boxs contained within
//to a javascript dropdown list (similer to suckerfish) and sends user to rss page on selection

var cur_submit = false;
var cur_select = "";
var drop_open = false;

function get_selects()
{
   if($("#feed_subs").length)
   {
	var sel2 = $("#feed_subs");
	var sel2_opt = $("#feed-subscribe-select > option").size();
	var sel2_opt_val = ""
	
	for(x=2; x<=sel2_opt; x++)
	{
	    var sel_text = $("#feed-subscribe-select :nth-child("+x+")").text();
	    var sel_link = $("#feed-subscribe-select :nth-child("+x+")").val();
	    sel2_opt_val += "<li><a href='"+sel_link+"' title='View feed'>"+sel_text.replace('\'', ' ')+"</a></li>";
	}
	 
	sel2.html("<a href='#' title='Subscribe to feed' id='show_results_format' onclick='return false;'>"+$("#feed-subscribe-select").children(":first-child").text().replace("'","")+"</a><ul>"+sel2_opt_val+"</ul>");
	
	$("#show_results_format").bind("click", function(event){
			var pos = $(this).position();
			$("#feed_subs ul").css("left", pos.left);
			$("#feed_subs ul").css("top", pos.top+27);
			$("#feed_subs ul").fadeIn("fast");
			close_selects();
	})
	
	$("#feed_subs ul li a").bind("click", function(){
	  return_res($(this).text(),$(this).attr('href'));
	});
	
   }
}


//this is the function that actually does the putting of values into hideen fields
function return_res(cont, link)
{
    $("#show_results_format").html("Select a feed");
    $("#feed_subs ul").fadeOut("fast");
    drop_open = false;
}

function close_selects()
{
    if(drop_open)
    {
      $("#show_results_format").html("Select a feed");
      $("#feed_subs ul").fadeOut("fast");
      $("#show_results_format").removeClass("close");
      open = false;
      return false;
    }
    else
    {
      $("#show_results_format").html("Close");
      $("#show_results_format").addClass("close");
      drop_open = true;
    }
}
