// Front page functions
var animationIndex = 0;
var animationTimeout = 0;

function fpAnimate()
{
	animationIndex++;
	if (animationIndex >= $("#fpArt_tab > div").length) animationIndex = 0;
	fpUpdate(1);
	animationTimeout = setTimeout(fpAnimate, 7000);
}

function fpStopAnimation()
{
	clearTimeout(animationTimeout);
}

function fpUpdate(direction)
{
	$(".overlay").show();
	
	var n = $("#fpArt_tab > div").length;
	var a1 = animationIndex;
	var a2 = a1 + 1 < n ? a1 + 1 : 0;
	var a3 = a2 + 1 < n ? a2 + 1 : 0;
	
	var fp = $("#fpArt_tab");
	//fp.find(".title").hide();
	if (direction > 0){
		fp.find("#fp" + a3).css({left: 1000});
		fp.find(".fp1").removeClass("fp1").addClass("fpD").css({left: 500});
	}
	else {
		fp.find("#fp" + a1).css({left: -200});
		fp.find(".fp3").removeClass("fp3").addClass("fpD").css({left: -500});
	}
	fp.find(".arrowLeft").hide();
	fp.find(".arrowRight").hide();
		
	fp.find("#fp" + a1).animate({ top: 40, left: 3, width: 75, height: 316 }, 500, function() {
		//$(this).find(".title").css({"top": 0, "margin-top": 0}).show();
  });
	fp.find("#fp" + a1).find(".overlay").animate({ opacity: 0.7 });
	
	fp.find("#fp" + a2).animate({ top: 15, left: 80, width: 575, height: 360 }, 500, function() {
		$(this).find(".title").css({"margin-top": 60}).show().animate({marginTop: 260}, 200);
		$(this).find(".title").css({"top": 60, "margin-top": 60}).show().animate({marginTop: 260, top: 260}, 200);
		fp.find(".arrowLeft").fadeIn();
		fp.find(".arrowRight").fadeIn();
  });
	fp.find("#fp" + a2).find(".overlay").animate({ opacity: 0.0 });

	fp.find("#fp" + a3).animate({ top: 40, left: 660, width: 75, height: 316 }, 500, function() {
		$(this).find(".title").css({"top": 0, "margin-top": 0}).show();
  });
	fp.find("#fp" + a3).find(".overlay").animate({ opacity: 0.7 });
	
	fp.find("#fp" + a1).removeClass("fpD fp1 fp2 fp3").addClass("fp1");
	fp.find("#fp" + a2).removeClass("fpD fp1 fp2 fp3").addClass("fp2");
	fp.find("#fp" + a3).removeClass("fpD fp1 fp2 fp3").addClass("fp3");
}


function fpScroll(direction)
{
	clearTimeout(animationTimeout);
	animationIndex += direction;
	var n = $("#fpArt_tab > div").length;
	if (animationIndex >= n) animationIndex = 0;
	if (animationIndex < 0) animationIndex = n-1;
	fpUpdate(direction);
}



/**
 * common theme behaviours
 * 
 */

jQuery(document).ready(function($){
	  
	   $(function(){
	        $("div.calNM1").carousel();
	    });
});
;
/**
 * Top region js
 * bartext and bartext2 come from theme settings through template.php
 */
jQuery(document).ready(function($) {

  	// Hide region (don't hide in the demo block page)
	if(!Drupal.settings.adabasket.blockdemo){
		$('#topBar').hide();
	}
	
	// set the right text in the blcok demo page
	if(Drupal.settings.adabasket.blockdemo){
		$('#topBarLink a').text("↑ " + Drupal.settings.adabasket.bartext2 + "");
	}
	
	// Make the spy effect
	$('#topBarLink a').live('mouseover mouseout', function(event) {
    if (event.type == 'mouseover' && $(this).text() == "↓ " + Drupal.settings.adabasket.bartext + "") {
      $('#topBarLink').animate({
        'padding-top':'5px'
      });
    }
    else if (event.type == 'mouseout' && $(this).text() == "↓ " + Drupal.settings.adabasket.bartext + "") {
    $('#topBarLink').animate({
      'padding-top':'0px'
    });
    }
	});
  
	// Click logics
	$('#topBarLink a').click(function () {
    if ($(this).text()=="↓ " + Drupal.settings.adabasket.bartext + "") {
      $(this).text("↑ " + Drupal.settings.adabasket.bartext2 + "");
      $(this).attr('title','Close this region');
    }
    else if ($(this).text()=="↑ " + Drupal.settings.adabasket.bartext2 + "") {
      $(this).text("↓ " + Drupal.settings.adabasket.bartext + "");
      $(this).attr('title','Open this region');
    }
    $('#topBar').slideToggle("slow");
    return false;
  });

	// Link positioning
	var linkWidth = $('#topBarLink a').width();
	var windowWidth = $(window).width();

  	// Set start margin
	$('#topBarLink a').css('margin-left', ((windowWidth / 2) - (linkWidth / 2) -10) + 'px');

	$(window).bind('resize', function(event) {
		$('#topBarLink a').css('margin-left', (($(window).width() / 2) - (linkWidth / 2) - 10) + 'px');
	});

});;

