$(function(){
	$('button').button();
	$('.tab-navigation li').click(function(){
		tab_id = $(this).attr('id').split('-')[2];
		tcc_show_tab(tab_id);
	});
	if(location.hash.slice(1).length > 0 && location.hash.slice(1)[0] == 't'){
		tcc_show_tab(location.hash.slice(1).split('-')[1]);
	}
	$('.slideshow').cycle({
		timeout: 5500,
		before: change_slideshow_number
	});
});

function change_slideshow_number(){

	$buttons = $(this).parent().parent().find('.slideshow-buttons');
	var _index = $(this).index();
	$buttons.find('.sb-na').removeClass('sb-na');
	$buttons.find('.sb-' + (_index+1)).addClass('sb-na');
	
}

function tcc_show_tab(id){
	create_redirect_cancel_all();
	$('.tab-navigation .selected').removeClass('selected');
	$('#tcc-n-' + id).addClass('selected');
	$('.tab-content .tab:visible').hide();
	$('#tcc-' + id).removeClass('hidden').show();
	$('#tcc-' + id).trigger('create_redirect');
}
function redirect(url){
	document.location.href = url;
}
var create_redirect_count = 0;
var create_redirect_opts = [];
var create_redirect_timer = null;
function create_redirect(target, url, title, str, time){
	$(target).html('Preusmerjam - ' + title + ' (' + url + ') - <span id="create_redirect-' + create_redirect_count + '">' + time + '</span> s');
	create_redirect_opts[create_redirect_count] = [create_redirect_count, url, title, str, time, true];
	create_redirect_count++;
	if(create_redirect_timer == null){
		create_redirect_timer = setTimeout("create_redirect_check()", 1000);
	}
}
function create_redirect_check(){
	for(var i in create_redirect_opts){
		if(create_redirect_opts[i][5] && create_redirect_opts[i][4] == 1){
			redirect(create_redirect_opts[i][1]);
		}else{
			create_redirect_opts[i][4]--;
			$('#create_redirect-' + create_redirect_opts[i][0]).text(create_redirect_opts[i][4]);
		}
	}
	setTimeout("create_redirect_check()", 1000);
}
function create_redirect_cancel_all(){
	for(var i in create_redirect_opts){
		if(create_redirect_opts[i][5]){
			create_redirect_opts[i][5] = false;
		}
	}
}






