// JavaScript Document
var left;

$(function() {
	
	navInit();
	
	
	if($.browser.msie) {
		ieCaretAnimationsInit();
	} else {
		caretAnimationsInit();
	}
	
	tooltips_init();
	footerGMaps();
	
});

function navInit() {
	
	varleft = getLeft();
	//console.log(varleft);
	navActivate(varleft);
}

function getLeft(){
		
	var currentid=$('.current-menu-item').attr("id");
	//console.log('currentid: ' + currentid);
	
	switch(currentid){
		case 'menu-item-359':
			return 0;
			break;
		
		case 'menu-item-358':
			$('#indicator_bar').css('left','70px').show();
			return 67;
			break;
		
		case 'menu-item-357':
			$('#indicator_bar').css('left','145px').show();
			return 142;
			break;
			
		case 'menu-item-356':
			$('#indicator_bar').css('left','227px').show();
			return 226;
			break;
			
		case 'menu-item-355':
			$('#indicator_bar').css('left','321px').show();
			return 320;
			break;
			
		case 'menu-item-354':
			$('#indicator_bar').css('left','422px').show();
			return 419;
			break;
			
		case 'menu-item-352':
			$('#indicator_bar').css('left','505px').show();
			return 503;
			break;
			
		case 'menu-item-353':
			$('#indicator_bar').css('left','575px').show();
			return 575;
			break;
			
		case 'menu-item-351':
			$('#indicator_bar').css('left','644px').show();
			return 643;
			break;
			
		default:
			$('#indicator_bar').css('left','-646px').hide();
			return -646;
			break;
		}
		
} // End of getLeft()

function navActivate(left) {
	
	$(".menu-item-359").hover(
		function() {
			$('#indicator_bar').stop().show().animate({left: '0'}, 750,'easeOutBack', function() {});
		}, 
	
		function () {
			if(left == -646){
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {}).hide();
				
			} else {
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {});
			}
		}
	);
	
	$(".menu-item-358").hover(				  
		function () {
			$('#indicator_bar').stop().show().animate({left: '70'}, 750,'easeOutBack',  function() {});
		},
		
		function () {
		
			if(left == -646){
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {}).hide();
				
			} else {
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {});
			}
		}
	);
	
	$(".menu-item-357").hover(
		function () {
			$('#indicator_bar').stop().show().animate({left: '145'}, 750,'easeOutBack', function() {});
		}, 
		
		function () {
			if(left == -646){
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {}).hide();
				
			} else {
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {});
			}
		}
	);	

	$(".menu-item-356").hover(
		function () {
			$('#indicator_bar').stop().show().animate({left: '227'}, 750,'easeOutBack', function() {});
		},
		
		function () {
			if(left == -646){
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {}).hide();
				
			} else {
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {});
			}
		}
	);	

	$(".menu-item-355").hover(
		function () {
			$('#indicator_bar').stop().show().animate({left: '321'}, 750,'easeOutBack', function() {});
		}, 
		
		function () {
			if(left == -646){
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {}).hide();
				
			} else {
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {});  
			}
		}
	);	

	$(".menu-item-354").hover(
		function () {
			$('#indicator_bar').stop().show().animate({left: '422'}, 750,'easeOutBack', function() {});
		}, 
		
		function () {
			if(left == -646){
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {}).hide();
				
			} else {
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {});  
			}
		}
	);
	
	$(".menu-item-352").hover(
		function () {
			$('#indicator_bar').stop().show().animate({left: '505'}, 750,'easeOutBack', function() {});
		}, 
		
		function () {
			if(left == -646){
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {}).hide();
				
			} else {
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {});
			}
		}
	);	

	$(".menu-item-353").hover(				  
		function () {
			$('#indicator_bar').stop().show().animate({left: '575'}, 750,'easeOutBack', function() {});
		}, 
		
		function () {
			if(left == -646){
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {}).hide();
			} else {
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {});
			}
		}
	);	

	$(".menu-item-351").hover(			  
		function () {
			$('#indicator_bar').stop().show().animate({left: '644'}, 750,'easeOutBack', function() {});
		}, 
		
		function () {
			if(left == -646){
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {}).hide();
			} else {
				$('#indicator_bar').stop().show().animate({left: left}, 450,'easeOutBack', function() {}); 
			}
		}
	);
	/* --------------------------------- */
	// End Top Menu Navigation Functions // 
	/* --------------------------------- */	
}


function caretAnimationsInit() {
	// Large Inline Caret Animation
	var inlineCarets = $('.inline_caret');
	
	if(inlineCarets) {
		inlineCarets.hover(
			function () {
				var inlineCaret = $(this).find('span.caret');
				inlineCaret.css('opacity', 0);
				inlineCaret.css('left', '0px');
				inlineCaret.animate({left: '10px', opacity: 1}, 350, 'easeOutQuad', function() {});
			}, 
			function () {
				inlineCaret.css('opacity', 1);
				inlineCaret.css('left', '10px');  
			}
		);
	}
	
	// Small Background-Image Caret Animation
	var smallCarets = $('a.right_arrow.small');
	
	if(smallCarets) {
		$(smallCarets).each(function(e) {
			var smallCaret = $(this);
			
			var newBackgroundPosX = smallCaret.width() + parseFloat(smallCaret.css('padding-left')) + parseFloat(smallCaret.css('padding-right')) - 6 - 15;
			var origBackgroundPosX = newBackgroundPosX + 15;
			newBackgroundPosX = newBackgroundPosX + "px";
			origBackgroundPosX =  origBackgroundPosX + "px";
			
			smallCaret.data('origBGPosX', origBackgroundPosX);
			smallCaret.data('newBGPosX', newBackgroundPosX);
			
			//console.log("smallCaret.css('width'): " + smallCaret.css('width') + " smallCaret.width():  " + smallCaret.width() + " smallCaret.css('padding-left'): " + parseFloat(smallCaret.css('padding-left')) + " smallCaret.css('padding-right'): " + parseFloat(smallCaret.css('padding-right')));
			//console.log("Small Caret Link: " + smallCaret + ", " + "Reposition Value: " + newBackgroundPosX + ", " + "Original Position: " + origBackgroundPosX);
		});
		
		if($.browser.msie) {
			blogEntries.not(blogID).css({'display': 'none'});
			displayPost.css({'display': 'block'});
		} else {
			smallCarets.hover(
				function () {
					$(this).css('background-position', $(this).data('newBGPosX') + ' 0px');
					$(this).animate({backgroundPosition: $(this).data('origBGPosX') + ' 0px'}, 200, 'easeOutQuad', function() {});
				}, 
				function () {
					$(this).stop(true, false);
					$(this).css('background-position', $(this).data('origBGPosX') + ' 0px');
					$(this).css('opacity', 1);
				}
			);
		}
	}
	
	// Widget Slider Caret
	
	// Side Navigation Caret
	
	// Orange Button Caret - Left
	var orangeLeftCarets = $('.orange.left');
	
	if(orangeLeftCarets) {
		$(orangeLeftCarets).each(function(e) {
			var buttonLeftBG = $(this);
			
			var newBackgroundPosX = buttonLeftBG.width() + parseFloat(buttonLeftBG.css('padding-left')) + parseFloat(buttonLeftBG.css('padding-right')) - 31;
			var origBackgroundPosX = newBackgroundPosX + 15;
			newBackgroundPosX = newBackgroundPosX + "px";
			origBackgroundPosX =  origBackgroundPosX + "px";
			
			buttonLeftBG.data('origBGPosX', origBackgroundPosX);
			buttonLeftBG.data('newBGPosX', newBackgroundPosX);
		});
	
		orangeLeftCarets.hover(
			function () {
				$(this).css('background-position', $(this).data('newBGPosX') + ' 0px');
				$(this).animate({backgroundPosition: $(this).data('origBGPosX') + ' 0px'}, 350, 'easeOutQuad', function() {});
			}, 
			function () {
				$(this).stop(true, false);
				$(this).css('background-position', $(this).data('origBGPosX') + ' 0px');
				$(this).css('opacity', 1);
			}
		);
	}
	
	// Orange Button Caret - Right
	var orangeRightCarets = $('.orange.right');
	
	if(orangeRightCarets) {
		$(orangeRightCarets).each(function(e) {
			var buttonRightBG = $(this);
			var origBackgroundPosX = 0;
			var newBackgroundPosX = 15;
			
			origBackgroundPosX =  origBackgroundPosX + "px";
			newBackgroundPosX = newBackgroundPosX + "px";
			
			buttonRightBG.data('origBGPosX', origBackgroundPosX);
			buttonRightBG.data('newBGPosX', newBackgroundPosX);
		});
	
		orangeRightCarets.hover(
			function () {
				$(this).css('background-position', $(this).data('newBGPosX') + ' 0px');
				$(this).animate({backgroundPosition: $(this).data('origBGPosX') + ' 0px'}, 350, 'easeOutQuad', function() {});
			}, 
			function () {
				$(this).stop(true, false);
				$(this).css('background-position', $(this).data('origBGPosX') + ' 0px');
				$(this).css('opacity', 1);
			}
		);
	}
}

function smallCaretReInit(elem) {
	
	var caretReInit = $(elem).find('.right_arrow.small');
	
	var newBackgroundPosX = caretReInit.width() + parseFloat(caretReInit.css('padding-left')) + parseFloat(caretReInit.css('padding-right')) - 6 - 15;
	var origBackgroundPosX = newBackgroundPosX + 15;

	newBackgroundPosX = newBackgroundPosX + "px";
	origBackgroundPosX =  origBackgroundPosX + "px";
	
	caretReInit.data('origBGPosX', origBackgroundPosX);
	caretReInit.data('newBGPosX', newBackgroundPosX);
		
	caretReInit.unbind();
	caretReInit.hover(
		function () {
			$(this).css('background-position', $(this).data('newBGPosX') + ' 1px');
			$(this).animate({backgroundPosition: $(this).data('origBGPosX') + ' 1px'}, 200, 'easeOutQuad', function() {});
		}, 
		function () {
			$(this).stop(true, false);
			$(this).css('background-position', $(this).data('origBGPosX') + ' 1px');
			$(this).css('opacity', 1);
		}
	);
}


function columnizerInit() {
	////console.log('inside columnizerInit...');
	var elems = $('div#content').find('.columnize');
	////console.log(elems);
	
	elems.each(function(e) {
		var numColumns = $(this).attr('rel');
		numColumns = parseInt(numColumns);
		
		var holderWidth = $(this).width();
		
		$(this).columnize({columns: numColumns, parentWidth: holderWidth, gutter: 20, lastNeverTallest: true})
	});
}

function ieCaretAnimationsInit() {
	
}

function tooltips_init() {
	var penguinOne = $('span#penguin_1.trigger');
	penguinOne.tooltip({effect: 'slide', position: "top left", offset: [40, 2], slideInSpeed: 400, relative: true});
	
	var penguinTwo = $('span#penguin_2.trigger');
	penguinTwo.tooltip({effect: 'slide', position: "top right", offset: [30, -5], slideInSpeed: 400, relative: true});
	
}

function footerGMaps() {
	$('a#nav_buoy').click(function(e) {
		window.open('http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Integrity+Custom+Web+Development,+6358+Delmar+Blvd.+Suite+444+,+St.+Louis,+MO+63130&ie=UTF8&hq=Integrity+Custom+Web+Development,&hnear=6358+Delmar+Blvd.+Suite+444+,+St.+Louis,+MO+63130&t=h&z=16&iwloc=A');
	});
	
}
