var scroller_current = 1;

function init()
{
	$('.top_links > ul > li:eq(0)').addClass("first-child");

	/* font vergroot/verklein */
	var change_fields = new Array('#content_field', '#content_field h1,#content_field h2,#content_field h3,#content_field span .kop1, #content_field span .kop2','.menu a');
	$("#font_plus").click(function(){increase_font(change_fields);});
	$("#font_min").click(function(){decrease_font(change_fields);});

	//menu activatie
	$('.menu li').hoverIntent({sensitivity: 7, interval: 100 ,over: menu_slidedown, timeout: 100, out: menu_slideup});

	$('.contentTop .buttons a').click(button_handler);
	$('.zoeken .input_text').focus(clear_zoek_tekst);

	// kleine fix om geen fouten te krijgen op external links
	externalLinks();
}

function scroller_pause()	{$('#scroller .foto').cycle('pause')}
function scroller_resume()	{$('#scroller .foto').cycle('resume')}
function scroller_before(){
	//alert(arguments[0].className+ ' ' +scroller_current+' '+this.className);
	if (scroller_current != this.className)
	{
		scroller_current = this.className;
        var old = arguments[0].className;
		$('#scroller .tekst .'+arguments[0].className+' *').fadeOut('normal', function(){$('#scroller .tekst .'+old ).css('display', 'none')});
	}
}
function scroller_after(){
    //alert(scroller_current);
	if (scroller_current == this.className)
	{
	    $('#scroller .tekst .'+scroller_current).show();
		$('#scroller .tekst .'+this.className+' *').fadeIn('normal');
	}
}
function start_scroller() {
	$('#scroller .tekst .'+scroller_current).show();
   // $('#scroller .tekst span:visible ').not('.'+scroller_current).css('display','none');
	$('#scroller .tekst span:visible ').not('.'+scroller_current).children('*').hide();
	$('#scroller .foto').cycle({fx:'fade', speed:'normal', timeout:5000, pager: '#scroller .items', before:scroller_before, after:scroller_after});
	$('#scroller .items a').hoverIntent(
		function(){
			if (scroller_current != $(this).html()){
				$(this).click();
			}
		},
		dummy_function
	)
	$('#scroller').hoverIntent(scroller_pause,scroller_resume);
}
function clear_zoek_tekst()
{
    if ($(this).attr('value') == 'Ik zoek naar...')
    {
        $(this).attr('value','');
    }
}
function fix_height(){
	/*$('.insideOutsideContainer').height("auto");
    if (($('.insideContainer').height()) < $('.footer').offset().top)
    {
	    $('.insideOutsideContainer').height($('.footer').offset().top)
    }*/
}

function button_handler(){
	var id = $(this).attr('id');

	if (id == 'print'){
		PrintContent();
	}
}


function menu_slidedown()
{
	$(this).children("ul").slideDown("fast");
}

function menu_slideup()
{
	$(this).children("ul").slideUp("fast");
}

function increase_font (element)
{
	var current_size = '';
	var cur_size_num = 0;
	var unit = '';

	for (j=0;j<element.length;j++)
	{
	    current_size = $(element[j]).css('font-size');
		cur_size_num = parseFloat(current_size, 10);
		unit = current_size.slice(-2);
		cur_size_num = cur_size_num +2;
		current_size = $(element[j]).css('font-size', cur_size_num + unit);
	}

	return false;
}

function decrease_font (element)
{
	var cur_size_num = 0;
	var unit = '';
    var i;
    var j;
	for (j=0;j<element.length;j++)
	{
	    current_size = $(element[j]+', '+element[j]+' a').css('font-size');
		cur_size_num = parseFloat(current_size, 10);
		unit = current_size.slice(-2);
		cur_size_num = cur_size_num -2;
		current_size = $(element[j]).css('font-size', cur_size_num + unit);
	}
	return false;
}

function PrintContent()
{
    var content_value = document.getElementById("content_field").innerHTML;
    var docprint = window.open("","","toolbar=no,location=no,directories=yes,menubar=no,scrollbars=yes,width=650, height=600, left=100, top=25");
    docprint.document.open();
    docprint.document.write('<html><head><title>Kamermuziek</title><link type="text/css" rel="stylesheet" href="style/print.css" /></head><body onLoad="self.print();" id="printwindow"><div>' + content_value + '</div></body></html>');
    docprint.document.close();
    docprint.focus();
}

function dummy_function()
{
	return false;
}
function externalLinks() {
    $('a').each(function()
    {
        if ($(this).attr('rel') == "external")
        {
            $(this).attr('target','_blank');
        }
    });
}
