function scaleIMG (obj) {
	if (obj.width > 570) {
		makeIMGLink(obj, obj.width, obj.height);
		obj.width = 570;
	}
	else if (obj.height > 500) {
		makeIMGLink(obj, obj.width, obj.height);
		obj.height = 500;
	} 
}

function makeIMGLink (obj, width, height) {
	obj.style.cursor = "pointer";
	obj.onclick = function () {
		window.open(obj.src, 'IMGPopup', 'location=0, status=0, width='+(width*1+20)+', height='+(height*1+20));
	}
}

var base = (document.getElementsByTagName ('BASE')[0] && document.getElementsByTagName( 'BASE')[0].href) || location.href
function goTo (url) {
	location.href = base+url;
}
// popup Yobi-link
function about () {
	window.open('index/about/', 'AboutYobi', 'width=400,height=130');
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
function money (amount) {
    amount = Math.round(parseFloat(amount));
    var american = addCommas(amount.toFixed(2));
    var europe = american.replace(/,/g, '|');
    var europe = europe.replace(/\.00/, ',-');
    return '&euro;'+europe.replace(/\|/g, '.');
}

function showint (amount) {
    amount = parseInt(amount);
    var american = addCommas(amount);
    var europe = american.replace(/,/g, '.');
    return europe;
}

var timer = null;
function startMenuMouseover () {
	clearTimeout(timer);
	timer = setTimeout(function () {
		if (typeof jQuery=='undefined') {
			$('menu_overlay').show();
		}
		else {
			$('#menu_overlay').show();
		}
	}, 250);
}
function endMenuMouseover () {
	clearTimeout(timer);
	timer = setTimeout(function () {
		if (typeof jQuery=='undefined') {
			$('menu_overlay').hide();
		}
		else {
			$('#menu_overlay').hide();
		}
	}, 250);
}
function startMenuOverlayMouseover () {
	clearTimeout(timer);
}
function endMenuOverlayMouseover () {
	clearTimeout(timer);
	timer = setTimeout(function () {
		$('#menu_overlay').hide();
	}, 250);
}
var serverTimestamp = 0;
function updateClock (h, m, s, timestamp) {
	serverTimestamp = timestamp;

    if (s == 59) {
        s = 0;
        if (m == 59) {
            h = h+1;
            m = 0;
        }
        else {
            m = m+1;
        }
    }
    else {
        s = s+1;
    }
    
	timestamp = timestamp+1;
    setTimeout(function () {
        updateClock(h, m, s, timestamp);
    }, 1000);
    
	$('#clock').html(zeroPad(h,2)+':'+zeroPad(m,2)+'<b>\''+zeroPad(s,2)+'</b>');
}
function zeroPad (num,count) {
	var numZeropad = num + '';
	while (numZeropad.length < count) {
		numZeropad = "0" + numZeropad;
	}
	return numZeropad;
}


function stdTimer (element, timeleft) {
	if (typeof jQuery=='undefined') {
		$(element+'_min').update(Math.floor(timeleft/60));
		$(element+'_sec').update(timeleft%60);
	}
	else {
		$('#'+element+'_min').text(Math.floor(timeleft/60));
		$('#'+element+'_sec').text(timeleft%60);
	}
	
	if (timeleft > 1) {
		setTimeout('stdTimer("'+element+'", '+(timeleft-1)+')', 1000);
	}
	else {
		if (typeof jQuery=='undefined') {
			$(element).hide();
		}
		else {
			$('#'+element).fadeOut();
		}
	}
}

function protTimer (sec) {
	if (sec>0) {
		t=Math.floor(sec/60)+'m '+(sec%60)+'s';
		t2='Je hebt nog '+Math.floor(sec/60)+' minuten en '+(sec%60)+' seconden bescherming';
	}
	else {
		t=sec+'s';
		t2='Je hebt nog '+sec+' seconden bescherming';
	} 
	$('div.protectiontimer a').text(t);
	$('div.protectiontimer a').attr('title', t2);
	
	if (sec>0) {
		setTimeout('protTimer('+(sec-1)+')', 1000);
	}
	else {
		$('div.protectiontimer').remove();
	}
}
