function galleryPrevious(divId) {
	if ($(divId).style.left != '0px' && $(divId).style.left != '') {
		new Effect.Move(divId, { x: 92, y: 0, duration: 0.3, transition: Effect.Transitions.sinoidal });
	}
}  

function galleryNext(divId) {
	if ( (parseInt($(divId).style.left) + parseInt($(divId).getWidth()) >= 915) || ($(divId).style.left == '') && parseInt($(divId).getWidth()) >= 828) {
		new Effect.Move(divId, { x: -92, y: 0, duration: 0.3, transition: Effect.Transitions.sinoidal });
	}
	
}

function switchDivs(toHide, toShow, page) {

	if (page == 'home') {
		setActualHomeBox(toShow);
	}
	if (toHide == '') {
		var objToHide = document.getElementsByClassName('selectedDiv');
		var obj = objToHide[0];
		obj.removeClassName('selectedDiv');
		
		var extPosition = obj.id.lastIndexOf('_link');
		
		if (extPosition > 0) {
			toHide = obj.id.substring(0,extPosition);
			
		}
		
	} else {
		
		if ($(toHide + '_link')) {
			$(toHide + '_link').removeClassName('selectedDiv');
		}
	}
	
	new Effect.Fade($(toHide + '_box'), {duration: 0.5, afterFinish: function(){
																		$(toHide + '_box').addClassName('hiddenDiv');
																		$(toShow + '_box').style.display = 'none';
																		$(toShow + '_box').removeClassName('hiddenDiv');
																		new Effect.Appear($(toShow + '_box'), {duration: 0.5}); 
																	} });
	
	if ($(toHide + '_images') && $(toShow + '_images') && Prototype.Browser.IE){
		new Effect.Fade($(toHide + '_images'), {duration: 0.5, afterFinish: function(){
																					new Effect.Appear($(toShow + '_images'), {duration: 0.5}); 
																				} });
	
	}
	if ($(toShow + '_link')) {
		$(toShow + '_link').addClassName('selectedDiv');
	}
	
}

function saveTrip(formDivId, submitType) {
	$('imagefile').onclick = function(){ return false; };
	$('upload_button').innerHTML = 'UPLOADING...';
	$('submit_type').value = submitType;
	$(formDivId).submit();
}

var homeBoxes = new Array(6);
homeBoxes[0] = "mt_ararat";
homeBoxes[1] = "mt_suphan";
homeBoxes[2] = "mt_nermut";
homeBoxes[3] = "fish_lake_home";
homeBoxes[4] = "mt_kackar";
homeBoxes[5] = "mt_kutiz";

var homeBoxesCounter = 1;
var homeBoxesTimer = 0;

var actualHomeBox = "mt_ararat";
var homeImagesCounter = 0;
var homeImagesTimer = 0;

var homeAraratImages = new Array(5);
homeAraratImages[0] = "mt_ararat.jpg";
homeAraratImages[1] = "mt_ararat2.jpg";
homeAraratImages[2] = "mt_ararat3.jpg";
homeAraratImages[3] = "mt_ararat4.jpg";
homeAraratImages[4] = "mt_ararat5.jpg";

var homeSuphanImages = new Array(4);
homeSuphanImages[0] = "mt_suphan.jpg";
homeSuphanImages[1] = "mt_suphan1.jpg";
homeSuphanImages[2] = "mt_suphan2.jpg";
homeSuphanImages[3] = "mt_suphan3.jpg";

var homeNemrutImages = new Array(5);
homeNemrutImages[0] = "mt_nemrut.jpg";
homeNemrutImages[1] = "mt_nemrut1.jpg";
homeNemrutImages[2] = "mt_nemrut2.jpg";
homeNemrutImages[3] = "mt_nemrut3.jpg";
homeNemrutImages[4] = "mt_nemrut4.jpg";

var homeFishImages = new Array(2);
homeFishImages[0] = "fish_lake_home.jpg";
homeFishImages[1] = "fishlake.jpg";

var homeKackarImages = new Array(2);
homeKackarImages[0] = "mt_kackar.jpg";
homeKackarImages[1] = "mt_kackar3.jpg";

var homeKutizImages = new Array(4);
homeKutizImages[0] = "mt_kutiz.jpg";
homeKutizImages[1] = "mt_kutiz1.jpg";
homeKutizImages[2] = "mt_kutiz2.jpg";
homeKutizImages[3] = "mt_kutiz3.jpg";

function setActualHomeBox(boxName){
	actualHomeBox = boxName;
	homeImagesCounter = 0;
	initHomeImages();
}

function changeHomeImages() {

	var tmpArray = new Array();
	
	switch (actualHomeBox) {
		case 'mt_ararat':
			tmpArray = homeAraratImages;
		break;
		
		case 'mt_suphan':
			tmpArray = homeSuphanImages;
		break;
		
		case 'mt_nermut':
			tmpArray = homeNemrutImages;
		break;
		
		case 'fish_lake_home':
			tmpArray = homeFishImages;
		break;
		
		case 'mt_kackar':
			tmpArray = homeKackarImages;
		break;
		
		case 'mt_kutiz':
			tmpArray = homeKutizImages;
		break;
		
		default:
			tmpArray = homeAraratImages;
	}
	
	var imageDiv = $(actualHomeBox + '_main_image');
	
	new Effect.Fade(imageDiv, {duration: 0.5, afterFinish: function(){
																		imageDiv.style.background = 'url(images/' + tmpArray[homeImagesCounter] + ')';
																		new Effect.Appear(imageDiv, {duration: 0.5}); 
																	} });
	
	//imageDiv.style.background = 'url(images/' + tmpArray[homeImagesCounter] + ')';
	homeImagesCounter++;
	if (homeImagesCounter > (tmpArray.length - 1)) {
		homeImagesCounter = 0;
	}
	clearTimeout(homeImagesTimer);
	homeImagesTimer = setTimeout(
					function(){
						changeHomeImages();
					},
					5000
				);
}

function initHomeImages(){
	clearTimeout(homeImagesTimer);
	homeImagesTimer = setTimeout(
					function(){
						changeHomeImages();
					},
					5000
				);
}

function changeHomeBoxes() {

	switchDivs('', homeBoxes[homeBoxesCounter]);
	homeBoxesCounter++;
	if (homeBoxesCounter > (homeBoxes.length - 1)) {
		homeBoxesCounter = 0;
	}
	clearTimeout(homeBoxesTimer);
	homeBoxesTimer = setTimeout(
					function(){
						changeHomeBoxes();
					},
					5000
				);
}

function initHomeBoxes(){
	homeBoxesTimer = setTimeout(
					function(){
						changeHomeBoxes();
					},
					5000
				);
}

function changeHomeBoxesStop() {
	clearTimeout(homeBoxesTimer);
}

function getBoxFromQS(page) {
	var fullURL = document.URL;
	var qs = '';
	if(fullURL.indexOf('#') > 0){
		qs = fullURL.substring(fullURL.indexOf('#')+1, fullURL.length);
	}
	
	switch (page) {
		case 'home':
			if(qs != '') {
				if ($(qs + '_box')){
					switchDivs('', qs, 'home');
				}
			} else {
				initHomeImages();
			}
		break;
		
		case 'culture':
			if(qs != '') {
				if ($(qs + '_box')){
					switchDivs('', qs, 'culture');
				}
			}
			
		break;
		
	}
}
