$(document).ready(function()
		{
			
			findNewPolls();
			findPopularPolls();
			findHighestRatedPolls();
			getFeaturedPoll();
			
			$('#main_category').change(function()
					{
						var selected_category = $('#main_category option:selected').attr('value');
						if (selected_category != '-1')
						{
							var cat_link = 'http://pollshare.myisay.com/index.php/main/poll_search?category_search_list=' + selected_category + '&category_status=1&category_submit=Search&type=category';
							$('#show_category_list').attr('href', cat_link);
						}
					});

					
		
	
			function findNewPolls()
			{
				$.getJSON('/index.php/main/get_new_polls/', function(data)
						{
							if (data.results)
							{
								$('#new_poll_header').html('<img src="/web/images/icons/newpollsicon.jpg" /> New To PollShare');
								$.each(data.results, function(i, result)
										{
											//$('#new_poll_list').append('<li>Something</li>');
											//var append_string = '<li><a href="http://pollshare.myisay.com/index.php/show/poll/id/' + result.id + '>' + result.question + '</a></li>';
											//alert(append_string);
											$('#new_poll_list').append('<li><a href="http://pollshare.myisay.com/index.php/show/poll/id/' + result.id + '">' + result.question + '</a><br />By ' + result.author + '<br />' + result.date + '</li>');
										});

							}
							else
							{
								$('#new_polls').append('<p>There are no new polls at this time.');								
								$('#new_poll_header').html('<img src="/web/images/icons/newpollsicon.jpg" /> New To PollShare');
							}
						});
			}
			
			function findPopularPolls()
			{
				$.getJSON('/index.php/main/get_popular_polls/', function(data)
						{
							if (data.results)
							{;
								$('#popular_poll_header').html('<img src="/web/images/icons/popularpollsicon.jpg" /> Popular Polls');
								$.each(data.results, function(i, result)
										{
											$('#popular_poll_list').append('<li><a href="http://pollshare.myisay.com/index.php/show/poll/id/' + result.id + '">' + result.question + '</a><br />By ' + result.author + '<br />' + result.total + ' votes</li>');
										});
							}
							else
							{
								$('#popular_polls').append('<p>There are no popular polls at this time.</p>');
								$('#popular_poll_header').html('<img src="/web/images/icons/popularpollsicon.jpg" /> Popular Polls');
							}
					
					
						});
			}
			
			function findHighestRatedPolls()
			{
				$.getJSON('/index.php/main/get_highest_rated_polls/', function(data)
						{
							if (data.results)
							{;
								$('#rated_poll_header').html('<img src="/web/images/icons/highestratedicon.jpg" /> Highest Rated Polls');
								$.each(data.results, function(i, result)
										{	
											if (result.total > 0)
											{
												$('#rated_poll_list').append('<li><a href="http://pollshare.myisay.com/index.php/show/poll/id/' + result.id + '">' + result.question + '</a><br />By ' + result.author + '<br />+' + result.total + ' rating</li>');												
											}
											else
											{
												$('#rated_poll_list').append('<li><a href="http://pollshare.myisay.com/index.php/show/poll/id/' + result.id + '">' + result.question + '</a><br />By ' + result.author + '<br />' + result.total + ' rating</li>');												
											}
										});
							}
							else
							{
								$('#rated_polls').append('<p>There are no highest rated polls at this time.</p>');
								$('#rated_poll_header').html('<img src="/web/images/icons/highestratedicon.jpg" /> Highest Rated Polls');
							}
					
					
						});
			}			
			
			
			function getFeaturedPoll()
			{
				$.getJSON('/index.php/main/get_featured/', function(data)
						{
							if (data.results.success == true)
							{
								var featured_poll = data.results.id;
								$.getJSON('/index.php/widget/get_data/poll/' + featured_poll, function(data)
										{
											$('#featured_poll_header').html('<img src="/web/images/icons/featuredpollsicon.jpg" /> Featured Poll');
											$('#featured_poll_list').append('<li class="title">' + data.poll.question + '</li>');
											$('#featured_poll_list').append('<li class="author">By ' + data.poll.author + '</li>');
											$.each(data.poll.answers, function(i, answer)
													{
														$('#featured_poll_list').append('<li>&raquo ' + answer.text + '</li>');
													});
											$('#featured_poll_list').append('<li class="link"><a href="http://pollshare.myisay.com/index.php/show/poll/id/' + featured_poll + '">Vote Now!</a>');
									
										});
							}
							else
							{
								$('#featured_poll_header').html('<img src="/web/images/icons/featuredpollsicon.jpg" /> Featured Poll');
								$('#featured').append('<p>There is no featured poll at this time.</p>');
							}
							
						});
				/*$.getJSON('/index.php/widget/get_data/poll/' + featured_poll, function(data)
						{
							$('#featured_poll_header').html('<img src="/web/images/icons/featuredpollsicon.jpg" /> Featured Poll');
							$('#featured_poll_list').append('<li class="title">' + data.poll.question + '</li>');
							$('#featured_poll_list').append('<li class="author">By ' + data.poll.author + '</li>');
							$.each(data.poll.answers, function(i, answer)
									{
										$('#featured_poll_list').append('<li>&raquo ' + answer.text + '</li>');
									});
							$('#featured_poll_list').append('<li class="link"><a href="http://pollshare.myisay.com/index.php/show/poll/id/' + featured_poll + '">Vote Now!</a>');
					
						});
						*/
			}
	
	
		});