$(document).ready(function(){
	//
	// APPLICATION
	//-------------------------------------------------------------------------------------\
	// Home v0.1
	//
	//=======================================================================================================\
	//
	// Main
	//
	function application(){
		//
		var app = this;
		//
		//---------------------------------------------------------------\
		//
		// APP ELEMENTS
		//
		//---------------------------------------------------------------\
		//
		// Elements
		//
		app.photoStage = $('ul.imageList');
		app.photos = $('li', app.photoStage);
		app.currentPhoto = 0;
		app.totalPhotos = app.photos.length;
		app.autoInterupt = false;
		//
		//--------------------------\
		//
		// Constants
		//
		//pho.switchSpeed = 5;
		//pho.fadeSpeed = 500; // sec
		//
		//---------------------------------------------------------------\
		//
		// APP METHODS
		//
		//---------------------------------------------------------------\
		//
		// Intialize
		//
		app.initialize = function(){
			//
			// prep stage
			app.photos.hide();
			app.currentPhoto = Math.floor(Math.random()*app.totalPhotos);
			//$(app.photos[app.currentPhoto]).fadeIn(app.fadeSpeed);
			app.switchPhoto();
			window.setInterval(function(){app.switchPhoto();}, (app.switchSpeed));
			//console.log('Start At Image = '+app.currentPhoto);
			//
			$('.explorerFeatures a.next').click(function(){
				//
				//app.nextPhoto();
				app.prevPhoto();
				//
			});
			$('.explorerFeatures a.prev').click(function(){
				//
				//app.prevPhoto();
				app.nextPhoto();
				//
			});
			$('.intro a').click(function(){
				//
				popup.openPopup('aboutcopy');
				//
			});
			$('ul.explorerNav li.about a').click(function(){
				//
				popup.openPopup('aboutcopy');
				//
			});
			$('.popup a.close').click(function(){
				//
				popup.closePopup();
				//
			});
			//
			$('div.explorerSummary').click(function(){
				//
				window.location = $('a', $(this)).attr('href');
				//
			});
			//
			$('.subMenu').mouseenter(function(){
				//
				$(this).removeClass('open closed').addClass('open');
				//
			});
			//
			$('.subMenu').mouseleave(function(){
				//
				$(this).removeClass('open closed').addClass('closed');
				//
			});
			//
			$('a.warisnav').click(function(){
				//
				popup.openPopup('waris');
				//
			});
			//
			$('.explorers li.stories a').mouseover(function(){
				//
				$('.explorers li.andrea a').removeClass('on off').addClass('off');
				$('.explorers li.waris a').removeClass('on off').addClass('off');
				$('.explorers li.greg a').removeClass('on off').addClass('off');
				$(this).removeClass('on off').addClass('on');
				app.gotoPhoto(3);
				//
			});
			//
			$('.explorers li.andrea a').mouseover(function(){
				//
				$('.explorers li.stories a').removeClass('on off').addClass('off');
				$('.explorers li.waris a').removeClass('on off').addClass('off');
				$('.explorers li.greg a').removeClass('on off').addClass('off');
				$(this).removeClass('on off').addClass('on');
				app.gotoPhoto(2);
				//
			});
			//
			$('.explorers li.greg a').mouseover(function(){
				//
				$('.explorers li.stories a').removeClass('on off').addClass('off');
				$('.explorers li.waris a').removeClass('on off').addClass('off');
				$('.explorers li.andrea a').removeClass('on off').addClass('off');
				$(this).removeClass('on off').addClass('on');
				app.gotoPhoto(1);
				//
			});
			//
			$('.explorers li.waris a').mouseover(function(){
				//
				$('.explorers li.stories a').removeClass('on off').addClass('off');
				$('.explorers li.andrea a').removeClass('on off').addClass('off');
				$('.explorers li.greg a').removeClass('on off').addClass('off');
				$(this).removeClass('on off').addClass('on');
				app.gotoPhoto(0);
				//
			});
			//
			/*$('.explorers li.andrea a').mouseleave(function(){
				//
				$(this).removeClass('on off').addClass('off');
				//
			});
			//
			$('.explorers li.greg a').mouseleave(function(){
				//
				$(this).removeClass('on off').addClass('off');
				//
			});
			//
			$('.explorers li.waris a').mouseleave(function(){
				//
				$(this).removeClass('on off').addClass('off');
				//
			});*/
			//
		}
		//
		//---------------------------------------------------------------\
		//
		// Switch Photo
		//
		app.switchPhoto = function(){
			//
			//console.log('app.switchPhoto : app.currentPhoto = '+app.currentPhoto);
			//
			if(!app.autoInterupt){
				app.prevPhoto('auto');
			}
			//
		}
		//
		//---------------------------------------------------------------\
		//
		// Next Photo
		//
		app.nextPhoto = function(moveType){
			//
			//console.log('app.nextPhoto');
			//
			if(app.currentPhoto < (app.photos.length-1)){
				// move to next photo
				$(app.photos[app.currentPhoto]).fadeOut(app.fadeSpeed);
				$(app.photos[app.currentPhoto+1]).fadeIn(app.fadeSpeed);
				app.currentPhoto++;
				//
			}else{
				// move to first photo
				$(app.photos[app.currentPhoto]).fadeOut(app.fadeSpeed);
				$(app.photos[0]).fadeIn(app.fadeSpeed);
				app.currentPhoto = 0;
				//
			}
			//
			app.highlightExplorer();
			//
			if(moveType != 'auto'){
				app.autoInterupt = true;
			}
			//
		}
		//
		//---------------------------------------------------------------\
		//
		// Prev Photo
		//
		app.prevPhoto = function(){
			//
			//console.log('app.prevPhoto');			
			//
			if(app.currentPhoto > 0){
				// move to prev photo
				$(app.photos[app.currentPhoto]).fadeOut(app.fadeSpeed);
				$(app.photos[app.currentPhoto-1]).fadeIn(app.fadeSpeed);
				app.currentPhoto--;
			}else{
				// move to last photo
				$(app.photos[app.currentPhoto]).fadeOut(app.fadeSpeed);
				$(app.photos[app.photos.length-1]).fadeIn(app.fadeSpeed);
				app.currentPhoto = app.photos.length-1;
			}
			//
			app.highlightExplorer();
			//
		}
		//
		//---------------------------------------------------------------\
		//
		// Go To Photo
		//
		app.gotoPhoto = function(photoId){
			//
			// move to photo
			if(photoId != app.currentPhoto){
				app.autoInterupt = true;
				$(app.photos[app.currentPhoto]).fadeOut(app.fadeSpeed);
				$(app.photos[photoId]).fadeIn(app.fadeSpeed);
				app.currentPhoto = photoId;
			}
			//
		}
		//
		//---------------------------------------------------------------\
		//
		// Highlight Explorer
		//
		app.highlightExplorer = function(){
			//
			// move to photo
			if(app.currentPhoto == 0){
				$('.explorers li.stories a').removeClass('on off').addClass('off');
				$('.explorers li.andrea a').removeClass('on off').addClass('off');
				$('.explorers li.greg a').removeClass('on off').addClass('off');
				$('.explorers li.waris a').removeClass('on off').addClass('on');
			}else if(app.currentPhoto == 1){
				$('.explorers li.stories a').removeClass('on off').addClass('off');
				$('.explorers li.waris a').removeClass('on off').addClass('off');
				$('.explorers li.andrea a').removeClass('on off').addClass('off');
				$('.explorers li.greg a').removeClass('on off').addClass('on');
			}else if(app.currentPhoto == 2){
				$('.explorers li.stories a').removeClass('on off').addClass('off');
				$('.explorers li.waris a').removeClass('on off').addClass('off');
				$('.explorers li.greg a').removeClass('on off').addClass('off');
				$('.explorers li.andrea a').removeClass('on off').addClass('on');
			}else if(app.currentPhoto == 3){
				$('.explorers li.waris a').removeClass('on off').addClass('off');
				$('.explorers li.greg a').removeClass('on off').addClass('off');
				$('.explorers li.andrea a').removeClass('on off').addClass('off');
				$('.explorers li.stories a').removeClass('on off').addClass('on');
			}
			//
		}
		//
	}
	//
	// Initialize
	app = new application();
	app.switchSpeed = 8000;
	app.fadeSpeed = 500;
	app.initialize();
	//
});
