$(document).ready(function() {
	// Set menu animations
	$('#bottomNav li').hover(
		function() {
		    //$(this).find('.menuOverlay').slideDown('slow');
		    $(this).find('.menuOverlay').fadeIn();
		    $(this).css('background-color', '#7b7d7f');
		},
		function() {
			//$(this).find('.menuOverlay').slideUp('fast');
			$(this).find('.menuOverlay').fadeOut(); 
			$(this).css('background-color', 'transparent');
		}
	);
	$('.dropMenu').parent().hover(
		function() {
			$(this).find('ul').fadeIn();		
		},
		function() {
			$(this).find('ul').fadeOut();
		}
	);

	$('input[class=grayBox]').focus(
		function() {
			if ($('input[class=grayBox]').attr('value') == 'search') {
				$('input[class=grayBox]').attr('value', '');
			}
		}
	);
	$('input[class=grayBox]').blur(
		function() {
			if ($('input[class=grayBox]').attr('value') == '') {
				$('input[class=grayBox]').attr('value', 'search');
			}
		}
	);
});


/*  Home header javascript */
var images = [["Digineer/media/DigineerAssets/hp_lowercosts.jpg", "To lower costs, elevate the approach.", "results/lower-costs.aspx"],
				["Digineer/media/DigineerAssets/hp_drivingrevenue.jpg", "Drive revenue faster with more authority.", "results/drive-revenue.aspx"],
				["Digineer/media/DigineerAssets/increaseefficiency.jpg", "Even a well-oiled machine runs better with less friction.", "results/increase-efficiency.aspx"],
				["Digineer/media/DigineerAssets/hp_alignprocesses.jpg", "Want to pull ahead? First make sure everyone pulls together.", "results/align-practices.aspx"],
				["Digineer/media/DigineerAssets/clarifyinitiatives.jpg", "Business initiatives grinding to a halt? We can get you rolling again.", "results/clarify-initiatives.aspx"],
				["Digineer/media/DigineerAssets/hp_ensurecompliance.jpg", "Not all compliance headaches have to be painful.", "results/ensure-compliance.aspx"]];
var imageIndex = 0;
var imageInterval;

function cycleImages() {
    $('#mainImageRear img').attr('src', images[imageIndex][0]);
    $('#mainImageFront').hide();
    imageIndex++;
    if (imageIndex >= images.length) {
        imageIndex = 0;
    }
    $('#mainImageFront img').attr('src', images[imageIndex][0]);
    $('h1.headline').hide();
    $('h1.headline').html(images[imageIndex][1]);
    $('#mainImageFront').fadeIn('slow');
    $('h1.headline').fadeIn('slow');
    $('#bannerLink').attr('href', images[imageIndex][2]);
}

function nextImage() {
    if (imageIndex < images.length - 1) {
        $('#mainImageRear img').attr('src', images[imageIndex][0]);
        $('#mainImageFront').hide();
        imageIndex++;

        $('#mainImageFront img').attr('src', images[imageIndex][0]);
        $('h1.headline').hide();
        $('h1.headline').html(images[imageIndex][1]);
        $('#mainImageFront').fadeIn('slow');
        $('h1.headline').fadeIn('slow');
        $('#bannerLink').attr('href', images[imageIndex][2]);
    }
}

function previousImage() {
    if (imageIndex > 0) {
        $('#mainImageRear img').attr('src', images[imageIndex][0]);
        $('#mainImageFront').hide();
        imageIndex--;

        $('#mainImageFront img').attr('src', images[imageIndex][0]);
        $('h1.headline').hide();
        $('h1.headline').html(images[imageIndex][1]);
        $('#mainImageFront').fadeIn('slow');
        $('h1.headline').fadeIn('slow');
        $('#bannerLink').attr('href', images[imageIndex][2]);
    }
}

function toggleCycle() {
    if (imageInterval != -1) {
        stopCycle();
    } else {
        startCycle();
    }
}

function stopCycle() {
    clearInterval(imageInterval);
    imageInterval = -1;
}

function startCycle() {
    imageInterval = setInterval(cycleImages, 10000);
    imageIndex = 0;
    $('h1.headline').html(images[imageIndex][1]);
    $('#bannerLink').attr('href', images[imageIndex][2]);
}

function preLoadImages() {

    // Preload the "bar" images
    bottomBarHover = new Image();
    bottomBarHover.src = "~/Digineer/media/DigineerAssets/bottom_bar_hover.png";

    bottomBarOff = new Image();
    bottomBarOff.src = "~/Digineer/media/DigineerAssets/bottom_bar_off.png";

    var i = 0;
    image = new Image();

    for (i = 0; i < images.length; i++) {
        image.src = images[i][0];
    }
}

