﻿var chHeadlines = new Array();
var chHeadlineIndex = 0;
var chIteration = 0;
var chSelector = null;
function chHeadline(body, img) {
	this.body = body;
	this.img = img;
	this.pager = "";
}

function initHeadlines(selector) {
	chSelector = selector;
	$("#bgImg1").load(function() { $(this).fadeIn("slow"); $("#bgImg2").fadeOut("slow"); });
	$("#bgImg2").load(function() { $(this).fadeIn("slow"); $("#bgImg1").fadeOut("slow"); });
	$("#bgImg2").hide();
	window.setTimeout(nextHeadline, 8000);
}

function nextHeadline() {
	$(chSelector).fadeOut("slow", nextHeadline_show);
}
function nextHeadline_show() {
	$("#" + chHeadlines[chHeadlineIndex].pager).removeClass("active");
	chHeadlineIndex++;
	chIteration++;
	if (chHeadlineIndex >= chHeadlines.length) chHeadlineIndex = 0;
	$(chSelector).html(chHeadlines[chHeadlineIndex].body).fadeIn("slow");
	$("#bgImg" + ((chIteration % 2) + 1)).attr("src", chHeadlines[chHeadlineIndex].img);
	$("#" + chHeadlines[chHeadlineIndex].pager).effect("pulsate", { times: 1 }, 250, function() { $(this).addClass("active"); });
	window.setTimeout(nextHeadline, 8000);
}

function hideHeadline(selector) {
	$(selector).click(function() { $(this).fadeOut("slow"); });
}