jQuery.noConflict();

// timer
var jobTimer;
var imTime = 8000;

function rotatorChangeTab(iCurrentTab, iNewTab) {
	var iJobs = 1;
	jQuery("#premierjobs_jobsection a." + iCurrentTab + " img").attr("src", "/global/img/scroll_blank.gif");
	jQuery("#premierjobs_jobsection a." + iNewTab + " img").attr("src", "/global/img/scroll_active.gif");
	jQuery("#premierjobs_jobs div").each(function() {
		if(iJobs == iNewTab) {
			jQuery("#premierjobs_jobsection ul").attr("className", "" + iJobs);
			jQuery(this).show();
		}
		else {
			jQuery(this).hide();
		}
		iJobs++;
	});
	clearInterval(jobTimer);
	jobTimer = setInterval("rotatorNextTab()", imTime);
}

function rotatorNextTab() {
	var iCurrentTab = parseInt(jQuery("#premierjobs_jobsection ul").attr("className"));
	rotatorChangeTab(iCurrentTab, iCurrentTab < jQuery('#premierjobs_jobs').children().size() ? iCurrentTab + 1 : 1);
}

jQuery(function() {
	// add links
	var iJobs = 1;
	var liStart = "<li><a href=\"#\" class=\"";
	var liMid = "\"><img src=\"/global/img/scroll_";
	var liEnd = ".gif\"></a></li>";
	jQuery("#premierjobs_jobsection ul").append(liStart + "prev" + liMid + "prev" + liEnd);
	jQuery("#premierjobs_jobs div").each(function() {
		jQuery("#premierjobs_jobsection ul").append(liStart + iJobs + liMid + (iJobs == 1 ? "active" : "blank") + liEnd);
		iJobs++;
	});
	jQuery("#premierjobs_jobsection ul").append(liStart + "next" + liMid + "next" + liEnd);
	
	// add click events
	jQuery("#premierjobs_jobsection ul li a").click(function(e){
		var iCurrentTab = parseInt(jQuery("#premierjobs_jobsection ul").attr("className"));
		e.preventDefault();
		if(jQuery(this).attr("class") == "prev")
			rotatorChangeTab(iCurrentTab, iCurrentTab > 1 ? iCurrentTab - 1 : 1);
		else if(jQuery(this).attr("class") == "next")
			rotatorChangeTab(iCurrentTab, iCurrentTab < jQuery('#premierjobs_jobs').children().size() ? iCurrentTab + 1 : 1);
		else
			rotatorChangeTab(iCurrentTab, jQuery(this).attr("class"));
	});
	
	// start timer
	jobTimer = setInterval("rotatorNextTab()", imTime);
});