var minotJs = {
	curPage: null,
	alreadyLoaded: false,
	initPause: 150
};

var indexPage = {
	ready: function() { $('#lady').css('display', 'none'); },
	load: function() { setTimeout("$('#lady').fadeIn('slow')", minotJs.initPause);  }
}

var evltPage = {
	ready: function() { 
			$('#lady img:not(:last)').css('opacity', '.65');
			$('#lady_image').css('display', 'none');
			multipageCnt.init();
	},
	load: function() {
			setTimeout("$('#lady_image').fadeIn('slow')", minotJs.initPause);
	}
}

var sclerotherapyPage = {
	ready: function() {
			$('#lady_image').css('display', 'none');
			multipageCnt.init();
		},
	load: function() { 
			setTimeout("$('#lady_image').fadeIn('slow')", minotJs.initPause);
	}
}

var contactusPage = {
	ready: function() {
			$('#lady_image').css('display', 'none');
			multipageCnt.init();

			$('#map').width($('#map_box').width() + 5);
			$('#map').height($('#map_box').height() + 6);

	       if (GBrowserIsCompatible()) {
        		var map = new GMap2(document.getElementById("map"));
		        map.setCenter(new GLatLng(48.2115, -101.3167 ), 15);
				var point = new GLatLng(48.2115, -101.3167 );
				map.addOverlay(new GMarker(point));
		   }
			
		},
	load: function() { setTimeout("$('#lady_image').fadeIn('slow')", minotJs.initPause); }
}

var multipageCnt = {
	pages: null,
	index: 0,
	prevPage: null,
	curPage: null,
	nextPage: null,
	changeTime: 900,
	easing: 'swing',
	borderEasing: 'swing',
	init: function() {
		this.pages = $('.page, .page_hide');


// trying to get animation on enter!
/*		this.index = -1;
		this.curPage = this.pages[this.pages.length - 1];
		this.nextPage = this.pages[0];
		this.nextClick();*/
		
		this.assignPages();


		// maybe...
/*		$(this.curPage).css('right', $(this.curPage).width() * -1);
		this.animateBorders($(this.curPage));
		$(this.curPage).animate({right:0}, function () {
													  $(this).css('right', '');
													  });*/


		this.showHideButtons();
		
		$('#next_button').click(function() { multipageCnt.nextClick(); return false; });
		$('#back_button').click(function() { multipageCnt.backClick(); return false; });
		
	},
	nextClick: function() {

		$(this.nextPage).removeClass('page_hide').addClass('page');
		this.animateBorders(this.nextPage);		
		$(this.curPage).removeClass('page').addClass('page_hide');

		$(this.nextPage).css('right', ($(this.nextPage).width() * -1) - 70);
		$(this.nextPage).animate({right:0}, 
								 {complete: function () { $(this).css('right', ''); },
								  easing: this.easing,
								  duration: this.changeTime});
		
		this.index++;
		this.assignPages();
		this.showHideButtons();
	},
	backClick: function() {
		$(this.prevPage).removeClass('page_hide').addClass('page');
		this.animateBorders(this.prevPage);
		$(this.curPage).removeClass('page').addClass('page_hide');

		$(this.prevPage).css('right', ($(this.prevPage).width() * -1) - 70);
		$(this.prevPage).animate({right:0}, 
								 {complete: function() { $(this).css('right', ''); },
								  easing: this.easing,
								  duration: this.changeTime });


		this.index--;
		this.assignPages();
		this.showHideButtons();
	},
	
	assignPages: function() {
		var curIndex = this.index;
		var prevIndex = curIndex - 1;
		var nextIndex = curIndex + 1;
		if(prevIndex < 0) { prevIndex = undefined; }
		if(nextIndex > this.pages.length - 1) { nextIndex = undefined; }
		
		this.curPage = this.pages[curIndex];
		
		if(prevIndex == undefined) { this.prevPage = null; }
		else { this.prevPage = this.pages[prevIndex]; }
		
		if(nextIndex == undefined) { this.nextPage = null; }
		else { this.nextPage = this.pages[nextIndex]; }
	},
	
	showHideButtons: function() {
		if(this.prevPage == null) { $('#back_button').css('display', 'none'); }
		else { $('#back_button').css('display', 'block'); }
		
		if(this.nextPage == null) { $('#next_button').css('display', 'none');  }
		else { $('#next_button').css('display', 'block'); }
	},
	
	animateBorders: function(newPage) {
		var prefix = null;
		var heightDiff = $(newPage).height() - $(this.curPage).height();

		if(heightDiff < 0) prefix = '-=';
		else prefix = '+=';
		
				
		heightDiff = Math.abs(heightDiff);


		$('#content_border').animate({height: prefix + heightDiff},
									 {easing: this.borderEasing,
									  duration: this.changeTime});
		$('#big_square').animate({height: prefix + heightDiff},
								 {easing: this.borderEasing,
								  duration: this.changeTime});
	}
}

// first we color the navigation, then we call functions specific to each page
$(function() {
		   
		   		var curLocation = $(document).attr('location') + "";
				curLocation = curLocation.substring(curLocation.lastIndexOf('/') + 1, curLocation.length);
				if(curLocation == '') curLocation = 'index.html';
				
				minotJs.curPage = curLocation;
				
				var links =  $('#nav a');
				$(links).each(function(i) { 
									   	if($(this).attr('href') == curLocation)
										{
											$(this).css('color', '#5d9fcf');
										}
									   
									   });


				// hide circle div's while images load
				$('.rounded_box').each(function() { $(this).css('visibility', 'hidden');	});
	
				if(minotJs.curPage == 'index.html')
					indexPage.ready();
				else if(minotJs.curPage == 'evlt.html')
					evltPage.ready();
				else if(minotJs.curPage == 'sclerotherapy.html')
					sclerotherapyPage.ready();
				else if(minotJs.curPage == 'contactus.html')
					contactusPage.ready();
				
				if(minotJs.alreadyLoaded == true)
					windowOnLoad();  // force a call, for IE only i think
		   });

window.onload = windowOnLoad;

function windowOnLoad() {

				$('.rounded_box').each(function() { $(this).css('visibility', 'visible'); });
				if(minotJs.curPage == 'index.html')
					indexPage.load();
				else if(minotJs.curPage == 'evlt.html')
					evltPage.load();
				else if(minotJs.curPage == 'sclerotherapy.html')
					sclerotherapyPage.load();
				else if(minotJs.curPage == 'contactus.html')
					contactusPage.load();					

				minotJs.alreadyLoaded = true;
		   };
