//var isGclTopModOpen = false;
//var isGclTopModHeight = -55;


var $gclFeaturedLinks;
var gclFeaturedLinkCurPos = -1;



var $gclContentRotatorLinks;
var $gclContentRotatorContents;
var gclContentRotatorLinkCurPos = 0;
var gclContentRotatorLinkHeight = 32;
var gclContentRotatorLinkTop = 8;



jQuery(document).ready(function() {


/*
  $("#gcl-topmod-tab-toggle").click(function () {
	if(isGclTopModOpen) {
		$("#gcl-topmod-wrapper").animate( { marginTop: isGclTopModHeight }, 1200);
		isGclTopModOpen = false;
		$(this).removeClass("gcl-topmod-tab-up");
		$(this).addClass("gcl-topmod-tab-down");
	} else {
		$("#gcl-topmod-wrapper").animate( { marginTop: "0" }, 1200);
		isGclTopModOpen = true;
		$(this).removeClass("gcl-topmod-tab-down");
		$(this).addClass("gcl-topmod-tab-up");
	}
  });

*/


  $gclFeaturedLinks = $(".gcl-featured-link");
  $gclFeaturedLinks.mouseover(function () {
    if(gclFeaturedLinkCurPos != $gclFeaturedLinks.index(this)) {
      $(this).animate({ top:4 }, 70).animate( { top:0 }, 70);
      gclFeaturedLinkCurPos = $gclFeaturedLinks.index(this);
    }
  });




  $gclContentRotatorLinks = $("#gcl-content-rotator li a");
  $gclContentRotatorContents = $(".gcl-content-rotator-content");
  $gclContentRotatorLinks.attr({'href': 'javascript:void(0)'});

  if ($.browser.msie) {
	var vers = $.browser.version.substring(0,1);
	if(vers > 6) {  }
	else {gclContentRotatorLinkHeight += 4;}
  }

  $gclContentRotatorLinks.click(function () {
	if(gclContentRotatorLinkCurPos != $gclContentRotatorLinks.index(this)) {
		gclContentRotatorLinkCurPos = $gclContentRotatorLinks.index(this);
		$("#gcl-content-rotator-arrow").animate({ top:(gclContentRotatorLinkCurPos*gclContentRotatorLinkHeight)+gclContentRotatorLinkTop }, "fast");
		$gclContentRotatorLinks.removeClass("selected");
		$(this).addClass("selected");
		$gclContentRotatorContents.fadeOut("fast");
		$gclContentRotatorContents.eq(gclContentRotatorLinkCurPos).fadeIn("slow");
	}
  });




	jQuery("ul.news-slider").liSlider({
		 slideSpeed   : 0.6,
		 slideInterval: 0
	});

});






(function($) {
$.fn.liSlider = function(options) {
   var defaults = {
	  slideSpeed   : 0.5,
	  slideInterval: 1000
   },
   settings = $.extend({}, defaults, options);
   return this.each(function () {
	  var $this = jQuery(this),
	  	stripWidth = 0,
		containerWidth = 0;
	  containerWidth = $this.parent().width();
	  $this.find("li").each(function (i) {
		 stripWidth += jQuery(this, i).width();
	  });
	  $this.width(stripWidth);
	  var totalSpace = stripWidth + containerWidth;
	  var totalTime = Math.floor(totalSpace / (settings.slideSpeed / 10));

	  function scrollnews(space, time) {
		 //console.log(":: containerWidth: %s - stripWidth: %s - space: %s - time: %s", containerWidth, stripWidth, space, time);
		 $this.animate({
			left: '-=' + space
		 }, time, "linear", function () {
			$this.css("left", containerWidth);
			setTimeout(function () {
			   scrollnews(totalSpace, totalTime);
			}, settings.slideInterval);
		 });
	  }

	  scrollnews(totalSpace, totalTime);

	  $this.hover(function () {
		 jQuery(this).stop();
	  }, function () {
		 var offset = jQuery(this).position();
		 var remainingSpace = Math.ceil(stripWidth + offset.left);
		 var remainingTime =  Math.ceil(remainingSpace / (settings.slideSpeed / 10));
		 //console.log("containerWidth: %s - stripWidth: %s - offset.left: %s - remainingSpace: %s - remainingTime: %s", containerWidth, stripWidth, offset.left, remainingSpace, remainingTime);
		 scrollnews(remainingSpace, remainingTime);
	  });
   });
};
})(jQuery);
