$(function() {
	
/* dropdown menu */                 
    $('#nav li').hover(function(){
        $(this).addClass('hover');
        $('ul:first', this).css('visibility', 'visible');
    }, function(){
        $(this).removeClass('hover');
        $('ul:first', this).css('visibility', 'hidden');
    });
    
/* clickable(big) feature buttons */
    var hostName = window.location.hostname;
    
    $('ul.quickMenu li').click(function() {
	var theLink = $(this).find('a')[0].href;
	
	if(theLink.indexOf('.pdf') != -1 || theLink.indexOf(hostName) == -1) {
	    window.open(theLink);	
	} else {
	    window.location = theLink;
	}
	
    }).css('cursor', 'pointer');
    
/* Newsletter placeholder text (HOMEPAGE ONLY) */
    $('#email').addClass('placeholder');
    $('#email').bind('focusin', function(event){
	var obj = $(event.target);
	obj.removeClass('placeholder');
	if(obj.val() == obj.attr('title')) obj.val('');
    });
    $('#email').bind('focusout', function(event){
	var obj = $(event.target);
	if((obj.val() == '') || (obj.val() == obj.attr('title'))) {
	    obj.val(obj.attr('title'));
	    obj.addClass('placeholder');
	}
    });
    
/* menu styling adjustment */
    $('#nav li#investors .submenu ul').css({'left': 'auto', 'right': '100%'})
                                      .find('a').css('width', '150px');
    $('#nav > ul > li:last').find('ul:first').css({'left': 'auto', 'right': '0', 'width': '100px'});
        
    pageName = $('#sidebar > h2').text().toLowerCase().replace(/ /g,'').replace(/&/g,'');
    //$('#nav > ul > li').removeClass('current').filter('#'+ pageName).addClass('current');
            
    if(pageName === 'corporate') {$('#nav li#corporate').css({'background-position': '0 -32px'});}
    if(pageName === 'projects') {$('#nav li#projects').css({'background-position': '-145px -32px'});}
    if(pageName === 'investors') {$('#nav li#investors').css({'background-position': '-283px -32px'});}
    if(pageName === 'news') {$('#nav li#news').css({'background-position': '-430px -32px'});}

/* re-styling sidebar for pages without subnav */
    if($('#content_sub').length > 0) {
        if($('#sidebar #subNav > ul').length < 1) {
	    $('#sidebar h2:first').remove();
	    $('#subNav').remove();
	    $('#features').css('margin-top', '0');
	}
    }
    
});

/* background image rotator */
function rotator() {
        $('#rotatingBanner div, #rotatingBanner_uranium div').css('opacity', 0)
                                .eq(0).css('opacity', 1).addClass('active');
        
        setInterval('rotateIt()', 5000);
}

function rotateIt() {
    // Get the first image
    var currentImg = $('#rotatingBanner div.active') ? $('#rotatingBanner div.active') : $('#rotatingBanner div:first');
    var currentImg2 = $('#rotatingBanner_uranium div.active') ? $('#rotatingBanner_uranium div.active') : $('#rotatingBanner_uranium div:first');

	// Get next image, when it reaches the end, rotate it back to the first image
    var nextImg = (currentImg.next().length) ? (currentImg.next().hasClass('active')) ? $('#rotatingBanner div:first') : currentImg.next() : $('#rotatingBanner div:first');
    var nextImg2 = (currentImg2.next().length) ? (currentImg2.next().hasClass('active')) ? $('#rotatingBanner_uranium div:first') : currentImg2.next() : $('#rotatingBanner_uranium div:first');
	
	// Set the fade in effect for the next image, the active class has higher z-index
	nextImg.css('opacity', 0)
	       .addClass('active')
	       .animate({opacity: 1}, 1500);
	
	nextImg2.css('opacity', 0)
	       .addClass('active')
	       .animate({opacity: 1}, 1500);

	// Hide the current image
	currentImg.animate({opacity: 0}, 1500)
	          .removeClass('active');
                  
	currentImg2.animate({opacity: 0}, 1500)
	          .removeClass('active');
       
}

