// ADD HOVER CLASS
function navHover(){
	$("#navigation li").hover(
		function (){ 
			$(this).addClass("selected");
			$(this).addClass("over");
			$(this).children("ul")
			.css({
				'opacity': 0,
				'width': 0
			})
			.animate({
				'opacity': 1,
				'width': '160px'
			}, 400, 
			function(){
				if($.browser.msie){
					this.style.removeAttribute('filter');
				}
			});
		},
		function (){
			$(this).removeClass("selected");
			$(this).removeClass("over");
			$(this).children("ul")
			.css({
				'opacity': 1
			});
		}
	);
}

// STINGS AND BITES
function stingsAndBites(){
	$("#stings li a")
	.css({'opacity': 0.2, 'backgroundColor': '#ffffff'})
	.hover(
		function (){
			$(this).animate({'opacity': 0}, 400);
		},
		function (){
			$(this).animate({'opacity': 0.2}, 400);
		}
	);
	$(".bite a")
	.css({'opacity': 0.8})
	.hover(
		function (){
			$(this).animate({'opacity': 1}, 400);
		},
		function (){
			$(this).animate({'opacity': 0.8}, 400);
		}
	);
	$("#stings li a, .bite a, .tooltip").tooltip({ 
		track: true, 
		delay: 0, 
		showURL: false, 
		showBody: " - ", 
		fade: 250
	});
}

// FEATURE ROTATION
function featureFader(){
	$("#feature").cycle({
		fx: 'crossfade',
		speed: 1500,
		timeout: 4000
	});
}

function backgroundHeight(){

	if($('#map_canvas').is('*')){

	}else{
	var windowHeight = $(window).height();

	var getContHeight = $('#main').height();
	var getContPadding = $('#main').css('padding-top');

	var contHeight = parseInt(getContHeight);
	var contPadding = parseInt(getContPadding);

	var contBoxSize = (contHeight + contPadding)
	if(contBoxSize > windowHeight){
    		$('#background').css({'height': contBoxSize + 'px'});
	}else{
		$('#background').css({'height': windowHeight + 'px'});
	}
	}
}

// custom CROSSFADE for cycle on 'featureFader' function
$.fn.cycle.transitions.crossfade = function($cont, $slides, opts) {
	var d = opts.direction || 'left';
	var w = $cont.css('overflow','hidden').width();
	var h = $cont.height();
	opts.before.push(function(curr, next, opts) {
		opts.cssBefore.display = 'block';
		opts.animOut.left = 0;
		opts.animOut.top = 0;
	opts.animOut.opacity = 0;
		$(curr).css('zIndex',2);
		$(next).css('zIndex',1);
	});    
	opts.onAddSlide = function($s) { $s.hide(); };
	if (!opts.animIn)  opts.animIn = { left: 0, top: 0 };
	opts.cssBefore = opts.cssBefore || {};
	opts.cssBefore.top = 0;
	opts.cssBefore.left = 0;
	opts.cssBefore.opacity = 1;
	opts.cssAfter = opts.cssAfter || {};
	opts.cssAfter.zIndex = 1;
	opts.cssAfter.display = 'none';
};

// INITIALIZE FUNCTIONS
$(document).ready(
	function() { 
		navHover();
		stingsAndBites();
		backgroundHeight();
		$("#feature").css({'visibility': 'hidden'});
	}
);
    
$(window).resize(
	function() {
		backgroundHeight();
	}
);

$(window).load(
	function() {
		$("#feature").css({'visibility': 'visible', 'opacity': 0.1}).animate({'opacity': 1}, 500);
		//alert("window loaded");
		featureFader();
	}
);


