var userInteractedFl = false;
var _timerID = 0;

var _iconOver = 'images/common/greyBox_over.gif';
var _icon = 'images/common/greyBox.gif';

function NonInteractionHandler() {

	if (userInteractedFl == true) {
		clearTimeout (_timerID);
		return;
	}
	
	var _count = $('#projectNav ul li a').length;
	var _selected = 1;
	var _found = false;
	$('#projectNav ul li a img').each(function() {
		if (_found || $(this).attr('src') == _iconOver) {
			_found = true;
		} else {
			_selected++;
		}
	});
	
	if (_selected == _count) {
		_selected = 1;
	} else {
		_selected++;
	}
	$('#projectNav ul li a').eq((_selected-1)).click();
}

$(document).ready(function() {

    $('#projectNav ul li a').click(function(e) {
    	if (e.target.href == undefined) {
    		userInteractedFl = true;
    	}
    	$('#projectNav ul li a img').attr('src', _icon);
        $(this).children('img').eq(0).attr('src', _iconOver);
        $('img#PreviewImage').hide();
        $('img#PreviewImage').attr('src', $('input#lrg'+$(this).attr('id')).val()).fadeIn();
        $(this).blur();
        return false;
    });
    
    $('#projectNav ul li a').eq(0).click();
    
    $('input.hiddenpreviews').each(function() {
        $.preloadimages($(this).val());
    });
    
    if ($('#projectNav ul li').length) {
    	_timerID = setInterval("NonInteractionHandler()", 8000);
    }
    
});
