function changeTopClass(obj) {
	obj.className = "topOver";
}
function restoreTopClass(obj) {
	obj.className = "topNormal";
}
function changeTopClass02(obj)
{
	obj.className = "menuOverLev03";
}
function restoreTopClass02(obj)
{
	obj.className = "menuNormalLev03";
}
function changeTopClass03(obj){
	obj.className = "splashOver";
}
function restoreTopClass03(obj)
{
obj.className = "splashNormal";
}

function changeTopClass04(obj){
obj.className = "splashROver";
}
function restoreTopClass04(obj)
{
obj.className = "splashRNormal";
}

function toggleMenu() {
	if($('ul.menu_body').css('display') == 'none') {
		var h = $('ul.menu_body').height() + parseInt($('ul.menu_body').css('paddingTop')) + parseInt($('ul.menu_body').css('paddingBottom'));
		$('ul.menu_body').css('marginTop', -h);
		$('ul.menu_body').css('display', 'block');
	}
	$('ul.menu_body').blindToggle(1200, function () {
			$('#v_toggle').toggleClass('open');
			if($('#v_toggle').hasClass('open')) {
				$('#v_toggle').html(menuslide_word[0]);
			} else {
				$('#v_toggle').html(menuslide_word[1]);
			}
      });
}

jQuery.fn.blindToggle = function(speed, easing, callback) {
	var h = this.height() + parseInt(this.css('paddingTop')) + parseInt(this.css('paddingBottom'));
	return this.animate({marginTop: parseInt(this.css('marginTop')) < 0 ? 0 : -h}, speed, easing, callback);
};

function showFlashItem(id) {
	jQuery(".hp_flashcarroussel_item").hide();
	jQuery("#hp_flash_" + id).show();
	jQuery(".flashNavL a").removeClass('active');
	jQuery("#hp_flash_link_" + id).addClass('active');
}

function showFlashItemPrepare(id) {
	if(cPlaying) clearTimeout(cTimer);
	showFlashItem(id);
	for (var i = 0; i < cItems.length; i++) {
		if(cItems[i] == id) cCurrentActive = i + 1;
	}
	if(cPlaying) {
		cTimer = setTimeout("playHPCarrousel()", cHold * 1000);
	}
}

function playHPCarrousel() {
	if(cPlaying) {
		if(cCurrentActive == cItems.length) {
			showFlashItem(cItems[0]);
			cCurrentActive = 1;
		} else {
			showFlashItem(cItems[cCurrentActive]);
			cCurrentActive += 1;
		}
		cTimer = setTimeout("playHPCarrousel()", cInterval * 1000);
	}
}

function showNextHPCarrousel() {
	var k = cCurrentActive + 1;
	if(cCurrentActive == cItems.length) k = 1;
	showFlashItemPrepare(cItems[k - 1]);
}

function showPrevHPCarrousel() {
	var k = cCurrentActive - 1;
	if(cCurrentActive == 1) k = cItems.length;
	showFlashItemPrepare(cItems[k - 1]);
}

function hoverCarrouselImg(img, s) {
	if(s == 'over') img.src = img.src.replace('.gif', 'Hover.gif');
	if(s == 'out') img.src = img.src.replace('Hover.gif', '.gif');
}

function toggleHPCarrousel() {
	if(cPlaying) {
		clearTimeout(cTimer);
		cPlaying = false;
		jQuery("#hp_flash_button_playpause").attr('src', image_base_path + 'btn_bannerPlay.gif');
	} else {
		cPlaying = true;
		playHPCarrousel();
		jQuery("#hp_flash_button_playpause").attr('src', image_base_path + 'btn_bannerBreak.gif');
	}
}

function showListItem(id) {
	jQuery(".hp_listitem_item").hide();
	jQuery("#hp_listitem_" + id).show();
	jQuery(".hp_listitem_li a").removeClass('active');
	jQuery("#hp_listitem_link_" + id).addClass('active');
}

function showListItemPrepare(id) {
	clearTimeout(wTimer);
	showListItem(id);
	for (var i = 0; i < wItems.length; i++) {
		if(wItems[i] == id) wCurrentActive = i + 1;
	}
	wTimer = setTimeout("playCenteaCarrousel()", wHold * 1000);
}

function playCenteaCarrousel() {
	if(wCurrentActive == wItems.length) {
		showListItem(wItems[0]);
		wCurrentActive = 1;
	} else {
		showListItem(wItems[wCurrentActive]);
		wCurrentActive += 1;
	}
	wTimer = setTimeout("playCenteaCarrousel()", wInterval * 1000);
}

function showAgentDay(id) {
	jQuery(".scedule").hide();
	jQuery("#agent_day_table_" + id).show();
	jQuery(".day a").removeClass('active');
	jQuery("#agent_day_link_" + id).addClass('active');
}

function triggerSubmitAgentForm() {
	prepareAgentForm(document.searchagent);
	document.searchagent.submit();
}

function prepareAgentForm(oForm) {
	var bCity = false;
	var aZipCity = oForm.searchstring.value;
	if (aZipCity.length == 4) {
			var numberString = "0123456789";
			for (var i = 0; i<aZipCity.length; i++) {
					var char = aZipCity.charAt(i);
					if (numberString.indexOf(char) < 0) {
							var bCity = true;
							break;
					}
			}
	} else {
			bCity = true;
	}
	if(bCity) {
		oForm.city.value = oForm.searchstring.value;
		oForm.zip.value = '';
	} else {
		oForm.zip.value = oForm.searchstring.value;
		oForm.city.value = '';
	}
	NgPopup_other('','agentpopupwindow','720','500','toolbar=no,status=no,location=no');
}

function findZipOrCity(sLang) { var aZipCity = document.searchagent.searchstring.value;searchAgentInGeo(aZipCity, sLang);}

function searchAgentInGeo(aZipCity,aLang) {
        var bCity = false;

        if (aZipCity.length == 4) {
                var numberString = "0123456789";
                for (var i = 0; i<aZipCity.length; i++) {
                        var char = aZipCity.charAt(i);
                        if (numberString.indexOf(char) < 0) {
                                var bCity = true;
                                break;
                        }
                }
        } else {
                bCity = true;
        }

        var nr = Math.random() * 1000;
        nr = Math.round(nr);
        var nameForPopup = aZipCity + nr;
        
		if (bCity) {
			var sPopuUrl = 'http://services4.geochooser.com/Geochooser.asp?client=centea&language='+aLang;
			if(aZipCity.length != 0) sPopuUrl += '&city=' + aZipCity;
			NgPopup_other(sPopuUrl,nameForPopup,'720','500','toolbar=no,status=no,location=no');
        } else {
			NgPopup_other('http://services4.geochooser.com/Geochooser.asp?client=centea&language='+aLang+'&zip='
 + aZipCity,nameForPopup,'720','500','toolbar=no,status=no,location=no');
        }
		
		/*$.post("test.php", { func: "getNameAndTime" }, function(data){
    alert(data.name); // John
    console.log(data.time); //  2pm
  });*/
}

$(document).ready(function() {
	var a = menuslide_height.split(",");
	var max_count = 0;
	for(var i=0;i<a.length; i++) {
		if(a[i] > max_count) max_count = a[i];
	}
	$('ul.menu_body').css('height', Math.round(((max_count * 1.7) + 1.2)*10)/10 + 'em');
	var pic1 = new Image();
	pic1.src = image_base_path + "ico_rightPane.gif";
	var pic2 = new Image();
	pic2.src = image_base_path + "ico_rightPaneOpen.gif"; 
});

$.fn.highlight = function(what,spanClass) {
    return this.each(function(){
        var container = this,
		content = container.innerHTML,
		pattern = new RegExp('(>[^<.]*)(' + what + ')([^<.]*)', 'gi'),
		replaceWith = '$1<span class="' + spanClass + '">$2</span>$3';
		//var a = pattern.exec(content);
		var highlighted = content.replace(pattern,replaceWith);
		//if(highlighted.indexOf('ontwikkelingen') > 0) alert(a.join('|'));
        container.innerHTML = highlighted;
    });
}