var actuele_vacatures = '/templates/generated/actueel.gen.html';

$(document).ready(function(){
    $('#topbanen li').each(function(i,el){
        var count = $(this).text().length;
        if (count > 85) {
            var chop = $(this).find('span').text().length - (count-85);
            var val = $(this).find('span').text().substr(0,chop);
            $(this).find('span').text(val+'...');
        }
    });
    
    $('#search-werkgevers input').bind({
        focus: function() {
            if ($(this).attr('name') == $(this).attr('value')) {
                $(this).attr('value','');
            }
        },
        blur: function() {
            if ($(this).attr('value') == '') {
                $(this).attr('value',$(this).attr('name'));
            }
        }
    })
	if ($('.jobOpeningList').length > 0) {
		var vacatureCount = 0;
		$('.jobOpeningList').attr('id', 'list0').load(actuele_vacatures, '', function() {
			function scrollHandler(){
				var scrollTo;
				scrollTo = -$('#list0 li:eq(1)').position().top;
				$('#list0').animate({top: scrollTo}, 2000, 'linear', function() {
					$('#list0 li:first').appendTo('#list0'); //push the first element on the end
					$('#list0').css('top', 0); //make sure the list doesn't move
					scrollHandler();
				});
			}
			scrollHandler();
			$('#list0').hover(function() {
				$('#list0').stop();
			}, function() {
				scrollHandler();
			});
			/* $('#prevJobList').click(function() { // disabled by request
				$('#list0 li:gt(10)').prependTo('#list0');
				return false;
			});
			$('#nextJobList').click(function() {
				$('#list0 li:lt(4)').appendTo('#list0');
				return false;
			}); */
		});
	}
});

function toggle_cvstaffel()
{
	var sp = null;
	if (document.getElementById)
		sp = document.getElementById('cvstaffel');
	else if (document.all)
		sp = document.all['cvstaffel'];
	if (sp)
	{
		sp.style.display = (sp.style.display == '') ? 'none' : '';
	}
	return false;
}

function productpopup(name)
{
    var width = 500;
    var height = 580;
    var x = (screen.width - width)/2;
    var y = (screen.height - height)/2;
    var win = window.open('/werkgever/?action=productinfo&popup=1&name=' + name, 'productinfopopup', 'left='+x+',top='+y+',width='+width+',height='+height+',menubar=no,status=no,toolbar=no,scrolling');
    win.focus();
    return false;
}

function productpopup(type)
{
    // Het is hier geen popup
    document.location.href='/werkgever/?action=productinfo&name=' + type;
    return false;

}

function doPassVar(args)
{
	window.document.bereiksMeterObj.SetVariable("tweenEnd", args);
}

function initVars()
{
   window.document.bereiksMeterObj.SetVariable("startScore", uitslag);
   window.document.bereiksMeterObj.SetVariable("minReach",	0);
   window.document.bereiksMeterObj.SetVariable("maxReach",	10); //%[uitslag_max]%);
   window.document.bereiksMeterObj.SetVariable("chartLabel", 'effectiviteit'); //"gem.views/dag");
}

function productpopupsmall(type)
{
    var width = 800;
    var height = 580;
    var x = (screen.width - width)/2;
    var y = (screen.height - height)/2;
    var win = window.open('/werkgever/?action=productinfo&popup=1&name=' + type, 'productinfopopup', 'left='+x+',top='+y+',width='+width+',height='+height+',menubar=no,status=no,toolbar=no,scrollbars,resizable=yes');
    win.focus();
    return false;
}
