var effectInProgress=false;

var currentNews=1;

var step=10;

var pages=1;

var currentPage=1;

var currentIndex=50;

var oldPump=0;

var oldMode=0;

var tempPump=0;

var tempMode=0;



window.onload=function()
{
	if (document.getElementById('scrollContent')!=null && document.getElementById('scrollContent').offsetHeight<document.getElementById('scrollContent').scrollHeight)
	document.getElementById('scrollNav').style.display="block";
	
	
	if (document.getElementById('newsContent1')!=null && document.getElementById('newsContent1').offsetHeight<document.getElementById('newsContent1').scrollHeight)
	document.getElementById('newsNav1').style.display="block";


	if (document.getElementById('boxShowFrame')!=null)
	{
		pages=Math.ceil(document.getElementById('boxShowFrame').scrollWidth/975);
				
		if (pages>1) document.getElementById('boxShowScrollRight').style.display="block";
	}
}


function checkPump()
{
	if (tempPump!=0)
	{
		pumpImg(tempPump,tempMode);
		
		tempPump=0;
		
		tempMode=0;
	}
}


function pumpImg(id,mode)
{
	if (!effectInProgress)
	{
		if (oldPump!=0 && oldPump!=id && tempPump==0)
		{
			tempPump=id;
			tempMode=mode;
	
			id=oldPump;
			mode=oldMode;
		}
			
		currentIndex++;
		
		if (document.getElementById('img2'+id).offsetHeight>300)
		{
			oldPump=0;
		
			oldMode=0;
			
			document.getElementById('imgTitle'+id).style.display="none";
			
			if (mode==1)
			{
				new Effect.Parallel([
				new Effect.Scale('img2'+id,47.5,{queue: 'end', sync: true}),
				new Effect.Move('imgMove'+id,{mode: 'relative', y: 220, queue: 'end', sync: true})
				],{duration: 1, beforeStart: function(){effectInProgress=true;}, afterFinish: function(){effectInProgress=false;document.getElementById('imgFrame'+id).style.zIndex=1;checkPump();}});
			}
			else if (mode==2)
			{
				new Effect.Parallel([
				new Effect.Scale('img2'+id,47.5,{queue: 'end', sync: true}),
				new Effect.Move('imgMove'+id,{mode: 'relative', x: 165, queue: 'end', sync: true})
				],{duration: 1, beforeStart: function(){effectInProgress=true;}, afterFinish: function(){effectInProgress=false;document.getElementById('imgFrame'+id).style.zIndex=1;checkPump();}});
			}			
			else if (mode==3)
			{
				new Effect.Parallel([
				new Effect.Scale('img2'+id,47.5,{queue: 'end', sync: true}),
				new Effect.Move('imgMove'+id,{mode: 'relative', x: 165, y: 220, queue: 'end', sync: true})
				],{duration: 1, beforeStart: function(){effectInProgress=true;}, afterFinish: function(){effectInProgress=false;document.getElementById('imgFrame'+id).style.zIndex=1;checkPump();}});
			}
			else
			new Effect.Scale('img2'+id,47.5,{duration: 1, queue: 'end', beforeStart: function(){effectInProgress=true;},afterFinish: function(){effectInProgress=false;document.getElementById('imgFrame'+id).style.zIndex=1;checkPump();}});
		}
		else
		{			
			oldPump=id;
		
			oldMode=mode;

			document.getElementById('imgFrame'+id).style.zIndex=500;

			if (mode==1) //7-11
			{
				new Effect.Parallel([
				new Effect.Scale('img2'+id,210,{scaleMode: {originalHeight: 200, originalWidth: 150}, queue: 'end', sync: true}),
				new Effect.Move('imgMove'+id,{mode: 'relative', y: -220, queue: 'end', sync: true})
				],{duration: 1, beforeStart: function(){effectInProgress=true;}, afterFinish: function(){effectInProgress=false; document.getElementById('imgTitle'+id).style.display="block";}});
			}
			else if (mode==2) //6
			{
				new Effect.Parallel([
				new Effect.Scale('img2'+id,210,{scaleMode: {originalHeight: 200, originalWidth: 150}, queue: 'end', sync: true}),
				new Effect.Move('imgMove'+id,{mode: 'relative', x: -165, queue: 'end', sync: true})
				],{duration: 1, beforeStart: function(){effectInProgress=true;}, afterFinish: function(){effectInProgress=false; document.getElementById('imgTitle'+id).style.display="block";}});
			}
			else if (mode==3) //12
			{
				new Effect.Parallel([
				new Effect.Scale('img2'+id,210,{scaleMode: {originalHeight: 200, originalWidth: 150}, queue: 'end', sync: true}),
				new Effect.Move('imgMove'+id,{mode: 'relative', x: -165, y: -220, queue: 'end', sync: true})
				],{duration: 1, beforeStart: function(){effectInProgress=true;}, afterFinish: function(){effectInProgress=false; document.getElementById('imgTitle'+id).style.display="block";}});
			}
			else //1-5
			new Effect.Scale('img2'+id,210,{duration: 1, queue: 'end', scaleMode: {originalHeight: 200, originalWidth: 150}, beforeStart: function(){effectInProgress=true;}, afterFinish: function(){effectInProgress=false; document.getElementById('imgTitle'+id).style.display="block";}});
		}
	}
}


function toggleWindow(dir)
{
	if (!effectInProgress)
	{
		if (dir==1 && document.getElementById('scrollFrame').style.display!="none")
		new Effect.SlideUp('scrollFrame', {duration: 1.5, fps: 50, queue: 'end', beforeStart: function(){effectInProgress=true;}, afterFinish: function(){effectInProgress=false;toggleTitle(2);}});
		
		if (dir==2 && document.getElementById('scrollFrame').style.display=="none")
		new Effect.SlideUp('scrollTitle', {duration: 0.3, fps: 50, queue: 'end', beforeStart: function(){effectInProgress=true;}, afterFinish: function(){effectInProgress=false;toggleTitle(1);}});

	}
}


function toggleTitle(dir)
{
	if (!effectInProgress)
	{
		if (dir==1)
		new Effect.SlideDown('scrollFrame', {duration: 1.5, fps: 50, queue: 'end', beforeStart: function(){effectInProgress=true;}, afterFinish: function(){effectInProgress=false;}});
		
		if (dir==2)
		new Effect.SlideDown('scrollTitle', {duration: 0.3, fps: 50, queue: 'end', beforeStart: function(){effectInProgress=true;}, afterFinish: function(){effectInProgress=false;}});
	}
}


function showNews(id)
{
	if (!effectInProgress && currentNews!=id)
	{
		new Effect.Parallel([
		new Effect.SlideUp('newsBody'+currentNews, {sync: true, duration: 1.5, fps: 40, queue: 'end'}),
		new Effect.SlideDown('newsBody'+id, {sync: true, duration: 1.5, fps: 40, queue: 'end'})
		], { duration: 1, beforeStart: function(){effectInProgress=true;}, afterFinish: function(){checkScroll(id);effectInProgress=false;}});
		
		currentNews=id;

	}
}

function checkScroll(id)
{
	if (document.getElementById('newsContent'+id)!=null && document.getElementById('newsContent'+id).offsetHeight<document.getElementById('newsContent'+id).scrollHeight)
	document.getElementById('newsNav'+id).style.display="block";
}


function scrollShow(dir)
{
	if (!effectInProgress)
	{
		if (dir==1)
		var toScroll = (document.getElementById('boxShowFrame').scrollLeft>=975) ? 975 : document.getElementById('boxShowFrame').scrollLeft;

							
		if (dir==2)
		var toScroll = (document.getElementById('boxShowFrame').scrollWidth-(document.getElementById('boxShowFrame').scrollLeft+975)>=975) ? 975 : document.getElementById('boxShowFrame').scrollWidth-(document.getElementById('boxShowFrame').scrollLeft+975);

		effectInProgress=true;

		doScroll(toScroll,dir);	
	}
}


function doScroll(toScroll,dir)
{
	if (toScroll>=step)
	{
		(dir==2) ? document.getElementById('boxShowFrame').scrollLeft+=step : document.getElementById('boxShowFrame').scrollLeft-=step;

		window.setTimeout('doScroll('+(toScroll-step)+','+dir+')',10);	
	}
	else
	{
		(dir==2) ? document.getElementById('boxShowFrame').scrollLeft+=toScroll : document.getElementById('boxShowFrame').scrollLeft-=toScroll;

		effectInProgress=false;
		
		(dir==2) ? currentPage++ : currentPage--;
		
		document.getElementById('boxShowScrollRight').style.display = (currentPage<pages) ? "block" : "none";
		
		document.getElementById('boxShowScrollLeft').style.display = (currentPage>1) ? "block" : "none";
	}
}



