(function($) {
$.fn.newsTicker = $.fn.newsticker = function(delay)
{
	delay = delay || 6000;
	initTicker = function(el)
	{
		stopTicker(el);
		el.items = $("li", el);
		// hide all items (except first one)
		el.items.not(":eq(0)").hide().end();
                $("#ticker_list").attr("class","show");
		// current item
		el.currentitem = 0;
		startTicker(el);
	};
	startTicker = function(el)
	{
		el.tickfn = setInterval(function() { doTick(el) }, delay)
	};
	stopTicker = function(el)
	{
		clearInterval(el.tickfn);
	};
	pauseTicker = function(el)
	{
		el.pause = true;
	};
	resumeTicker = function(el)
	{
		el.pause = false;
	};
	doTick = function(el)
	{
		// don't run if paused
		if(el.pause) return;
		// pause until animation has finished
		el.pause = true;
		// hide current item
		$(el.items[el.currentitem]).fadeOut("slow",
			function()
			{
				$(this).hide();
				// move to next item and show
				el.currentitem = ++el.currentitem % (el.items.size());
				$(el.items[el.currentitem]).fadeIn("slow",
					function()
					{
						el.pause = false;
					}
				);
			}
		);
	};
	this.each(
		function()
		{
			if(this.nodeName.toLowerCase()!= "ul") return;
			initTicker(this);
		}
	)
	.addClass("newsticker")
	.hover(
		function()
		{
			// pause if hovered over
			pauseTicker(this);
		},
		function()
		{
			// resume when not hovered over
			resumeTicker(this);
		}
	);
	return this;
};

})(jQuery);


function animateResults(){
$(".bar").each(function(){
var percentage = $(this).attr("id");
$(this).css({width: "0%"}).animate({  
width: percentage},1500);  
});  
}


(function($) {
$.fn.equalHeights = function(minHeight, maxHeight) {
tallest = (minHeight) ? minHeight : 0;
this.each(function() {
if($(this).height() > tallest) {
tallest = $(this).height();
}
});
if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
return this.each(function() {
$(this).height(tallest + 20)
});
}
})(jQuery);



/* Print Page */

$(".printpage").click(function() {
    window.print();
    return false;
});



$(document).ready( function(){

$("#ticker_list").newsTicker();
$(".poll").css("height",$(".poll").height()+10);
animateResults();
$("#box_1,#box_2").equalHeights();
$("#box_3,#box_4").equalHeights();
$("#box_5,#box_6").equalHeights();
$("#box_7,#box_8").equalHeights();
$("#box_9,#box_10").equalHeights();
$("#box_11,#box_12").equalHeights();
$("#box_13,#box_14").equalHeights();
$("#box_15,#box_16").equalHeights();
$("#box_17,#box_18").equalHeights();
$("#box_19,#box_20").equalHeights();
});



/* Poll Functionality */

$("#poll_submit").click(function() {
   $(".poll_error").hide();
   var isChecked = false;   
   var dataString = this.name + "=" + this.value + "&" ;
   $("input[name='option_id']").each(function() {
      if(this.checked) {
         dataString = this.name + "=" + this.value;
         isChecked = true;
      }
   });
   if(!isChecked) {
      $(".poll_error").fadeIn(500);     
   }
   else {
       $(".poll_content").fadeOut(500, function () {
           $(".poll_loading").fadeIn(500,function () {
               $.ajax({
                   type: "POST",  
                   url: $(".poll form").attr("action"),  
                   data: dataString,
                   dataType: "html",
                   success: function(pollContent) {
                       $(".poll_content").html(pollContent)
                       $(".poll_loading").fadeOut(500)
                       $(".poll_content").fadeIn(500,animateResults);
                       $('.poll').supersleight();
                   }  
               });               
          });      
      });
  }
return false;
});


//News Date correction e.g. "Wed, 08 Jul 2009 00:00:00 +0100" to "08 Jul 2009"

$(document).ready(function() {
	var date_array=new Array();
	date_counter = 0;
	
	$(".news_date").each(function(){
		date_array[date_counter] = $(this).html().split(" ");
		$(this).html(date_array[date_counter][1]+" "+date_array[date_counter][2]+" "+date_array[date_counter][3]);
		date_counter=date_counter+1;
	});        
});

//