function theRotator(timer) {	

	//all images opacity set to 0 so all background images wont show up
	jQuery('div.rotator ul li').css({opacity: 0.0});
	jQuery('div.rotating-title ul li').css({opacity: 0.0});

	
	//Display the first image by setting its opacity to 1
	jQuery('div.rotator ul li:first').css({opacity: 1.0});
	jQuery('div.rotating-title ul li:first').css({opacity: 1.0});

	//set up the order of the loop, does something every 15 secs
	setInterval('change()',timer);

}

function change() {

	//This part of the code gets the first image. 
	var current = (jQuery('div.rotator ul li.show')? jQuery('div.rotator ul li.show') : jQuery('div.rotator ul li:first'));
	var current_title = (jQuery('div.rotating-title ul li.show')? jQuery('div.rotating-title ul li.show') : jQuery('div.rotating-title ul li:first'));
	
		//The first image either have class=show on it or its the first element inside rotator div
		if ( current.length == 0 ) current = jQuery('div.rotator ul li:first');
		if ( current_title.length == 0 ) current_title = jQuery('div.rotating-title ul li:first');

	//Now get the next image and when you reach the last image, point it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? jQuery('div.rotator ul li:first') :current.next()) : jQuery('div.rotator ul li:first'));
	var next_title = ((current_title.next().length) ? ((current_title.next().hasClass('show')) ? jQuery('div.rotating-title ul li:first') :current_title.next()) : jQuery('div.rotating-title ul li:first'));
	
	//Fade-in effect for the next image and displays the image with the higher z-index
	next.css({opacity: 0.0})
	
	.addClass('show')

	.animate({opacity: 1.0}, 1000);
	
  next_title.css({opacity: 0.0})
  .addClass('show')
	.animate({opacity: 1.0}, 1000);
	
	//This part of the code hides the current image so that the next image is seen.
	current.animate({opacity: 0.0}, 1000)

	.removeClass('show');
	
	current_title.animate({opacity: 0.0}, 1000)

	.removeClass('show');

};
jQuery(document).ready(function() {

  jQuery(".rotator li:first ").addClass("show");
  jQuery(".rotating-title li:first ").addClass("show");
  
	var theWindow        = jQuery(window),
	    jQuerybg         = jQuery("#bg1 li img"),
	    jQueryOneImgBg   = jQuery("#bg1"),
	    jQueryContentHeight   = jQuery("#content"),
	    aspectRatio      = jQuerybg.width() / jQuerybg.height();

	    
	// if the content is not there or the height of the content is less than the height of the entire window    
  if ( (jQuery('#content').length == 0) || ((jQueryContentHeight.height() + 150) < theWindow.height()) ) { 
    jQuery('#footer').addClass('absolutely-positioned');
    jQuery('#footer').removeClass('hide-nav');
  } else {
  // console.log('outside');
    jQuery('#footer').removeClass('hide-nav');
  }

	function resizeBg() {

		if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
		    jQuerybg
			.removeClass()
			.addClass('bgheight');			
		} else {
		    jQuerybg
			.removeClass()
			.addClass('bgwidth')
      .addClass('bgheight');			
		}

	}
	
	function resizeStaticBg() {

		if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
		  jQueryOneImgBg
			.removeClass()
			.addClass('bgheight');			
		} else {
		   jQueryOneImgBg
			.removeClass()
			.addClass('bgwidth')
      .addClass('bgheight');			
		}

	}

	theWindow.resize(function() {
		resizeBg();
		resizeStaticBg();
	}).trigger("resize");
	
	

	jQuery('div.rotator').fadeIn(1000); // works for all the browsers other than IE
	jQuery('div.rotating-title').fadeIn(1000); // works for all the browsers other than IE

	jQuery('div.rotator ul li').fadeIn(1000); // IE hack
	jQuery('div.rotating-title').fadeIn(1000); // works for all the browsers other than IE
	

	
	//Fix Errors - http://www.learningjquery.com/2009/01/quick-tip-prevent-animation-queue-buildup/
		
		//Remove outline from links
		//jQuery("#menu-main-navigation li a").click(function(){
			//jQuery(this).addClass('active');
			//jQuery(this).css( 'color','#447C3C' );
	//	});
		
		//When page loads slide the content from right to left
		jQuery("#content").animate({width:'65%'},{queue:false, duration:4000, easing: 'easeOutQuad'});
		
		//When mouse rolls over
		jQuery("#menu-main-navigation > li").mouseover(function(){
			jQuery(this).stop().animate({height:'110px'},{queue:false, duration:1000, easing: 'easeOutQuad'})
		});
		
		//When mouse is removed
		jQuery("#menu-main-navigation > li").mouseout(function(){
			jQuery(this).stop().animate({height:'20px'},{queue:false, duration:1000, easing: 'easeOutQuad'})
	  });
	  
	   //Stop slide up for the 'news' menu link
	   jQuery("#menu-main-navigation > li#menu-item-50").mouseover(function(){
	     jQuery(this).stop()
	   });
	   
	   jQuery("#menu-main-navigation > li#menu-item-50").mouseout(function(){
	     jQuery(this).stop()
	   });
	   
	   //Stop slide up for the 'contact' menu link
	   jQuery("#menu-main-navigation > li#menu-item-51").mouseover(function(){
	     jQuery(this).stop()
	   });
	   
	   jQuery("#menu-main-navigation > li#menu-item-51").mouseout(function(){
	     jQuery(this).stop()
	   });
	 
	   //Stop slide up for the 'contact' menu link
	   jQuery("#menu-main-navigation > li#menu-item-53").mouseover(function(){
	     jQuery(this).stop()
	   });
	   
	   jQuery("#menu-main-navigation > li#menu-item-53").mouseout(function(){
	     jQuery(this).stop()
	   });	 
	   
	   //Stop slide up for the 'contact' menu link
	   jQuery("#menu-main-navigation > li#menu-item-55").mouseover(function(){
	     jQuery(this).stop()
	   });
	   
	   jQuery("#menu-main-navigation > li#menu-item-55").mouseout(function(){
	     jQuery(this).stop()
	   });	   
	   
	   //Stop slide up for the 'twitter' menu link
	   jQuery("#menu-main-navigation > li#menu-item-129").mouseover(function(){
	     jQuery(this).stop()
	   });
	   
	   jQuery("#menu-main-navigation > li#menu-item-129").mouseout(function(){
	     jQuery(this).stop()
	   });
	   
	   //jQuery('#menu-main-navigation > li#menu-item-129 a').wrap('<span />');
	   
	   //Stop slide up for the 'linkedin' menu link
	   jQuery("#menu-main-navigation > li#menu-item-128").mouseover(function(){
	     jQuery(this).stop()
	   });
	   
	   jQuery("#menu-main-navigation > li#menu-item-128").mouseout(function(){
	     jQuery(this).stop()
	   });

});

