//############## NEWS SLIDE SHOW ############
var snum = $("#lastnews li").length;
var sheight = $("#lastnews li").height();
var sstop=10000;
var sspeed=1000;
if(snum>1){var st = setTimeout("sliderShow()", sstop);}
function sliderGoTo(id)
{
	$("#lastnews li").removeClass('on');
	$("#lastnews li:eq("+(id-1)+")").addClass('on');
	$("#lastnews ul").animate({"marginTop": "-="+sheight+"px"}, sspeed);
	clearTimeout(st);
	st = setTimeout("sliderShow()", sstop);
}
function sliderShow()
{
	var id = $("#lastnews li").index($("#lastnews .on")) + 2;
	if (id >= snum) {$("#lastnews ul").animate({"marginTop": "0px"}, 500, '', function() {st = setTimeout("sliderGoTo(1)", sstop);});}
	else {sliderGoTo(id);}
}
//##########################
//############## CUST SLIDE SHOW ############
var cnum = $("#custblock li").length;
var cheight = $("#custblock li").height()+20;
var cstop=5000;
var cspeed=1000;
if(cnum>1){var cst = setTimeout("custSliderShow()", cstop);}
function custSliderGoTo(id)
{
	$("#custblock li").removeClass('on');
	$("#custblock li:eq("+(id-1)+")").addClass('on');
	$("#custblock ul").animate({"marginTop": "-="+cheight+"px"}, cspeed);
	clearTimeout(cst);
	cst = setTimeout("custSliderShow()", cstop);
}
function custSliderShow()
{
	var id = $("#custblock li").index($("#custblock .on")) + 2;
	if (id >= cnum) {$("#custblock ul").animate({"marginTop": "0px"}, 1, '', function() {cst = setTimeout("custSliderGoTo(1)", cstop);});}
	else {custSliderGoTo(id);}
}
//##########################
function setSelectedMenu(el)
{
	$(".menu a").removeClass("s");
	$(el).addClass("s").blur();
}
function jqScrollTo(target, more)
{
	var top = target.offset().top + more;
	$('html,body').animate({scrollTop: top}, 1000);
	return false;
}
function verifyDelete()
{
	if (confirm("Are you sure you want to delete?")){
		return true;
	} else {
		return false;
	}
}
function initChartSlider()
{
	$('#chart a').bind('click', function() {
		$(this).next().slideToggle(300);
	});
}
//Tooltip
function initTooltip()
{
	$('a[rel=tooltip]').unbind().bind('mouseover', function(e){
		var tip = $(this).attr('title');	
		$(this).attr('title','').append('<div id="tooltip">' + tip + '</div>');
		$('#tooltip').fadeTo(10,0.85);
	}).bind('mousemove', function(e){
		$('#tooltip').css('top', e.pageY+10).css('left', e.pageX+20);
	}).bind('mouseout', function(){
		$(this).attr('title',$('#tooltip').html()).children('#tooltip').remove();
	});
}
initTooltip();

function startUpload()
{
	document.getElementById('loadingarea').innerHTML = '<center><img src="image/uploading.gif"></center>';
	document.getElementById('uparea').style.display = "none";
	document.getElementById('loadingarea').style.display = "inline";
	document.getElementById('statusarea').style.display = "none";
	return true;
}

function show_modal_orgchart(ext, width, height)
{
	if (typeof(width) == 'undefined') { width=600; }
	if (typeof(height) == 'undefined') { height=500; }
	var d = new Date();
	d = d.getTime();
	$("#modal_content").html('<p style="text-align: center"><img src="upload/organization_chart.'+ext+'?'+d+'" width="'+width+'" height="'+height+'" tag="organization chart" /></p>');
	var dw = $(document).width();
	var dh = $(document).height();
	if (width >= dw) {width = dw - 100;}
	if (height >= dh) {height = dh - 140;}
	width += 30;
	height += 45;
	$("#loading").css("height", dh).css("opacity", 0.0).css("display", "block").fadeTo(700, 0.5);
	$("#modal_content").css("height",height-40+"px");
	$("#modal_win").css({"width": width+"px", "height": height+"px", "top": $(window).scrollTop() + 50 + "px", "left": (dw - width) / 2 - 15 + "px", "display":"block"});
}
function show_modal_licence(name)
{
	width=600;
	height=447;
	var d = new Date();
	d = d.getTime();
	$("#modal_content").html('<a href="image/cert/'+ name +'" title="Click here to view full size" target="_blank"><p style="text-align: center"><img src="image/cert/'+name+'?'+d+'" width="'+width+'" height="'+height+'" tag="Certificate" /></a></p>');
	var dw = $(document).width();
	var dh = $(document).height();
	width += 30;
	height += 45;
	$("#loading").css("height", dh).css("opacity", 0.0).css("display", "block").fadeTo(700, 0.5);
	$("#modal_content").css("height",height-40+"px");
	$("#modal_win").css({"width": width+"px", "height": height+"px", "top": $(window).scrollTop() + 50 + "px", "left": (dw - width) / 2 - 15 + "px", "display":"block"});
}
function hide_modal()
{
	$("#loading").fadeTo(500, 0, function() { $(this).css("display", "none"); });
	$("#modal_win").css("display","none");
}