// JavaScript Document

//////////
///// Array for Casestudies browsing
//////////
browseCasestudies.arr_filenames = new Array('casestudie_Trumpf_iLED.html',
                                            'casestudie_ResMed.html',
                                            'casestudie_Verla.html',
                                            'casestudie_ProLiant_G6_Launch.html',
											'casestudie_HP_TAW_eNewsletter.html',
											'casestudie_BT_cebit_2007.html',
											'casestudie_HP_E-Learning.html',
											'casestudie_HP_SoHo.html',
											'casestudie_Channel_based_Analytics.html',
											'casestudie_Geo_Analysis.html',
											'casestudie_HP_Welcome-Kit.html',
											'casestudie_HP_Transformer.html',
											'casestudie_HP_Workstation_Toolkit.html',
											'casestudie_Linde.html',
											'casestudie_HP_MS_CrossSell.html',
											'casestudie_Symantec_PartnerNews.html',
											'casestudie_Symantec_Sales_Tools.html');


function moveOverview(str_direction, int_numberOfLines)
{   
	document.getElementById('btUp_dark').style.visibility = 'hidden';
	document.getElementById('btDown_dark').style.visibility = 'hidden';

	if(moveOverview.move) moveOverview.move.stop();
	if(!moveOverview.currToLine) moveOverview.currToLine = 0;

	if(str_direction == 'up')moveOverview.currToLine --;
	if(str_direction == 'down')moveOverview.currToLine ++;

	if(moveOverview.currToLine-1 < 0)document.getElementById('btUp_dark').style.visibility = 'visible';
	if(moveOverview.currToLine < 0)moveOverview.currToLine = 0;
	if(moveOverview.currToLine > int_numberOfLines-3)document.getElementById('btDown_dark').style.visibility = 'visible';
	if(moveOverview.currToLine > int_numberOfLines-2)moveOverview.currToLine = int_numberOfLines-2;
	
	var obj_pos = Spry.Effect.getPosition(document.getElementById('overview'));
	var int_newPosY = -188 * moveOverview.currToLine;
	var effectDuration = Math.abs(int_newPosY - obj_pos.y) * 2;
	Spry.Effect.makePositioned(document.getElementById('overview'));
	moveOverview.move = new Spry.Effect.Move('overview', {x:0 , y:obj_pos.y , units: 'px'}, {x:0 , y: int_newPosY, units: 'px'}, {duration: effectDuration, toggle: false});
	moveOverview.move.start();
}

function showImage(obj_thisElement)
{
	if(showImage.lastImgToShowId){
		document.getElementById('img_' + showImage.lastImgToShowId).style.visibility = 'hidden';
		showImage.lastObjThisElement.src = 'img/bt_' + showImage.lastImgToShowId + '.gif';
	}
	
	var int_imgToShowId = obj_thisElement.id.replace(/bt_img_/, '');
	document.getElementById('img_' + int_imgToShowId).style.visibility = 'visible';
	obj_thisElement.src = 'img/bt_' + int_imgToShowId + '_unclickable.gif';
	
	showImage.lastObjThisElement = obj_thisElement;
	showImage.lastImgToShowId = int_imgToShowId;
}

function showDetails(str_action)
{
	if(!showDetails.move){
		Spry.Effect.makePositioned(document.getElementById('detailCont'));
		showDetails.move = new Spry.Effect.Move('detailCont', {x:0 , y:579 , units: 'px'}, {x:0 , y: 294, units: 'px'}, {duration: 500, toggle: true, transition:Spry.sinusoidalTransition});
		showDetails.barOpacity = new Spry.Effect.Opacity('controlBar', 1, 0, {setup: swapBtCloseZindex, finish: swapBtCloseZindex, duration: 500, toggle: true, transition:Spry.sinusoidalTransition});
	}
	if(!showDetails.isOpen && str_action == 'open'){
		showDetails.barOpacity.start();
		showDetails.move.start();
		showDetails.isOpen = true;
	} else if(showDetails.isOpen && str_action == 'close'){
		showDetails.isOpen = false;
		showDetails.barOpacity.start();
		showDetails.move.start();
	}

}
function swapBtCloseZindex(){
	if(showDetails.isOpen){
		document.getElementById('bt_close').style.zIndex = 3;
		document.getElementById('detailCopy').style.overflow = 'auto';
	}else{
		document.getElementById('bt_close').style.zIndex = 1;
		document.getElementById('detailCopy').style.overflow = 'hidden';
	}
}

function browseCasestudies(str_action){
	var arr_splitUrl = window.location.pathname.split('/');
	var str_currFileName = arr_splitUrl[arr_splitUrl.length-1];
	
	for(i in browseCasestudies.arr_filenames)
	{
		if(str_currFileName == browseCasestudies.arr_filenames[i]) var int_keyInFileArray = Number(i);
	}

	if(str_action == 'back' && int_keyInFileArray - 1 >= 0)window.location.href = browseCasestudies.arr_filenames[int_keyInFileArray - 1];
	if(str_action == 'forward' && int_keyInFileArray + 1 < browseCasestudies.arr_filenames.length)window.location.href = browseCasestudies.arr_filenames[int_keyInFileArray + 1];

	if(str_action == 'init' && int_keyInFileArray - 1 < 0)document.getElementById('bt_back').src = 'img/bt_back_dark.gif';
	if(str_action == 'init' && int_keyInFileArray + 1 >= browseCasestudies.arr_filenames.length)document.getElementById('bt_forward').src = 'img/bt_forward_dark.gif';
	
}



