var isGclTopModOpen = false;
var isGclTopModHeight = -55;


var $gclFeaturedLinks;
var gclFeaturedLinkCurPos = -1;


var $gclContentRotatorLinks;
var $gclContentRotatorContents;
var gclContentRotatorLinkCurPos = 0;
var gclContentRotatorLinkHeight = 52;
var gclContentRotatorLinkTop = 10;

var rotatorContentCount;
var rotateContentInterval;
var isContinueRotate = true;

$(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");
  $gclContentRotatorLinks.attr({'href': 'javascript:void(0)'});
  $gclContentRotatorContents = $(".gcl-content-rotator-content");
  rotatorContentCount = $gclContentRotatorContents.size();  


  rotateContentInterval = setInterval(rotateToNextContent,5500);
  

  $gclContentRotatorLinks.click(function () { 
	if(gclContentRotatorLinkCurPos != $gclContentRotatorLinks.index(this)) {
		gclContentRotatorLinkCurPos = $gclContentRotatorLinks.index(this);
		isContinueRotate = false;
		clearInterval ( rotateContentInterval );
		rotateContent();	
	}
  });


  function rotateToNextContent() {
	if(isContinueRotate) {
	    gclContentRotatorLinkCurPos++;
	    if(gclContentRotatorLinkCurPos >= rotatorContentCount) { gclContentRotatorLinkCurPos = 0; }
	    rotateContent();
	}
	clearInterval ( rotateContentInterval );
  }


  //if ($.browser.msie) { gclContentRotatorLinkHeight += 1; }

  function rotateContent() {
    $("#gcl-content-rotator-arrow").animate({ top:(gclContentRotatorLinkCurPos*gclContentRotatorLinkHeight)+gclContentRotatorLinkTop }, "fast");

    $gclContentRotatorLinks.removeClass("selected");
    $gclContentRotatorLinks.eq(gclContentRotatorLinkCurPos).addClass("selected");
    //$(this).addClass("selected");
    $gclContentRotatorContents.hide("fast");
    $gclContentRotatorContents.eq(gclContentRotatorLinkCurPos).show("slow");
  }



});
