﻿// JavaScript Document

jQuery(document).ready(function () {
	
	/* Report Slider */
	Report_slideCount = 1;
	Report_visibleCount = 4;
	Report_current = 1;
	Report_count = getItemsCount(".reportsBlock .container");
	Report_Dir = "bottom";
	changeContainerHeight(".reportsBlock .container");
	enableDisableArrow(".reportsBlock",Report_current,Report_count,Report_visibleCount);
	jQuery(".reportsBlock .bottomArrow").click(function(){
		if (Report_current > 1){
			Report_current = itemsSlide(".reportsBlock",Report_current,Report_count,Report_visibleCount,'top',500,Report_slideCount);
			Report_Dir = "top";
		}
	});
	jQuery(".reportsBlock .topArrow").click(function(){
		if (Report_current <= Report_count - Report_visibleCount){
			Report_current = itemsSlide(".reportsBlock",Report_current,Report_count,Report_visibleCount,'bottom',500,Report_slideCount);
			Report_Dir = "bottom";
		}
	});
	
	var interval2;
	interval2 = setInterval(intervalFun, 3500);
	
	jQuery(".reportsBlock").hover(function(){
		clearInterval(interval2);
	},
	function(){
		interval2 = setInterval(intervalFun, 3500);
	});
});

/* Report Slider */
function changeContainerHeight(block) {
	var sum=0;
	jQuery(block + ' > li').each(function(){
		sum += jQuery(this).outerHeight(true)+1;
	});
	jQuery(block).css('height', sum + 'px');
}
function getItemsCount(block) {
	var ItemsCount = 0;
	jQuery(block + ' > li').each(function(){
		ItemsCount += 1;
	});
	return ItemsCount;
}
function enableDisableArrow(block,currentItem,itemsCount,itemsVisibleCount){
	if(currentItem >= itemsCount - itemsVisibleCount + 1 ){
		jQuery(block + ' .bottomArrow').addClass('arrowDisable');
	}
	else{
		jQuery(block + ' .bottomArrow').removeClass('arrowDisable');
	}
	if(currentItem == 1){
		jQuery(block + ' .topArrow').addClass('arrowDisable');
	}
	else{
		jQuery(block + ' .topArrow').removeClass('arrowDisable');
	}
}
function itemsSlide(root,currentItem,itemsCount,itemsVisibleCount,direction,speed,slideCount) {
	block = root + ' .container';
	var slideValue = parseInt(jQuery(block + ' > li').outerHeight(true)) * slideCount;
	var topValue = parseInt(jQuery(block)[0].style.top + 0);
	
	if(direction == 'top'){
		if ($.browser.msie && $.browser.version.slice(0,3) == "9.0" ){
			jQuery(block).animate({
				top: "+=" + slideValue
			  },speed
			);
		}
		else{
			jQuery(block).animate({
				top: "+=" + slideValue
			  },speed
			);
		}
		currentItem -= slideCount;
	}
	else{
		if ($.browser.msie && $.browser.version.slice(0,3) == "9.0" ){
			jQuery(block).animate({
				top: "-=" + slideValue
			  },speed
			);
		}
		else{
			jQuery(block).animate({
				top: "-=" + slideValue
			  },speed
			);
		}
		currentItem += slideCount;
	}
	enableDisableArrow(root,currentItem,itemsCount,itemsVisibleCount);
	return currentItem;
}
function intervalFun() {
	if (Report_Dir == "bottom")
	{
		if (Report_current >= 1 && Report_current <= Report_count - Report_visibleCount)
		{
			Report_current = itemsSlide(".reportsBlock",Report_current,Report_count,Report_visibleCount,'bottom',500,Report_slideCount);
		}
		if (Report_current > Report_count - Report_visibleCount )
		{
			Report_Dir = "top";
		}
	}
	else
	{
		if (Report_current >= 1 && Report_current <= Report_count - Report_visibleCount + 1)
		{
			Report_current = itemsSlide(".reportsBlock",Report_current,Report_count,Report_visibleCount,'top',500,Report_slideCount);
		}
		if (Report_current == 1)
		{
			Report_Dir = "bottom";
		}
	}
}

