
function set_background(obj) {
	var url = "url(" + obj.find('img').attr('src') + ")";
	var repeat = "no-repeat";
	jQuery("#index-background").css({backgroundImage: url, backgroundRepeat: repeat});
	
	
	// Enable below two lines for animating homepage backgrounds....

	//obj.css({opacity: 1.0})
	//obj.animate({opacity: 0.0}, 1500);

}

function gallery() {
	var current = (jQuery('#index-background ul li.show') ? jQuery('#index-background ul li.show') : jQuery('#index-background ul li:first'));
	var next = ((current.next().length) ? current.next() : jQuery('#index-background ul li:first'));

	set_background(next);
	//next.css({opacity: 0.0, zIndex: 400}).addClass('show').animate({opacity: 1.0}, 2000);
	//current.animate({opacity: 0.0}, 2000).removeClass('show');
	
	
	//next.css({ opacity: 0.0 },15000).addClass('show').fadeTo("slow", 0.0);
	//current.css({ opacity: 1.0},10000).fadeTo("slow", 0.0).removeClass('show');
	next.addClass('show');
	current.removeClass('show');
}


jQuery(document).ready(function () {
	jQuery('.bt').click(function() { button_click(jQuery(this).attr('id')); });

	//news_rotation();
	button_click('b1');
});

var t;
var nto;
var cur_bt_id;

function news_rotation() {
	var current = jQuery("#news-line").find('.show');
	if(!current.hasClass('.show')) {
		jQuery("#news-line-content").css({ opacity: 0.0 });
		jQuery("#news-line :first").addClass('show');
		current = jQuery("#news-line").find('.show');
		var anchor = current.html();
		var content = current.find("a").html();

		jQuery("#news-line-content .layer-1").append(content);
		jQuery("#news-line-content .layer-2").append(anchor);
		jQuery("#news-line-content").animate( { opacity: 1.0 }, 500);
	}
	else {
		var current = (jQuery('#news-line .show') ? jQuery('#news-line .show') : jQuery('#news-line div:first'));
		var next = ((current.next().length) ? current.next() : jQuery('#news-line div:first'));
		
		var anchor = next.html();
		var content = next.find("a").html();
				
		next.addClass('show');
		current.removeClass('show');
		
		jQuery("#news-line-content").animate( { opacity: 0.0 }, 500, function() {
			jQuery("#news-line-content .layer-1").html("");
			jQuery("#news-line-content .layer-2").html("");
			
			jQuery("#news-line-content .layer-1").append(content);
			jQuery("#news-line-content .layer-2").append(anchor);	
		});
		
		jQuery("#news-line-content").animate({ opacity: 1.0 }, 500);		
	}

	clearTimeout(nto);
	nto = setTimeout(function() { news_rotation() }, 5000);
}



function button_click(bt_id) {
var count = jQuery("#p1");

if(count.next().html() == null)
	{
	jQuery('#promo-box .promo-tabs').css({display: "none"});
	}
else
	{
	jQuery("#promo-box .promo-tabs").css({display: "block"});
	}


	
var cid = '#' + bt_id;
		var next_bt_id = $(cid).next().attr('id');
		if (!next_bt_id) { 
			next_bt_id = 'b1';
		}
		clearTimeout(t);
		t = setTimeout(function() {button_click(next_bt_id);}, 5000);
		
		var item = jQuery("#index-background ul").find('.show');
		if(item.hasClass('.show')) {
			gallery();
		}
		else {
			jQuery('#index-background ul li').css({display: "block"});
			jQuery('#index-background ul li').css({opacity: 0.0});
			jQuery('#index-background ul li:first').css({opacity: 0.0});
			gallery();
			var item = jQuery("#index-background ul").find('.show');
			set_background(item);
		}
		
		jQuery(cid).addClass("active");
		jQuery(cid).nextAll().removeClass("active");
		jQuery(cid).prevAll().removeClass("active");
		
		var current = jQuery("#p"+ bt_id.substring(1, 2));
		var urlc = current.find("a");
		
		$('#promo-message').html(current.find("#description").html());
		$('#promo-header').html(current.find("#header").html());
$('#promo-url').html(vReadmore);
$('#promo-url').attr("href",urlc.attr("href"));
		
}