var curBlogHlInd = 0;
$(document).ready(function(){
	
	// ### TOP MENU
	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	$("ul#menu_top li span").hover(function() { 
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown(80).show(); //Drop down the subnav on hover
 
		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.subnav").slideUp(80); //When the mouse hovers out of the subnav, move it back up
		});
 
		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});	

	// ### HOME / INDEX
	if ($('div#blog_hl').length > 0){
		// *** Home newslist Box nav
		setupHomeBlogHlNav();
		setupBlogHl();
		startTimer();
		//openBlogHl(0);
	}
		
});


	// ### HOME / INDEX
function setupHomeBlogHlNav(){
	$('img.nav_circle').hover(function(event){
		var num = $(this).attr('name').split('_').slice(-1);
		openBlogHl(parseInt(num));
	});    
}
function openBlogHl(n){
	curBlogHlInd = n;
	if (curBlogHlInd > blogHlTab.length - 1)
		curBlogHlInd = 0;
	if (curBlogHlInd < 0)
		curBlogHlInd = blogHlTab.length - 1;
	
	hideBlogHl();
	resetTimer();
}
function nextBlogHl(){
	openBlogHl(curBlogHlInd + 1);
	
}
function startTimer(){ 
	bannerTimer = setTimeout('nextBlogHl()', 9000); 
}
function resetTimer(){ 
	clearTimeout ( bannerTimer ); 
	startTimer(); 
}

function hideBlogHl(){
 $('div#blog_hl').fadeOut("fast", setupBlogHl); // schowaj a nastepnie ustaw nowe
}
function setupBlogHl(){
	$('img.nav_circle').attr('src', '/local/img/blog_hl_nav_circle.gif'); // wszystkie circle zamieniam na czarne
	var selName = 'div#blog_hl_nav_circle_' + curBlogHlInd + ' img.nav_circle'; // wybrane kolko
	$(selName).attr('src', '/local/img/blog_hl_nav_circle_active.gif') // zmieniam na kolor
	
	var title = blogHlTab[curBlogHlInd].title;
	var subtitle = blogHlTab[curBlogHlInd].subtitle;
	var info = blogHlTab[curBlogHlInd].info;
	var url = blogHlTab[curBlogHlInd].url;
	var image = blogHlTab[curBlogHlInd].image;
	var number = curBlogHlInd + 1;
	if (number < 10){
		number = '0' + number;
	}
	$('div.blog_hl_img').html('<a href="' + url + '"><img src="' + image +'" border="0" alt="' + title + '" /></a>');
	$('div.blog_hl_number').html(number);
	$('div.blog_hl_title').html('<a href="' + url + '" class="nostyle nocolor">' + title + '</a>');
	$('div.blog_hl_subtitle').html('<a href="' + url + '" class="nostyle nocolor">' + subtitle + '</a>');
	$('div.blog_hl_info').html('<a href="' + url + '" class="nostyle nocolor">' + info + '</a>');
	
	$('div#blog_hl').fadeIn("fast");	
}



