(function($) {
$.fn.commentsRotator = function (limit, interval) {
		limit = limit || 3;
		interval = interval || 10000;

		return this.each(function () {
				// 1. setup
				// capture a cache of all the list items
				// chomp the list down to limit li elements
				var $list = $(this),
				items = [], // uninitialised
				currentItem = limit,
				total = 0, // initialise later on
				height = $list.find('> li:first').height();

				// capture the cache
				$list.find('> li').each(function () {
						items.push('<li>' + $(this).html() + '</li>');
				});

				total = items.length;

				$list.wrap('<div class="spyWrapper" />').parent().css({ height : height * limit });

				$list.find('> li').filter(':gt(' + (limit - 1) + ')').remove();

				// 2. effect
				function spy() {
						// insert a new item with opacity and height of zero
						var $insert = $(items[currentItem]).css({
								height : 0,
								opacity : 0,
								display : 'none'
						}).prependTo($list);

						// fade the LAST item out
						$list.find('> li:last').animate({ opacity : 0}, 1000, function () {
								// increase the height of the NEW first item
								$insert.animate({ height : height }, 1000).animate({ opacity : 1 }, 1000);

								// AND at the same time - decrease the height of the LAST item
								// $(this).animate({ height : 0 }, 1000, function () {
								// finally fade the first item in (and we can remove the last)
								$(this).remove();
								// });
						});

						currentItem++;
						if (currentItem >= total) {
								currentItem = 0;
						}

						setTimeout(spy, interval)
				}

				spy();
		});
};




	$.fn.slideshow = function(options){
	
			var defaults = {
					pauseSeconds: 2,
					fadeSpeed: 0.5,
					width: 468,
					height: 120,
					caption: true,
					cssClass: 'slideshowlite'
			};
	
			var options = $.extend(defaults, options);
	
			// ----------------------------------------
			// slideshow objects and variables
			// ----------------------------------------
	
			var target = this;
			var items  = $(target).children("a");
			var instance;
	
			// ----------------------------------------
			// some mandontory styling
			// ----------------------------------------
	
//        if ( ! $(this).hasClass(options.cssClass)) $(this).addClass(options.cssClass);
	
			$(this).css({
					width: options.width + "px",
					height: options.height + "px"
			});
	
			// ----------------------------------------
			// create anchor links to make the structure simpler for manupilation
			// ----------------------------------------
	
			$(this).children("div.slide").children("div.banner_text").fadeTo(0,0.85);

			
			$(this).children("div.slide").wrap(document.createElement("a"));
			
			$(this).children("a").attr("target", "blank");
	
			// ----------------------------------------
			// add item sequence markups
			// ----------------------------------------
	
			var i = 1;
			$(this).children("a").each(function(){
					$(this).attr("rel", i++);
			});
	
			// ----------------------------------------
			// create pagination and caption
			// ----------------------------------------
	
			$(this).append("<ul></ul>");
			$(this).append("<ol></ol>");
			var pagination = $(this).children("ul");
			
	
			var i = 1;
			var j = 0;
			$(this).children("a").each(function(){
					pagination.append("<li class='slideshow_paging'><a href=\"#\">" + i++ + "</a></li>");
//						caption.append("<li>" + $("#" + $(target).attr("id") + " img:nth(" + j++ + ")").attr("alt") + "</li>");
			});
			pagination.fadeTo(0, 0.8);
//        caption.hide();
	
			// ----------------------------------------
			// shortcuts
			// ----------------------------------------
	
			var firstItem   = $(target).children("a:first");
			var lastItem    = $(target).children("a:last");
			var currentItem = firstItem;
	
			// ----------------------------------------
			// pagination highlight
			// ----------------------------------------
	
			var paginationHighlight = function(sequence){
					pagination.children("li.slideshow_paging").children("a").removeClass("current");
					pagination.children("li.slideshow_paging").children("a:nth(" + sequence + ")").addClass("current");
			}
	
			// ----------------------------------------
			// caption
			// ----------------------------------------
/*		
			var showCaption = function(sequence){
					caption.show();
					caption.children("li").hide();
					caption.children("li:nth(" + sequence + ")").fadeIn();
			}
*/		
			// ----------------------------------------
			// slideshow logic
			// ----------------------------------------
	
			var makeSlideshow = function(){
		
					// pagination click
					pagination.children("li.slideshow_paging").children("a").click(function(){
							if ( ! $(this).hasClass("current"))
							{
									// select the current item after the pagination click
									currentItem = $(target).children("a:nth(" + ($(this).text()-1) + ")");

									currentItem.show();
									startSlideshow();
							}
					});
		
					// pagination highlight
					paginationHighlight(currentItem.attr("rel")-1);
		
					// show caption
/*            if (options.caption == true)
					{
							showCaption(currentItem.attr("rel")-1);
					}
*/			
					// show the current slide
					currentItem.fadeIn(options.fadeSpeed*1000, function(){
							$(target).children("a").hide();
							$(this).show().css("z-index", 1);
					});
		
					// prepare for the next slide
					// determines the next item (or we need to rewind to the first item?)
					if (currentItem.children("div").attr("rel") == lastItem.children("div").attr("rel"))
					{
							currentItem = firstItem;
							currentItem.css("z-index", 2);
					}
					else
					{
							currentItem = currentItem.next();
					}
			};
	
			var startSlideshow = function(){
					clearInterval(instance);
					makeSlideshow();
					instance = setInterval(makeSlideshow, options.pauseSeconds*1000);
			};
	
			// ----------------------------------------
			// start the slideshow!
			// ----------------------------------------
	
			startSlideshow();
	};

	$.fn.expanDiv = function (collapsedHeight) {
		mouse_over = false;
		
		var $this = $(this);
		
		$this.css("height", collapsedHeight + 'px')
//		var collapsedHeight = $this.height() + 'px'; // use when set from the target div
		$this.css("height", "auto");
		var autoHeight = $this.height() + 35 + 'px';
		$this.css("height", collapsedHeight);
		
		var expanded = false;
		var counter = 0;
		
		$this.mouseover(function()
		{
			mouse_over = true;
			if (mouse_over && !expanded)
			{
				$this.animate({height: autoHeight}, 500, function()
				{
					expanded = true;
				});
			}
		});
		
		
		$this.mouseout(function() {
			mouse_over = false;
			setTimeout (function(){
					if (!mouse_over && expanded)
					{
						$this.animate({height: collapsedHeight}, 500);
						expanded = false;
					}				
				}
			, 4000);
			});
					
	};
	

})(jQuery);



function countDown2010(yr, m, d, hr, min) {
	var current = "";
	var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

	var theyear = yr;
	var themonth = m;
	var theday = d;
	var thehour = hr;
	var theminute = min;
	var today = new Date();
	var todayy = today.getYear();
	if (todayy < 1000) {
			todayy += 1900
	}
	var todaym = today.getMonth();
	var todayd = today.getDate();
	var todayh = today.getHours();
	var todaymin = today.getMinutes();
	var todaysec = today.getSeconds();

	var todaystring = montharray[todaym] + " " + todayd + ", " + todayy + " " + todayh + ":" + todaymin + ":" + todaysec;
	var futurestring = montharray[m - 1] + " " + d + ", " + yr + " " + hr + ":" + min;
	var dd = Date.parse(futurestring) - Date.parse(todaystring);
	var dday = Math.floor(dd / (60 * 60 * 1000 * 24) * 1);
	var dhour = Math.floor((dd % (60 * 60 * 1000 * 24)) / (60 * 60 * 1000) * 1);
	var dmin = Math.floor(((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) / (60 * 1000) * 1);
	var dsec = Math.floor((((dd % (60 * 60 * 1000 * 24)) % (60 * 60 * 1000)) % (60 * 1000)) / 1000 * 1);

	if (dday <= 0 && dhour <= 0 && dmin <= 0 && dsec <= 0) {
			document.getElementById("dday").style.display = "none";
			return;
	}
	else {
			//document.getElementById("dday").innerHTML = dday;
			var hd =Math.floor(dday/100);
			var td=Math.floor(dday/10)-(hd*10);
			var od=Math.floor(dday)-(hd*100)-(td*10);

			document.getElementById("dday").innerHTML ="<img src='"+theme_path+"/images/img/"+hd+".png'/><img src='"+theme_path+"/images/img/"+td+".png'/><img src='"+theme_path+"/images/img/"+od+".png'/>"
			setTimeout("countdown('" + theyear + "','" + themonth + "','" + theday + "','" + thehour + "','" + theminute + "')", 60000);
	}
}