


// ----------------------------------------------------------------------------	
function slideFullPage(direction, gotourl) {
	var width; 
	document.body.setStyle({overflow:'hidden'});

	switch (direction) {
		case 'left':
			width = document.viewport.getWidth();
			break;
		case 'right':
			width = 0 - document.viewport.getWidth();
			break;
	}

	new Effect.Parallel([
		new Effect.Move('img-holder', { sync: true, x: width } ), 
		new Effect.Move('content',	  { sync: true, x: width } )
	], { 
		duration: 1,
		delay:    0,
		afterFinish: function(){
			window.location.href = gotourl;
		}
	});
}


//----------------------------------------------------------------------------	
function initPhotoSwitcher(){
	$('img-wrap2').src = arrImages[0].href;
	$('img-wrap1').src = arrImages[1].href;
}

//switch photos
//----------------------------------------------------------------------------	
function switchPhotos(e)  {
	photoid = photoid >= arrImages.length-1 ? 0 : photoid + 1; 

	//$('debug').update(arrImages[photoid].href);

	$('img-wrap'+imgHidden).setOpacity(0);
	$('img-wrap'+imgHidden).show();
	$('img-wrap'+imgHidden).setStyle({visibility:'visible'});
	new Effect.Parallel([
		new Effect.Opacity('img-wrap'+imgVisible, { sync: true, from: 1, to: 0 }), 
		new Effect.Opacity('img-wrap'+imgHidden, { sync: true, from: 0, to: 1 })
	], { 
		duration: 1,
		delay: 1 ,
		afterFinish: function(){
			$('img-wrap'+imgVisible).hide();
			$('img-wrap'+imgVisible).src=arrImages[photoid].href;
			imgVisible = imgVisible >= 2 ? 1 : imgVisible + 1;
			imgHidden = imgHidden >= 2 ? 1 : imgHidden + 1;
			//arrImages[photoid-1].removeClassName('photos-selected');
			arrImages[photoid].addClassName('photos-selected');
			
		}
	});
}

//----------------------------------------------------------------------------	
function handleClick(e) {
	var mouseX = Event.pointerX(e);
	var mouseY = Event.pointerY(e);
	var width = document.viewport.getWidth();
	
	if (mouseY < 60) { return }
	
	if (mouseX < width/3){
		imageBackClick(e);
	} else if (mouseX > 2*(width/3)) {
		imageNextClick(e);
	}
	
}

//-----------------------------------------------------------------------------
function imageBackClick(e) {
	e.stop();
	var idx = 0;
	var count = 0;
	
	// TODO: optimize
	if (config['bgSlideMode'] == 'sets') {
		slideFullPage('left',$('pervSetLink').href);
		return;
	}	
	
	arrImages.each(function(el, index) {
		if ($('img-wrap1').src == el.href) {
			idx = index;
		}
		count++;
	});
	
	
	if (idx == 0) {
		//idx = count - 1;
		slideFullPage('left',$('pervSetLink').href);
		return;
	} else {
		idx--;

	}	
	
	$('img-wrap1').src = arrImages[idx].href
}

//-----------------------------------------------------------------------------
function imageNextClick(e) {
	e.stop();
	var idx = 0;
	var count = 0;
	
	// TODO: optimize 
	
	if (config['bgSlideMode'] == 'sets') {
		slideFullPage('right',$('nextSetLink').href);
		return;
	}	

	arrImages.each(function(el, index) {
		if ($('img-wrap1').src == el.href) {
			idx = index;
		}
		count++;
	});
	if (idx + 1 == count) {
		//idx = 0;
		slideFullPage('right',$('nextSetLink').href);
		return;
	} else {
		idx++;

	}	
	
	$('img-wrap1').src = arrImages[idx].href
}









