/**
*	global js file template for POSK
* 	$Id: global.js 606 2010-04-28 15:43:49Z dl0 $
*	project:		trunk
*	all rights at:	daniel.liebig@wevin.de
**/


function flipContent()
{
	fadingSpeed = 400;

	if ( $("#layerLeft").css('display') == 'none' )
	{
		$("#layerLeft").fadeIn(fadingSpeed);
		$("#layerRight").fadeIn(fadingSpeed);
		$("#npText").attr('src', '/img/navigation/np_text_a.gif');
	}
	else
	{
		$("#layerLeft").fadeOut(fadingSpeed);
		$("#layerRight").fadeOut(fadingSpeed);
		$("#npText").attr('src', '/img/navigation/np_text_n.gif');
	}
}

var currentImgNo = 1;



function nextImg(page)
{
	//-- change background images

	var imgName;
	var lastImgNo = 0;
	if ( page == 'friedwald' ) {
		lastImgNo = 14;
	}
	else if ( page == 'feste_u_events' ) {
		lastImgNo = 38;
	}
	
	currentImgNo++;

	//-- swith images	
	if ( currentImgNo < 10 )
	{
		imgName = 'bg_' + page + '_0' + currentImgNo;
	}
	else
	{
		imgName = 'bg_' + page + '_' + currentImgNo;
	}
	$("#left").css('background-image', $("#right").css('background-image'));
	$("#right").css('background-image', 'url(/img/content/' + page + '/' + imgName + '.jpg)');

	//-- manage navigation arrows
	setBackButton(page);
	setNextButton(page, lastImgNo);

	//-- fade out text
	if ( $("#layerLeft").css('display') == 'block' )
	{
		flipContent();
	}

	//-- set category for feste & Events
	if ( page == 'feste_u_events' )
	{
		setCategoryActive();
	}

}

function prevImg(page)
{
	//-- change background images

	var imgName;
	
	currentImgNo--;

	//-- swith images	
	if ( ( currentImgNo - 1 ) < 10 )
	{
		imgName = 'bg_' + page + '_0' + ( currentImgNo - 1);
	}
	else
	{
		imgName = 'bg_' + page + '_' + ( currentImgNo - 1);
	}
	$("#right").css('background-image', $("#left").css('background-image'));
	$("#left").css('background-image', 'url(/img/content/' + page + '/' + imgName + '.jpg)');

	//-- manage navigation errors
	setBackButton(page);
	setNextButton(page, 500);

	//-- fade out text
	if ( $("#layerLeft").css('display') == 'block' )
	{
		flipContent();
	}

	//-- set category for feste & Events
	if ( page == 'feste_u_events' )
	{
		setCategoryActive();
	}
}

function jumpToImg(page, imgNo)
{
	var imgName;
	
	currentImgNo = imgNo;

	//-- swith images	
	if ( ( currentImgNo - 1 ) < 10 )
	{
		leftImgName = 'bg_' + page + '_0' + ( currentImgNo - 1 );
	}
	else
	{
		leftImgName = 'bg_' + page + '_' + ( currentImgNo - 1 );
	}
	if ( ( currentImgNo ) < 10 )
	{
		rightImgName = 'bg_' + page + '_0' + currentImgNo;
	}
	else
	{
		rightImgName = 'bg_' + page + '_' + currentImgNo;
	}
	$("#left").css('background-image', 'url(/img/content/' + page + '/' + leftImgName + '.jpg)');
	$("#right").css('background-image', 'url(/img/content/' + page + '/' + rightImgName + '.jpg)');

	// manage navigation arrows
	setBackButton(page);
	setNextButton(page, 500);

	//-- fade out text
	if ( $("#layerLeft").css('display') == 'block' )
	{
		flipContent();
	}

	//-- set category active
	setCategoryActive();
}

function setBcImg(month, imgSrc)
{
	$("#right").css('background-image', 'url(/img/content/bluetenkalender/' + month + '/' + imgSrc + ')');

}

/** Todo: someday use jquery for this (remember to merge back to POSK!) **/
function swapIn(Img)
{
	if ( !Img )
	{
		return;
	}
	if ( Img.src.substr(Img.src.length - 6) == '_a.gif' )
	{
		return;
	}
	overImgSrc 	= Img.src.substr(0, (Img.src.length - 6) ) + '_o.gif';
	Img.src		= overImgSrc;
}

function swapOut(Img)
{
	if ( !Img )
	{
		return;
	}
	if ( Img.src.substr(Img.src.length - 6) == '_a.gif' )
	{
		return;
	}
	outImgSrc 	= Img.src.substr(0, (Img.src.length - 6) ) + '_n.gif';
	Img.src		= outImgSrc;
}

function setActive(imgId)
{
	$('#feSn1').attr('src', '/img/navigation/snp_raeume_' + ( ( imgId == 'feSn1' ) ? 'a' : 'n' ) + '.gif');
	$('#feSn2').attr('src', '/img/navigation/snp_tischschmuck_' + ( ( imgId == 'feSn2' ) ? 'a' : 'n' ) + '.gif');
	$('#feSn3').attr('src', '/img/navigation/snp_gefaessfuellungen_' + ( ( imgId == 'feSn3' ) ? 'a' : 'n' ) + '.gif');
	$('#feSn4').attr('src', '/img/navigation/snp_brautstraeusse_' + ( ( imgId == 'feSn4' ) ? 'a' : 'n' ) + '.gif');
}

/* private functions: */
function setBackButton(page)
{
	//-- set left navi block
	if ( currentImgNo <= 1 )
	{
		$("#cNaviLeft").html('<a href="#" onclick="flipContent();"><img src="/img/navigation/np_text_n.gif" alt="' + page + '" id="npText" /></a><img src="/img/navigation/np_empty_arrow.gif" alt="" id="npPrev" />');
	}
	else
	{
		//alert('show');
		//-- take care that previous button returns, if it was removed
		$("#cNaviLeft").html('<a href="#" onclick="flipContent();"><img src="/img/navigation/np_text_n.gif" alt="' + page + '" id="npText" /></a><a href="#" onclick="prevImg(\'' + page + '\');"><img src="/img/navigation/np_left_n.gif" alt="zurück" id="npPrev" /></a>');
	}
}

function setNextButton(page, lastImgNo)
{
	//-- remove next button on end
	if ( currentImgNo >= lastImgNo )
	{
		$("#cNaviRight").html('<img src="/img/navigation/np_empty_arrow.gif" alt="" id="npPrev" />');
	}
	else
	{
		$("#cNaviRight").html('<a href="#" onclick="nextImg(\'' + page + '\');"><img src="/img/navigation/np_right_n.gif" alt="weiter" id="npNext" /></a>');
	}
}

function setCategoryActive()
{
	if ( currentImgNo >= 1 && currentImgNo < 14 )
	{
 		setActive('feSn1');
	}	
	else if ( currentImgNo >= 14 && currentImgNo < 22 )
	{
 		setActive('feSn2');
	}	
	else if ( currentImgNo >= 22 && currentImgNo < 32 )
	{
 		setActive('feSn3');
	}	
	else if ( currentImgNo >= 32 )
	{
 		setActive('feSn4');
	}	
}


