// *********************
// *     Navigatie     *
// *********************

$(document).ready(function() {
    $("#navi a.special").hover(function() {
        $("#navi a.special + .infospecial").show();
    }, function() {
        $("#navi a.special + .infospecial").hide();
    });

    $("#navi span").not(".active").not(".open").siblings("ul").hide();
    $("#navi span").not(".active").not(".open").click(function() {
        $(this).toggleClass("slide");
        $(this).siblings("ul").slideToggle(300);
    });
});

// *******************************
// *     Zoekfunctionaliteit     *
// *******************************

$(document).ready(function() {
    $("div[name='googleSearch']").each(function() {
        $(":text", this).each(function() {
            $(this).watermark($(this).attr("title"));
        }).keypress(function(e) {
            if ((e.which ? e.which : e.keyCode) == 13) {
                GoogleSearch($(this).val(), $(this).siblings("input[name='nid']").val());
                return false;
            }
        });

        $(":button", this).click(function() {
            GoogleSearch($(this).siblings(":text").val(), $(this).siblings("input[name='nid']").val());
        });
    });

});

function GoogleSearch(q, n) {
    if (q.length != 0) {
        var u = location.pathname.replace(/\/(nl|fr)\/_(build|immo|task)\/.+/i, "/$1/_$2/search.aspx");
        location.href = u + "?nid=" + n + "&q=" + encodeURI(q);
    }
}

// **************************
// *     Bottom banners     *
// **************************

$(document).ready(function() {
    $("#bottomBannersSlides").each(function() {
        var s = parseInt(readCookie("BannerSet"));
        if (isNaN(s)) s = 0;
        $(this).cycle({ timeout: 0, prev: "#bb_prev", next: "#bb_next", startingSlide: s});
    });
});

// *****************************
// *     Algemene functies     *
// *****************************

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function toggleNav(obj, toggleId) 
{
	if(document.all)
	{
		if(document.all[toggleId])
		{
			toggleObj = document.all[toggleId];
			toggleObj.style.display = (toggleObj.style.display == 'none')?'block': 'none';
		}
		else 
			return false;
	}
	else
	{
		if(document.getElementById(toggleId))
		{
			toggleObj = document.getElementById(toggleId);
			toggleObj.style.display = (toggleObj.style.display == 'none')?'block': 'none';
		}
		else
			return false;
	}
	var img = obj.childNodes[0];
	img.className = (img.className=='toggleOpen'?'toggleClose':'toggleOpen');
	return false;
}

function emailCloak() {
		if (document.getElementById) {
			var alltags = document.all? document.all : document.getElementsByTagName("*");
			for (i=0; i < alltags.length; i++) {
			  if (alltags[i].className == "emailCloak") {
			  	var oldText = alltags[i].firstChild;
			  	var emailAddress = alltags[i].firstChild.nodeValue;
			  	var user = emailAddress.substring(0, emailAddress.indexOf("("));
			  	var website = emailAddress.substring(emailAddress.indexOf(")")+1, emailAddress.length);
			  	var newText = user+"@"+website;
			  	var a = document.createElement("a");
			  	a.href = "mailto:"+newText;
				var address = document.createTextNode(newText);
				a.appendChild(address);
				alltags[i].replaceChild(a,oldText);
			  }
			}
		}
	}
	window.onload = emailCloak;
	

function MM_showHideLayers() { //v6.0
		  var i,p,v,obj,args=MM_showHideLayers.arguments;
		  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
			if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
			obj.visibility=v; }
		}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function jumpTo (link)
   {
   var new_url=link;
   if (  (new_url != "")  &&  (new_url != null)  )
      window.location=new_url;
}




