var currPic = 1;
var rotatorInt, rotatorColl;
var fadeSpeed = .66;
var currAlert = 1;
var totPics = 5;
function InitRotator()
{
    rotatorColl = $$('div[id^=Rotator_]');
    rotatorInt = setInterval("CycleRotator()", 8000);    
}
function InitAlertRotator()
{
    AlertColl = $$('div[id^=Alert_]');
    alertInt = setInterval("CycleAlerts()", 5000);    
}
function CycleRotator()
{
	currPic++;
	if (currPic > totPics){
		currPic = 1;
	} 
	if (currPic < 2){
		prevPic = 5;
	} else {
		prevPic = currPic - 1;
	}
	Effect.Fade('Rotator_'+prevPic, {duration:fadeSpeed});
	Effect.Appear('Rotator_'+currPic, {duration:fadeSpeed});
	$('RotatorBtn_'+currPic).src = 'images/homepage_frame-on.gif';
    $('RotatorBtn_'+prevPic).src = 'images/homepage_frame-off.gif';
	if (currPic > 1){
		$('rcs').show();
	} else {
		$('rcs').hide();
	}
}
function CycleAlerts()
{
    var nextAlert = currAlert + 1;
    if (nextAlert > AlertColl.length)
    {
        nextAlert = 1;
    }
    
    Effect.Fade('Alert_'+currAlert, {duration:fadeSpeed});
	setTimeout(function(){ Effect.Appear('Alert_'+nextAlert, {duration:fadeSpeed});}, 660);
    currAlert = nextAlert;
}
function openNewWindow(URLtoOpen, windowName, windowFeatures) { newWindow=window.open(URLtoOpen, windowName, windowFeatures); }

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function SkipToFrame(rotatorNum)
{
    clearInterval(rotatorInt);

    Effect.Fade('Rotator_'+currPic, {duration:fadeSpeed});
    $('RotatorBtn_'+currPic).src = 'images/homepage_frame-off.gif';
    
    Effect.Appear('Rotator_'+rotatorNum, {duration:fadeSpeed});
    $('RotatorBtn_'+rotatorNum).src = 'images/homepage_frame-on.gif';
    if (rotatorNum != 1){
		$('rcs').show();
	} else {
		$('rcs').hide();
	}
    currPic = rotatorNum;
    rotatorInt = setInterval("CycleRotator()", 8000); 
	
}
function SubmitComment(gallery)
{
    var errors = false;
    if (!$F('cmName') || !$F('cmComments'))
    {
        errors = true;
    }
    
    if (!errors)
    {
        new Ajax.Request('/bellman_new/ajax.php', {
           method: 'post',
           parameters: {
                arg : 'comment',
                galleryID : gallery,
                name : $F('cmName'),
                comments : $F('cmComments')
           },
           onComplete:function(obj)
           {
                $('cmName').value = '';
                $('cmComments').value = '';
                
                alert("Thanks for sharing your comments.");
           }
        });
    }
}

function SevenDateEntries(startAt)
{
    var loadrecs = true;

    if (loadrecs)
    {
        new Ajax.Request('/bellman_new/ajax.php', {
           method: 'post',
           parameters: {
                arg : 'entries',
                offset : startAt
           },
           onCreate:function(obj)
           {
                $('entryList').innerHTML = '<table cellspacing="10" cellpadding="0" border="0" align="center"><tr><td><img src="images/wait-spin-red.gif" width="32" height="32" border="0" /><br /></td><td style="font: bold 10px Arial, Helvetica, Tahoma; color: #A32B32">Loading Entries...</span><br /></tr></table>';
           },
           onComplete:function(obj)
           {
                $('entryList').innerHTML = obj.responseText;
           }
        });
    }
}
