jQuery(function($) {
	
	$("#primaryNav li > ul").hoverIntent({
		interval: 150, // milliseconds delay before onMouseOver
		over: function() { $(this).addClass('show'); }, 
		timeout: 500, // milliseconds delay before onMouseOut
		out: function() { $(this).removeClass('show'); }
	});
	
	$('.arrow').click(function() {
		$(this).parent().toggleClass('open').toggleClass('close');
		return false;
	});
 
	$('.arrowText').click(function() {
		$(this).parent().toggleClass('open').toggleClass('close');
		return false;
	});
 	
	$('#heroShots #controls a').bind('click', function() {
		$('#heroShots img').hide();
		$('#heroShots #controls a').removeClass('current');
		$(this).addClass('current');
		
		var id = $(this).attr('id').replace('feature-thumb-','feature-full-');
		$('#'+id).fadeIn('slow');
	});
	
	$(function() {
		if ($('#heroShots #controls a').length > 1)
			setInterval(heroShotAutoForward, 5000);

		function heroShotAutoForward() {
			$current = $('#heroShots #controls a.current');
			$currentParent = $current.parent();
			$('#heroShots img').hide();
			$('#heroShots #controls a').removeClass('current');
			if ($currentParent.prev().length != 0) {
				$a = $currentParent.prev().find('a');
				$a.addClass('current');
				var id = $a.attr('id').replace('feature-thumb-','feature-full-');
				$('#'+id).fadeIn('slow');
			} else {
				$a = $('#heroShots #controls li:last').find('a');
				$a.addClass('current');
				var id = $a.attr('id').replace('feature-thumb-','feature-full-');
				$('#'+id).fadeIn('slow');
			}
		}
	});
	
	$('#username').focus(function() {
		if(this.value == 'User Name') {
			this.value = '';
		}
	}).blur(function() {
		if(this.value == '') {
			this.value = 'User Name';
		}
	});
	
	$('#password').focus(function() {
		if(this.value == 'Password') {
			this.value = '';
		}
	}).blur(function() {
		if(this.value == '') {
			this.value = 'Password';
		}
	});
	
	$('#secondaryNav ul > li').click(function() {
		$(this).parent().find('.active').removeClass('active');
		$(this).addClass('active');
		return false;
	});

	$('#secondaryNav a').click(function() {
		if ($(this).attr("href") != "#") window.location = $(this).attr("href");
	});
	
	$('.employeeWidget .prev').click(function() {
		$parent = $(this).parent().parent().parent();
		$parent.hide();
		if ($parent.prev().length == 0)
			$parent.siblings(":last").fadeIn('slow');
		else
			$parent.prev().fadeIn('slow');
	});

	$('.employeeWidget .next').click(function() {
		$parent = $(this).parent().parent().parent();
		$parent.hide();
		if ($parent.next().length == 0)
			$parent.siblings(":first").fadeIn('slow');
		else
			$parent.next().fadeIn('slow');
	});
	
	$("#locationSelect").change(function () {
		$(".addressItem").hide();
		$("#"+$("#locationSelect option:selected").val()).show();
	});

	$("#dialog").dialog({
		autoOpen: false,
		modal: false,
		draggable: false,
		resizable: false,
		dialogClass: 'dialog',
		closeText: ''
	});
	
	$(".dialog-link").click(function(event) {
		event.preventDefault();
		$link = $(this);
		$.get($link.attr('href'), function(data) {
			addthis_close();
			var position = $link.position();
			$("#dialog").html(data);
			$("#dialog").dialog('option','position', [(position.left-255), (position.top+15)]);
			$("#dialog").dialog('open');
			$(".dialog").css({left: (position.left-255) + 'px', top: (position.top+15) + 'px'});
			
		});
	});
	
	$(".addThis").click(function(event) {
		$("#dialog").dialog('close');
	});
	
	$(".addThis").bind('mouseover', function(event) {
		$(this).find('img').attr('src', '/rebrand/img/addThisHover.gif');
	});
	
	$(".addThis").bind('mouseout', function(event) {
		$(this).find('img').attr('src', '/rebrand/img/addThis.gif');
	});
	
	$("#expand").click(function() {
		$(".faq li").removeClass("closed");
	});

	$("#collapse").click(function() {
		$(".faq li").addClass("closed");
	});
	
	$(".faq h4").click(function() {
		$(this).parent().toggleClass("closed");
	});
	
});

