var right_interval_time = 4000; // 3 seconds between changes
var right_item_count;
var right_item_interval;
var right_old_item = 0;
var right_current_item = 0;
var top_interval_time = 7000; // 3 seconds between changes
var top_item_count;
var top_item_interval;
var top_old_item = 0;
var top_current_item = 0;

$(document).ready(function() {
    right_item_count = $("div.ad-right-item").size();
	if (right_item_count > 1) {
    $("div.ad-right-item").each(function(i) {
        $(this).hide();
    });
    $("div.ad-right-item:eq(" + right_current_item + ")").fadeIn("slow");
    right_item_interval = setInterval(ad_rotate_right, right_interval_time);
    $('#ad-right').hover(function() {
        clearInterval(right_item_interval);
    }, function() {
        right_item_interval = setInterval(ad_rotate_right, right_interval_time);
        ad_rotate_right();
    })
	}
    top_item_count = $("div.ad-top-item").size();
	if (top_item_count > 1) {
    $("div.ad-top-item").each(function(i) {
        $(this).hide();
    });
    $("div.ad-top-item:eq(" + top_current_item + ")").fadeIn("slow");
    top_item_interval = setInterval(ad_rotate_top, top_interval_time);
    $('#ad-top').hover(function() {
        clearInterval(top_item_interval);
    }, function() {
        top_item_interval = setInterval(ad_rotate_top, top_interval_time);
        ad_rotate_top();
    })
	}
});
function addMainMenuLinks() {
	$("div.menu a[href*=/info.cfm]").click(function(event) {
		$("div.content").html('loading...');
		var theID = $(this).attr("id")
		if($.trim(theID) == '') return false
		$.get('/info.cfm/' + theID,{},function(data,status) {
			$("div.content").html(data)
		})
		var url = 'submenu.cfm?theMenuGroup=' + theID  + '&' + new Date().getTime()
		$("div.subMenu").load(url)
		event.preventDefault()
	})
};
function addSubMenuLinks() {
	$("div.subMenu a[href*=/info.cfm]").click(function(event) {
		var theID = $(this).attr("id")
		if($.trim(theID) == '') return false
		$.get('/info.cfm/' + theID,{},function(data,status) {
			$("div.content").html(data)
		})
		event.preventDefault()
	})
};
function addLinks() {
	$("div a[href*=/info.cfm]").click(function(event) {
		var theID = $(this).attr("id")
		if($.trim(theID) == '') return false
		$.get('/info.cfm/' + theID,{},function(data,status) {
			$("div.content").html(data)
		})
		event.preventDefault()
	})
};
function missingImage() {
	$("img").error(function() {
		$(this).attr("src", "/images/missing.jpg");
    });
};
function addPrettyHighlight() {
	$("div.content p").hover(function() {
	  	$(this).addClass('pretty-hover')
	}, function() {
  		$(this).removeClass('pretty-hover')
	})
};
function send_loginForm() {
	$.post('/components/login.cfc?method=doLogin&returnFormat=plain',$("##loginForm").serialize(),function(data,status) {
		data = $.trim(data)
		if (data == 'success') {
			$("div.logindiv").html('<b>You are logged in...</b>')
			var url = '/components/menuRemote.cfc?method=getMainMenu&returnFormat=plain&' + new Date().getTime()
			$("div.menu").load(url)
		} else {
			$("div.loginFailed").html('<b>Your login failed...</b>')
		}
	})
	return false
};
function addPrintButton() {
	$('<a href="#" title="Printer Friendly Page" class="print">Print Page</a>')
		.click(function() {
			$('div.page').hide()
			$('div.header').hide()
			$('div.menu').hide()
			$('div.top_ad').hide()
			$('div.top_main_right').hide()
			$('div.leftColumn').hide()
			$('div.rightColumn').hide()
			$('div.footer').hide()
			window.print()
			$('div.page').show()
			$('div.header').show()
			$('div.menu').show()
			$('div.top_ad').show()
			$('div.top_main_right').show()
			$('div.leftColumn').show()
			$('div.rightColumn').show()
			$('div.footer').show()
		})
		.appendTo('div.top_main_right_print')
}
function addEditButton( pageData ) {
	$('div.top_main_right_edit').empty()
	$('<a href="javascript: popup(&quot;/edit.cfm?alias=' + pageData + '&quot;);" class="edit">Edit</a>')
		.click(function() {
		})
		.appendTo('div.top_main_right_edit')
}
function ad_rotate_right() {
	right_current_item = (right_old_item + 1) % right_item_count;
	$("div.ad-right-item:eq(" + right_old_item + ")").fadeOut("slow", function() {
		$("div.ad-right-item:eq(" + right_current_item + ")").fadeIn("slow");
	});
	right_old_item = right_current_item;
}
function ad_rotate_top() {
	top_current_item = (top_old_item + 1) % top_item_count;
	$("div.ad-top-item:eq(" + top_old_item + ")").fadeOut("slow", function() {
		$("div.ad-top-item:eq(" + top_current_item + ")").fadeIn("slow");
	});
	top_old_item = top_current_item;
}
function edit(url) {
	newWindow = window.open(url,'daughter','status=no,menubar=no,toolbar=no,location=no,scrollbars=yes,resizable=no,width=1000,height=600,screenX=50,screenY=50,top=50,left=50');
	newWindow.focus();
}
function print(url) {
	newWindow = window.open(url,'daughter','status=yes,menubar=no,toolbar=no,location=no,scrollbars=yes,resizable=no,width=1000,height=600,screenX=50,screenY=50,top=50,left=50');
	newWindow.focus();
}
