//set navbar colors
//var navbarColor = '#52f7fa';
//var growtabColor = '#52fa77';
//var growrightColor = '#fa5291';
//var growleftColor = '#fa5291';
var navbarColor = '#222';
var growtabColor = '#3366ff';
var growrightColor = '#ff3366';
var growleftColor = '#ff3366';
//var navbarBorderTop = 'solid 3px #333';
//var growtabBorderTop = 'solid 3px #5983ff';
//var growrightBorderTop = 'solid 3px #ff5983';
//var growleftBorderTop = 'solid 3px #ff5983';
//var blueBorderTop = 'solid 3px #3366ff';

//ORIENTATION
var photos = '<a href="./misc.html">Miscellaneous</a><a href="./arizona.html">Arizona</a><a href="./hongkong.html">Hong Kong</a><a href="./nz.html">New Zealand</a>';

$(document).ready(function() {
	
	$('#navbar').css('background-color', navbarColor);
	//$('#navbar > .navtab').css('border-top', navbarBorderTop);
	$('.growtab').css('background-color', growtabColor);
	//$('.growtab').css('border-top', growtabBorderTop);
	$('.growright').css('background-color', growleftColor);
	//$('.growright').css('border-top', growrightBorderTop);
	$('.growleft').css('background-color', growleftColor);
	//$('.growleft').css('border-top', growleftBorderTop);
	
	//dynamically set growright/left width based on amount of navtabs within
	$('#navbar > .navtab > .growtab > .navtab').children('div').each(function(i) {
		this.id = 'grow'+i; //give growleft/right an id so it can have a width associated with it
		$(this).children('div').children('.navtab').each(function(j) {
			count = j; //find out how many navtabs are within
		});
		count++; //increment because .each above starts at zero
		$(this).css('width', count * 110+'px'); //multiply count by navtab width set in CSS (.growright .navtab)
		document.getElementById(this.id).w = $(this).css('width'); //save width value in the growtab object
		$(this).css('width', '0px'); //the growtab needs to start at 0px
	});
	
	$('#navbar > .navtab').hover(
		function() {$(this).css('background-color', growtabColor);},
		function() {$(this).css('background-color', navbarColor);}
	);
	
	$('#navbar > .navtab').hoverIntent({ //make growtabs rise and fall
		sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
		interval: 100, // number = milliseconds for onMouseOver polling interval    
		over: expandV, // function = onMouseOver callback (REQUIRED)    
		timeout: 500, // number = milliseconds delay before onMouseOut    
		out: contractV // function = onMouseOut callback (REQUIRED)  
	});
	
	$('#navbar > .navtab > .growtab > .navtab').hover(
		function() {$(this).css('background-color', growleftColor);},
		function() {$(this).css('background-color', growtabColor);}
	);
	
	$('#navbar > .navtab > .growtab > .navtab').hoverIntent({ //make second level growtabs expand and contract
		sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
		interval: 100, // number = milliseconds for onMouseOver polling interval    
		over: expandH, // function = onMouseOver callback (REQUIRED)    
		timeout: 500, // number = milliseconds delay before onMouseOut    
		out: contractH // function = onMouseOut callback (REQUIRED)    
	});
	/*
	//hover color for last level of menu
	$('#navbar > .navtab > .growtab > .navtab > .growleft > div > .navtab').hover(
		function() {$(this).css('background-color', '#47e313');},
		function() {$(this).css('background-color', growrightColor);}
	);
	*/
});

expandV = function() {
	$(this).children('.growtab').slideDown(500, 'easeInOutExpo');
}

contractV = function() {
	$(this).children('.growtab').slideUp(500, 'easeInOutExpo');
}

expandH = function() {
	if ($(this).children('div').html() == null) {return;}
	
	id = $(this).children('div').attr('id');
	w = document.getElementById(id).w;
	$(this).children('div').animate({width: w}, 300, 'easeInOutExpo');
}

contractH = function() {
	if ($(this).children('div').html() == null) {return;}
	
	$(this).children('div').animate({width: '0px'}, 300, 'easeInOutExpo', function() {
		$(this).hide();
	});
}

var c = 0;
var STOP = false;
function cycleImgs(init, sectionImages) {
	if (STOP == true) {return;}
	if (init == 1) {
		sectionImages = [];
		$('.sectionImg').each(function() {
			sectionImages.push(this);
		});
		masterImage = $(sectionImages[Math.round(Math.random()*(sectionImages.length-1))]).attr('src');
		masterImage = './img/big' + masterImage.split('./img')[1];
		$('#sectionImgContainer').css('background-image', 'url('+masterImage+')');
		cycleImgs(0, sectionImages);
	} else {
		q = Math.round(Math.random()*(sectionImages.length-1));
		p = Math.round(Math.random()*(sectionImages.length-1));
		if (p == q) {
			if (p == 0) {
				p = x
			} else {
				p = 0;
			}
		}
		$(sectionImages[q]).animate({"width": "-=100","height": "100"}, 990, function() {
			if (STOP == true) {return;}
			$('.sectionImg:eq('+p+')').after(sectionImages[q]);
			$(sectionImages[q]).animate({"width": "+=100","height": "100"}, 640);
			floatSwap(sectionImages[q]);
			cycleImgs(0, sectionImages);
		});
	}
}

function floatSwap(object) {
	if ($(object).css('float') == 'left') {
		$(object).css('float', 'right');
	} else {
		$(object).css('float', 'left');
	}
}

function initOrientation() {
	/*section = $('.orientation').attr('id');
	$('.orientation > a').click(function() {
		url = $(this).attr('href')+'?orient&ajax';
		$('#'+section+'Content').fadeOut(300, function() {
			$('#'+section+'Content').remove();
			$.get(url, function(data) {
				$('.orientation').after(data);
			});
		});
		
		return false;
	});*/
}

function initSlideShow() {
	//setTimeout('thumbClick();', 50);
	//setTimeout("h=$('.thumbs').height();$('.thumbs').css('height', '65px');", 50);
	thumbClick();
	
	h = $('.thumbs').height();
	$('.thumbs').css('height', '65px');
	thumbsHover();
}

function thumbClick(section) {
	section = $('.orientation').attr('id');
	$('.thumbs img').each(function() {
		$(this).click(function() {
			var src = $(this).attr('src');
			src = './'+section+'/'+src.split('/')[src.split('/').length-3] +'/'+ src.split('/')[src.split('/').length-1];
			$('.imgSpace').fadeOut(100, function() {
				$(this).empty().append('<center><img src="'+src+'"/></center>');
				$('.imgSpace').fadeIn(100);
			});
		});
	});
}

function thumbsHover() {
	if (h <= 65) {return;} //if the actual size of the thumbs div is smaller than the compressed size of 65px then don't do any hover crap
	$('.thumbs').hoverIntent({
		sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
		interval: 60, // number = milliseconds for onMouseOver polling interval    
		over: thumbsOver, // function = onMouseOver callback (REQUIRED)    
		timeout: 500, // number = milliseconds delay before onMouseOut    
		out: thumbsOut // function = onMouseOut callback (REQUIRED)
	});
}

thumbsOver = function() {
	$(this).animate({height: h+'px', opacity: '0.9'}, 200, 'easeInOutExpo');
}

thumbsOut = function() {
	$(this).animate({height: '65px', opacity: '1.0'}, 200, 'easeInOutExpo');
}
