//onload
$(document).ready(function() {
	$('div.show-hide-content').hide();
	$('a.moreToggle').show('slow');
	
	$(document).pngFix();
	$("#accordion").accordion({ header: '.accordionHeader', active:true });
	
	
	// shows the show-hide-content DIV on clicking the link with a class of "moreToggle"
	$('a.moreToggle').click(function() {
	  
	  var that = $(this);
	  that.parent().next('div.show-hide-content').show(400);
	  that.hide();
	  that.parent().children('a.lessToggle').show();
	  return false;
	  });

	$('a.lessToggle').click(function() {
	  
	  var that = $(this);
	  that.parent().next('div.show-hide-content').hide(400);
	   that.hide();
	  that.parent().children('a.moreToggle').show();
	  return false;
	  });



	//enable fontsize
	$("#font-size").show();
	setSize(getFontCookie());
	
   
   $("#slider").easySlider({
				loop: true,
				continuous: true, 
				autoplayDuration:6500,
				autogeneratePagination: true
   
			});
   // showing the selected foerderprogramm, depending on url-param "foe"
   var foe = getURLParam('foe');
   if (foe=='') {
        foe = 'foe1';
    }
   show(foe);
   
});	

/** show foerderprogramme depending on given param, add/remove active-class in subnav and choose appropiate select-option
* @param sel either string with class of dl or select-field with option-value as class
*/
function show(sel) {
	var current = "";
	var elements = $('.article');
    
    //depending on type of sel-argument, can be select-object (to get value) or just class-string
    if (typeof sel == "string") {
        current = sel;
    } else {
        current = $(sel).val();
        
        var subnav = $('ul#subnav li');
        subnav.find('a span').removeClass('active');
        subnav.find('a[onclick*='+current+'] span').addClass("active");
    }
    
    // set correct value select-object if value was string
    var options = elements.parent().find('p .select-sub option[value='+current+']');
    options.attr('selected','selected');
    
    // hide all lists, only if select-field exists
    if (elements.parent().find('p .select-sub').length > 0) {
		elements.hide();
		elements.addClass('none');
		// show selected list
		elements.filter('.'+current).removeClass('none').fadeIn('slow');
	}
    
    // set/unset class active in subnav
	if (show.arguments.length>1) {
		var that = $(show.arguments[1]);
		that.parents('ul').find('a span').removeClass('active');
		that.children('span').addClass('active');
	}
	
	return false;
}

// opening pages via selectbox
function gotoPage(href,sel) {
    var current = $(sel).val();
    if (current!='') {
        window.location.href=href+current;
    }
}

// opening flipbooks in iframe-overlay
function openFlipbook(obj) {
    var t = null;
	var a = $(obj).val();
	var g = false;
	if (a!="") {
        tb_show(t,a,g);
    }
}

// re-insert form-default-value when empty and user leaves field
function inputBlur(obj,val) {
    if (obj.value=='') {
        obj.value=val;
    }
}
// empty form-field of default-value when user wants to enter text
function inputFocus(obj,val) {
    if (obj.value==val) {
        obj.value='';
    }
    obj.select();
}

// setting font-size globally
function setSize(fontSize){
	var defaultSize = 12;
	

	if(fontSize == '' || isNaN(fontSize)) {
		fontSize = defaultSize;	
	}
	$("body").css('font-size', fontSize + 'px');
	
	// setting cookie
	var cur = new Date();
	var expires = new Date(cur.getTime()+(60*60*24*365*1000));
	document.cookie = 'fontsize='+fontSize+'; path=/go-international; expires='+expires.toGMTString();
	return false;
}

function getFontCookie() {
	var regex = /fontsize=([\w\s\.]*)/;
	regex.exec(document.cookie);
	return RegExp.$1;
}

// to get any url-parameter
function getURLParam(strParamName){
    var strReturn = "";
    var strHref = window.location.href;
    if (strHref.indexOf("?") > -1 ) {
        var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
        var aQueryString = strQueryString.split("&");
        for (var iParam = 0; iParam < aQueryString.length; iParam++ ) {
            if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ) {
                var aParam = aQueryString[iParam].split("=");
                strReturn = aParam[1];
                break;
            }
        }
    }
    return unescape(strReturn);
}