var allTablesPagesCount = 0;
var currentSelectTable;
var pagesNumber = 0;

$(document).ready(function() 
{
	var floatingPagesSelectPage;

	$("#image-page-pointer-start-text").hide();	
	$("#image-page-pointer-start-img").mouseover(function() 
	{
		$(this).attr("src", "http://www.seir.bg/images/image-page-pointer-start-shadow-modified.gif");
		$("#image-page-pointer-start-text").show();
	}).mouseout(function()
	{
		$(this).attr("src", "http://www.seir.bg/images/image-page-pointer-start-normal-modified.gif");
		$("#image-page-pointer-start-text").hide();
	});
	
	$("#image-page-pointer-previous-text").hide();
	$("#image-page-pointer-previous-img").mouseover(function() 
	{
		$(this).attr("src", "http://www.seir.bg/images/image-page-pointer-previous-shadow-modified.gif");
		$("#image-page-pointer-previous-text").show();
	}).mouseout(function()
	{
		$(this).attr("src", "http://www.seir.bg/images/image-page-pointer-previous-normal-modified.gif");
		$("#image-page-pointer-previous-text").hide();
	});
	
	$("#image-page-pointer-next-text").hide();
	$("#image-page-pointer-next-img").mouseover(function() 
	{
		$(this).attr("src", "http://www.seir.bg/images/image-page-pointer-next-shadow-modified.gif");
		$("#image-page-pointer-next-text").show();
	}).mouseout(function()
	{
		$(this).attr("src", "http://www.seir.bg/images/image-page-pointer-next-normal-modified.gif");
		$("#image-page-pointer-next-text").hide();
	});
	
	$("#image-page-pointer-end-text").hide();
	$("#image-page-pointer-end-img").mouseover(function() 
	{
		$(this).attr("src", "http://www.seir.bg/images/image-page-pointer-end-shadow-modified.gif");
		$("#image-page-pointer-end-text").show();
	}).mouseout(function()
	{
		$(this).attr("src", "http://www.seir.bg/images/image-page-pointer-end-normal-modified.gif");
		$("#image-page-pointer-end-text").hide();
	});
	
	$("#image-page-pointer-start-img").click(function()
	{
		hideAllTablesPages();
		currentSelectTable = 1;
		showOneTablePages(currentSelectTable, 'left');
	});
	
	$("#image-page-pointer-previous-img").click(function()
	{
		hideAllTablesPages();
		currentSelectTable--;
		if(currentSelectTable < 1)
		{
			currentSelectTable = 1;
			showOneTablePages(currentSelectTable, 'left');
		}
		else
		{
			showOneTablePages(currentSelectTable, 'left');
		}
	});
	
	$("#image-page-pointer-next-img").click(function()
	{
		hideAllTablesPages();
		currentSelectTable++;
		if(currentSelectTable > allTablesPagesCount)
		{
			currentSelectTable = allTablesPagesCount;
			showOneTablePages(currentSelectTable, 'right');
		}
		else
		{
			showOneTablePages(currentSelectTable, 'right');
		}
	});
	
	$("#image-page-pointer-end-img").click(function()
	{
		hideAllTablesPages();
		currentSelectTable = allTablesPagesCount;
		showOneTablePages(currentSelectTable, 'right');
	});
});

function setCurrentSelectTable(inputCurrentSelectTable)
{
	currentSelectTable = inputCurrentSelectTable;
}

function setFloatingPagesMouseEvent(pageId)
{
	$("#" + pageId).mouseover(function() 
	{
		$("#" + pageId + "-img").attr("src", "http://www.seir.bg/images/image-page-mouseover.gif");
		
		if(floatingPagesSelectPage != undefined)
		{
			setFloatingPagesSelectPage(floatingPagesSelectPage);
		}
	}).mouseout(function() 
	{
		$("#" + pageId + "-numbers").css("color", "#003282");
		$("#" + pageId + "-img").attr("src", "http://www.seir.bg/images/image-page-normal.gif");	
		
		if(floatingPagesSelectPage != undefined)
		{
			setFloatingPagesSelectPage(floatingPagesSelectPage);
		}
	}).mousedown(function() 
	{
		$("#" + pageId + "-numbers").css("color", "#ffffff");
		$("#" + pageId + "-img").attr("src", "http://www.seir.bg/images/image-page-mouseclick.gif");	
		
		if(floatingPagesSelectPage != undefined)
		{
			setFloatingPagesSelectPage(floatingPagesSelectPage);
		}
		
	}).mouseup(function()
	{
		$("#" + pageId + "-numbers").css("color", "#003282");
		$("#" + pageId + "-img").attr("src", "http://www.seir.bg/images/image-page-mouseover.gif");	
		
		if(floatingPagesSelectPage != undefined)
		{
			setFloatingPagesSelectPage(floatingPagesSelectPage);
		}
	});
	
}

function setFloatingPagesSelectPage(selectPageId)
{
	floatingPagesSelectPage	= selectPageId;
	$("#" + selectPageId + "-numbers").css("color", "#ffffff");
	$("#" + selectPageId + "-img").attr("src", "http://www.seir.bg/images/image-page-mouseclick.gif");	
}

function addOneTablePages()
{
	allTablesPagesCount += 1;
}

function showOneTablePages(tablePagesNumber, direction)
{
	clearAllPageBoxes();
	switch(direction)
	{
		case 'right':
				$("#table-pages-" + tablePagesNumber).show("slide", {direction: 'right'}, 500);
				//$('html, body').animate({scrollTop: 1000000000});
			break;
		case 'left':
				$("#table-pages-" + tablePagesNumber).show("slide", {direction: 'left'}, 500);
				//$('html, body').animate({scrollTop: 1000000000});
			break;
		default:
				$("#table-pages-" + tablePagesNumber).show("slide");
			break;
	}
	
	
}

function hideAllTablesPages()
{
	for( var i = 1; i <= allTablesPagesCount; i++)
	{
		$("#table-pages-" + i).hide();
	}	
}

function clearAllPageBoxes()
{
	for(i=0; i < pagesNumber; i++)
	{
		$("#floating-pages-page-number-" + i + "-numbers").css("color", "#003282");
		$("#floating-pages-page-number-" + i + "-img").attr("src", "http://www.seir.bg/images/image-page-normal.gif");	
	}
	
	if(floatingPagesSelectPage != undefined)
	{
		setFloatingPagesSelectPage(floatingPagesSelectPage);
	}
}

function setHrefLink(elementId, elementHref)
{
	$("#" + elementId).click(function()
	{
		window.location.href = elementHref;
	});
}

