/* Mickey's Javascript */



/* Functions for cool input text stuff */
function inputClick(input) {
	if (input.value == input.alt) {
		input.value = '';	
	}
}

function inputClickOff(input) {
	if (input.value == '') {
		input.value = input.alt;	
	}
}

// Clear periods from pageIntro divs when need be
function introPeriods() {
	var pageIntro = jQuery("div.pageIntro").text();
		
	//Get first and last period to check if the page intro has multiple sentences
	var firstPeriod = pageIntro.indexOf(".");
	var lastPeriod = pageIntro.lastIndexOf(".");
	if (firstPeriod == lastPeriod) {
		var pageIntro = jQuery("div.pageIntro").text().replace(".", "");
		jQuery("div.pageIntro").text(pageIntro);
	}	
}

// Adds 'Case Study:' before the actual case study title
function caseStudy() {
	var title = jQuery("div.caseStudy h2").html();
	var title = 'Case Study: ' + title;
	jQuery("div.caseStudy h2").html(title);
}

// Vertically align 'Latest News' and 'watchVideos' widgets
function alignFPWidgets() {
	
	if (jQuery("#latestNews").offset().top) {
		jQuery("#videoWidget").css({ 
			'margin-top': '0px',
        	        'top': (jQuery("#latestNews").offset().top-jQuery("#videoWidget").position().top)
       		 } );
		
		var height = jQuery("#latestNews .lcp_catlist").height()+'px';
		jQuery("#videoWidget .widget").css({ 
               		'height': height,
      		} );
	}
}

function theRotator() {
	//Set the opacity of all images to 0
	jQuery('div.rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	jQuery('div.rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	
}

//To be used globally as the timeout object
var timeout;

function next() {	
	//Get the first image
	var current = (jQuery('div.rotator div.images a.show')?  jQuery('div.rotator div.images a.show') : jQuery('div.rotator div.images a:first'));

    if ( current.length == 0 ) current = jQuery('div.rotator div.images a:first');

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? jQuery('div.rotator div.images a:first') :current.next()) : jQuery('div.rotator div.images a:first'));
	
	//Un-comment the 3 lines below to get the images in random order
	
	//var sibs = current.siblings();
        //var rndNum = Math.floor(Math.random() * sibs.length );
        //var next = jQuery( sibs[ rndNum ] );
			

	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
}

function previous() {
	//Get the first image
	var current = (jQuery('div.rotator div.images a.show')?  jQuery('div.rotator div.images a.show') : jQuery('div.rotator div.images a:first'));

    	if ( current.length == 0 ) current = jQuery('div.rotator div.images a:first');

	//Get previous image, when it reaches the end, rotate it back to the first image
	var next = ((current.prev().length) ? ((current.prev().hasClass('show')) ? jQuery('div.rotator div.images a:first') :current.prev()) : jQuery('div.rotator div.images a:last'));
	
	//Un-comment the 3 lines below to get the images in random order
	
	//var sibs = current.siblings();
        //var rndNum = Math.floor(Math.random() * sibs.length );
        //var next = jQuery( sibs[ rndNum ] );
			

	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
}

