
$.preloadImages=function(){
	for(var i=0;i<arguments.length;i++)
	{
		$("<img>").attr("src",arguments[i]);
	}
};

$.preloadImages("http://www.costarentalsonline.com/img/shortlist_loader2.gif",
				"http://www.costarentalsonline.com/img/shortlist_loader2hu.gif",				
				"http://www.costarentalsonline.com/img/button_cart-active.gif",
				"http://www.costarentalsonline.com/img/button_carthu-active.gif",
				"http://www.costarentalsonline.com/img/button_more-active.gif",
				"http://www.costarentalsonline.com/img/button_morehu-active.gif",
				"http://www.costarentalsonline.com/img/details_button_download-active.gif",
				"http://www.costarentalsonline.com/img/details_button_print-active.gif",
				"http://www.costarentalsonline.com/img/details_button_selection-active.gif",
				"http://www.costarentalsonline.com/img/s_details_button_dloadhu-active.gif",
				"http://www.costarentalsonline.com/img/s_details_button_download-active.gif",
				"http://www.costarentalsonline.com/img/s_details_button_print-active.gif",
				"http://www.costarentalsonline.com/img/s_details_button_printhu-active.gif",
				"http://www.costarentalsonline.com/img/s_details_button_selection-active.gif",
				"http://www.costarentalsonline.com/img/s_details_button_selhu-active.gif",
				"http://www.costarentalsonline.com/img/searchbutton2-active.gif",
				"http://www.costarentalsonline.com/img/searchbutton2hu-active.gif",
				"http://www.costarentalsonline.com/img/searchbutton-active.gif",
				"http://www.costarentalsonline.com/img/sendenquiry2-active.gif",
				"http://www.costarentalsonline.com/img/sendenquiry2hu-active.gif",
				"http://www.costarentalsonline.com/img/sendenquiry-active.gif",
				"http://www.costarentalsonline.com/img/sendenquiryhu-active.gif"				
				);
shortList=function(action,apid,name,price){
	
	var lang = $("#lang").val();
	
	if(lang == "hu") {
		$("#shortlist_container").css("background-image","url(http://www.costarentalsonline.com/img/shortlist_loader2hu.gif)");
	}
	else {
		$("#shortlist_container").css("background-image","url(http://www.costarentalsonline.com/img/shortlist_loader2.gif)");
	}	
	
	$("#shortlist").fadeTo("fast",0.5);
	
	$.ajax({
		   type:"POST",
		   url:"inc/shortlist.php",
		   data:"action="+action+"&apid="+apid+"&name="+name+"&price="+price+"",
		   success:function(data){			   		
			   		if(lang == "hu") {
						$("#shortlist_container").css("background-image","url(http://www.costarentalsonline.com/img/favourites2hu.jpg)");
					}
					else {
						$("#shortlist_container").css("background-image","url(http://www.costarentalsonline.com/img/favourites2.jpg)");
					}
					if(data=="empty")
					{
						if(lang == "hu") {
							$("#shortlist").html("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" id=\"shortlist_table\"><tr><td style=\"background-color:#eeeeee; color:#002f5b\"><p style=\"margin:0; font-weight:bold;\">Kedvenc lakások lista üres!</p><p style=\"margin:5px 0 0 0\">A \"Kedvencekhez\" gombra kattintással lakásokat adhat a listához.</p><p style=\"margin:5px 0 0 0\">Összesen 10 lakást rögzíthet a listán, így egyszer&#369;en, gyorsan és kényelmesen kérhet b&#337;vebb információt több lakásról.</p></td></tr></table>").fadeTo("fast",1);
						}
						else {
							$("#shortlist").html("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" id=\"shortlist_table\"><tr><td style=\"background-color:#eeeeee; color:#002f5b\"><p style=\"margin:0; font-weight:bold;\">Your selection list is empty!</p><p style=\"margin:5px 0 0 0\">Add apartments to your favourites list by clicking the shopping cart icon.</p><p style=\"margin:5px 0 0 0\">You can add up to 10 apartments to your list thus enquiring about multiple apartments becomes really easy and convenient.</p></td></tr></table>").fadeTo("fast",1);
						}						
						$("#enquiry_container").slideUp("fast").hide();
					}
					else 
					{
						$("#shortlist").html(data).fadeTo("fast",1);
						$("#enquiry_container").slideDown("fast");						
					}
				}
			});
};
	
$.fn.popupwindow=function(p){
		
		var profiles=p||{};
		return this.each(function(index){
			var settings,parameters,mysettings,b,a;
			mysettings=(jQuery(this).attr("rel")||"").split(",");
			settings={height:600,width:800,toolbar:0,scrollbars:1,status:0,resizable:1,left:0,top:0,center:1,createnew:1,location:1,menubar:0};
			if(mysettings.length==1&&mysettings[0].split(":").length==1){
				a=mysettings[0];
				if(typeof profiles[a]!="undefined"){
					settings=jQuery.extend(settings,profiles[a]);
				}
			}
		else{
			for(var i=0;i<mysettings.length;i++){
				b=mysettings[i].split(":");
				if(typeof settings[b[0]]!="undefined"&&b.length==2){
					settings[b[0]]=b[1];
				}
				}
			}
		if(settings.center==1){
			settings.top=(screen.height-(settings.height+110))/2;
			settings.left=(screen.width-settings.width)/2;
		}
		parameters="location="+settings.location+",menubar="+settings.menubar+",height="+settings.height+",width="+settings.width+",toolbar="+settings.toolbar+",scrollbars="+settings.scrollbars+",status="+settings.status+",resizable="+settings.resizable+",left="+settings.left+",screenX="+settings.left+",top="+settings.top+",screenY="+settings.top;
		
		$(this).bind("click",function(){
			var name=settings.createnew?"PopUpWindow"+index:"PopUpWindow";
			window.open(this.href,name,parameters).focus();
			return false;
			});
		});
		};
		
$(function(){$(".popupwindow").popupwindow();});

function validEmail(email){
	
	var reg=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(email)===true){
		return true;
	} else {
		return false;
	}
}

function validateEnquiryForm(formData,jqForm,options){
	
	var errors=0;
	var form=jqForm[0];
	var lang = $("#lang").val();
	
	if(lang == "hu") {
		var invalidemail = "Hibás email cím!";
		var missingform = "Kérjük töltse ki a hiányzó mez&#337;ket!";
		var sendingmail = "Üzenet küldése...";
	}
	else {
		var invalidemail = "Invalid email address!";		
		var missingform = "Please fill all required fields!";
		var sendingmail = "Sending mail, please wait...";
	}
	
	if(!form.e_email.value||!validEmail(form.e_email.value))
	{
		$("#txtHint").html('<img src=\"http://www.costarentalsonline.com/img/alert.jpg\" width=\"17\" height=\"17\" style=\"margin-right:5px; margin-bottom:-4px\"><span style=\"color:#4e172a\">'+invalidemail+'</span>');
		errors++;
	}
	
	if(!form.e_name.value||!form.e_phone.value){
		$("#txtHint").html('<img src=\"http://www.costarentalsonline.com/img/alert.jpg\" width=\"17\" height=\"17\" style=\"margin-right:5px; margin-bottom:-4px\"><span style=\"color:#4e172a\">'+missingform+'</span>');
		errors++;
	}

	if(form.e_send2friend && form.e_send2friend.value == "yes")
	{
		if(!form.ef_email.value||!validEmail(form.ef_email.value))
		{$("#txtHint").html('<img src=\"http://www.costarentalsonline.com/img/alert_white.jpg\" width=\"17\" height=\"17\" style=\"margin-right:5px; margin-bottom:-4px\"><span style=\"color:#b4613f\">Invalid email address!</span>');errors++;}			
		if(!form.ef_name.value)
		{$("#txtHint").html('<img src=\"http://www.costarentalsonline.com/img/alert_white.jpg\" width=\"17\" height=\"17\" style=\"margin-right:5px; margin-bottom:-4px\"><span style=\"color:#b4613f\">Please fill all required fields!</span>');errors++;}
	}

	if(errors>=1){
		return false;
	}
	else{
		
		$("#txtHint").css({color:"#00ff6c"});$("#txtHint").html(sendingmail);
		return true;
	}
}

function showResponse(responseText,statusText){
	if(statusText==="success"){
		$('#enquiryform').resetForm();
	}
}

function validateContactForm(formData,jqForm,options){
	var errors=0;
	var form=jqForm[0];
	var lang = $("#lang").val();
	
	if(lang == "hu") {
		var invalidemail = "Hibás email cím!";
		var missingform = "Kérjük töltse ki a hiányzó mez&#337;ket!";
		var sendingmail = "Üzenet küldése...";
	}
	else {
		var invalidemail = "Invalid email address!";		
		var missingform = "Please fill all required fields!";
		var sendingmail = "Sending mail, please wait...";
	}
	
	if(!form.c_email.value||!validEmail(form.c_email.value)){
		
		$("#txtHintEmail").html('<img src=\"http://www.costarentalsonline.com/img/alert_white.jpg\" width=\"17\" height=\"17\" style=\"margin-right:5px; margin-bottom:-4px\"><span style=\"color:#b4613f\">'+invalidemail+'</span>');
		errors++;
	}
	if(!form.c_name.value||!form.c_phone.value){
		$("#txtHintEmail").html('<img src=\"http://www.costarentalsonline.com/img/alert_white.jpg\" width=\"17\" height=\"17\" style=\"margin-right:5px; margin-bottom:-4px\"><span style=\"color:#b4613f\">'+missingform+'</span>');
		errors++;
	}

	if(form.send2friend && form.send2friend.value == "yes")
	{
		if(!form.cf_email.value||!validEmail(form.cf_email.value))
		{$("#txtHintEmail").html('<img src=\"http://www.costarentalsonline.com/img/alert_white.jpg\" width=\"17\" height=\"17\" style=\"margin-right:5px; margin-bottom:-4px\"><span style=\"color:#b4613f\">Invalid email address!</span>');errors++;}			
		if(!form.cf_name.value)
		{$("#txtHintEmail").html('<img src=\"http://www.costarentalsonline.com/img/alert_white.jpg\" width=\"17\" height=\"17\" style=\"margin-right:5px; margin-bottom:-4px\"><span style=\"color:#b4613f\">Please fill all required fields!</span>');errors++;}
	}
	
	if(errors>=1){
		return false;
	}
	else{
		$("#txtHintEmail").css({color:"#20711e"});
		$("#txtHintEmail").html(sendingmail);
		return true;
	}
}

function validateRegisterForm(formData,jqForm,options){
	var errors=0;
	var form=jqForm[0];
	var lang = $("#lang").val();
	
	if(lang == "hu") {
		var invalidemail = "Hibás email cím!";
		var missingform = "Kérjük töltse ki a hiányzó mez&#337;ket!";
		var sendingmail = "Üzenet küldése...";
	}
	else {
		var invalidemail = "Invalid email address!";		
		var missingform = "Please fill all required fields!";
		var sendingmail = "Sending mail, please wait...";
	}
	
	if(!form.r_email.value||!validEmail(form.r_email.value)){
		
		$("#txtHintEmail").html('<img src=\"http://www.costarentalsonline.com/img/alert_white.jpg\" width=\"17\" height=\"17\" style=\"margin-right:5px; margin-bottom:-4px\"><span style=\"color:#b4613f\">'+invalidemail+'</span>');
		errors++;
	}
	if(!form.r_name.value||!form.r_phone.value){
		$("#txtHintEmail").html('<img src=\"http://www.costarentalsonline.com/img/alert_white.jpg\" width=\"17\" height=\"17\" style=\"margin-right:5px; margin-bottom:-4px\"><span style=\"color:#b4613f\">'+missingform+'</span>');
		errors++;
	}

	
	if(errors>=1){
		return false;
	}
	else{
		$("#txtHintEmail").css({color:"#20711e"});
		$("#txtHintEmail").html(sendingmail);
		return true;
	}
}

function validateShortTermForm(formData,jqForm,options){
	var errors=0;
	var form=jqForm[0];
	var lang = $("#lang").val();
	
	if(lang == "hu") {
		var invalidemail = "Hibás email cím!";
		var missingform = "Kérjük töltse ki a hiányzó mez&#337;ket!";
		var sendingmail = "Üzenet küldése...";
	}
	else {
		var invalidemail = "Invalid email address!";		
		var missingform = "Please fill all required fields!";
		var sendingmail = "Sending mail, please wait...";
	}
	
	if(!form.c_email.value||!validEmail(form.c_email.value)){
		
		$("#txtHint").html('<img src=\"http://www.costarentalsonline.com/img/alert_white.jpg\" width=\"17\" height=\"17\" style=\"margin-right:5px; margin-bottom:-4px\"><span style=\"color:#b4613f\">'+invalidemail+'</span>');
		errors++;
	}
	if(!form.c_name.value||!form.c_phone.value){
		$("#txtHint").html('<img src=\"http://www.costarentalsonline.com/img/alert_white.jpg\" width=\"17\" height=\"17\" style=\"margin-right:5px; margin-bottom:-4px\"><span style=\"color:#b4613f\">'+missingform+'</span>');
		errors++;
	}

	
	if(errors>=1){
		return false;
	}
	else{
		$("#txtHint").css({color:"#20711e"});
		$("#txtHint").html(sendingmail);
		return true;
	}
}

function showContactResponse(responseText,statusText){
	if(statusText==="success"){
		$('#contactform').resetForm();
	}
}

$(document).ready(function(){
						   
	$(".rollover").hover(function(){
		if($(this).attr("src").indexOf("-active")==-1){
			var newSrc=$(this).attr("src").replace(".gif","-active.gif#hover");
			$(this).attr("src",newSrc);
		}
	},
	function(){
		if($(this).attr("src").indexOf("-active.gif#hover")!=-1){
			var oldSrc=$(this).attr("src").replace("-active.gif#hover",".gif");
			$(this).attr("src",oldSrc);
		}
	});
	
	$(".apimg").hover(function(){
		$(this).fadeTo("fast",0.6).fadeTo("fast",1);
	},
	function(){});
	
	$('#contactimg').cycle({fx:'fade',pause:1});
	
	$('a[rel*=facebox]').facebox();
	
	var options={target:'#txtHint',beforeSubmit:validateEnquiryForm,success:showResponse,url:'inc/sendenquiry.php',type:'post'};
	var options2={target:'#txtHintEmail',beforeSubmit:validateContactForm,success:showContactResponse,url:'inc/sendmail.php',type:'post'};
	var options3={target:'#txtHintEmail',beforeSubmit:validateRegisterForm,success:showContactResponse,url:'inc/sendregister.php',type:'post'};
	var options4={target:'#txtHintEmail',beforeSubmit:validateRegisterForm,success:showContactResponse,url:'inc/sendregisterfinder.php',type:'post'};
	var options5={target:'#txtHint',beforeSubmit:validateShortTermForm,success:showContactResponse,url:'inc/sendshortterm.php',type:'post'};
	
	$('#enquiryform').submit(function(){
		$(this).ajaxSubmit(options);
		return false;
	});
	
	$('#registerform').submit(function(){
		$(this).ajaxSubmit(options3);
		return false;
	});
	
	$('#registerfinderform').submit(function(){
		$(this).ajaxSubmit(options4);
		return false;
	});
		
	$('#contactform').submit(function(){
		$(this).ajaxSubmit(options2);
		return false;
	});
	
	$('#shorttermform').submit(function(){
		$(this).ajaxSubmit(options5);
		return false;
	});
	
	$("#send2friend").click(function(){		
		if(this.checked == true)
		{
			this.value = "yes";
			$("#trfriendname, #trfriendemail, #trfriendcomments").show();
		}	
		else
		{
			this.value = "no";
			$("#trfriendname, #trfriendemail, #trfriendcomments").hide();
		}		
	});
	
	$("#e_send2friend").click(function(){		
		if(this.checked == true)
		{
			this.value = "yes";
			$("#e_trfriendname, #e_trfriendemail, #trfriendcomments").show();
		}	
		else
		{
			this.value = "no";
			$("#e_trfriendname, #e_trfriendemail, #trfriendcomments").hide();
		}		
	});
	
	$("#pricefilter").change(function(){
		var basehref = $('base').attr('href');
		var prefix = $('#lang').val();		
		var val = this.value;						  
		if(val != '-')
		{
			window.location.href=basehref+''+prefix+'/cat/'+val;
		}
	});
	
	$("#project").change(function(){								  
		var basehref = $('base').attr('href');
		var prefix = $('#lang').val();
		var val = this.value;						  
		if(val != '-')
		{
			
			window.location.href=basehref+''+prefix+'/project/'+val;
			/*
			if(val == 4)
			window.location.href=basehref+''+prefix+'/castrum/';
			else if(val == 12)
			window.location.href=basehref+''+prefix+'/karolyi/';
			else if(val == 19)
			window.location.href=basehref+''+prefix+'/sztlaszlo/';
			else if(val == 22)
			window.location.href=basehref+''+prefix+'/sziv/';
			else if(val == 26)
			window.location.href=basehref+''+prefix+'/toscana/';
			else
				if(val != '-')
				{
				window.location.href=basehref+''+prefix+'/project/'+val;
				}
			*/	
		}
	});																																																																																																																																																																																																																																						
	
	$("#execsearch").click(function(){
		$("#project").val('');		
	});
	
});


/***********************************************
* Cross browser Marquee II- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var delayb4scroll=2000 //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
var marqueespeed=1 //Specify marquee scroll speed (larger is faster 1-10)
var pauseit=1 //Pause marquee onMousever (0=no. 1=yes)?

////NO NEED TO EDIT BELOW THIS LINE////////////

var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var actualheight=''

function scrollmarquee(){
if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8))
cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px"
else
cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
}

function initializemarquee(){
cross_marquee=document.getElementById("vmarquee")
cross_marquee.style.top=0
marqueeheight=document.getElementById("marqueecontainer").offsetHeight
actualheight=cross_marquee.offsetHeight
if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1){ //if Opera or Netscape 7x, add scrollbars to scroll and exit
cross_marquee.style.height=marqueeheight+"px"
cross_marquee.style.overflow="scroll"
return
}
setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll)
}

if (window.addEventListener)
window.addEventListener("load", initializemarquee, false)
else if (window.attachEvent)
window.attachEvent("onload", initializemarquee)
else if (document.getElementById)
window.onload=initializemarquee


$(document).ready(function(){
   // Change the image of hoverable images
   $(".imgHoverable").hover( function() {
       var hoverImg = HoverImgOf($(this).attr("src"));
       $(this).attr("src", hoverImg);
     }, function() {
       var normalImg = NormalImgOf($(this).attr("src"));
       $(this).attr("src", normalImg);
     }
   );
   
   
	$("#submitButton").click(function(){
		
		 var refno = $("#refno").val();
		
		if(refno.match(/\d{4}/))
		{
		window.location.href = "http://www.costarentalsonline.com/en/rentals/"+refno+"/";
		
		}
		
		});
  
});

function HoverImgOf(filename)
{
   var re = new RegExp("(.+)\\.(gif|png|jpg)", "g");
   return filename.replace(re, "$1_hover.$2");
}
function NormalImgOf(filename)
{
   var re = new RegExp("(.+)_hover\\.(gif|png|jpg)", "g");
   return filename.replace(re, "$1.$2");
}




 /****************************************************/
    /* Primary Menu HoverIntent                         */
    /****************************************************/

    if (!isIE6) {
        var menu = $("ul#primary-nav");
        menu.data("notClicked", true);
        var menuItem = $("ul#primary-nav li.top-level");
        var showDropdown = false;

        $("#primary-nav a").live("click", function(event) {
            if (event.button != 0) {// wasn't the left button - ignore
                return true;
            }
            menu.data("notClicked", false);
            $(this).addClass("selected-item-link").css("color", "#fff").css("text-decoration", "underline");
            showDropdown = false;
        });

        menuItem.hoverIntent({
            sensitivity: 5,
            interval: 50,
            over: function() {
                $("ul#primary-nav li.top-level.selected").addClass("removed-selected");
                $("ul#primary-nav li.top-level.removed-selected").removeClass("selected");
                $(this).addClass("user-selected");
            },
            timeout: 50,
            out: function() {
                $(this).removeClass("user-selected");
            }
        });

        menuItem.children().removeClass("dropdown-menu");
        menu.hoverIntent({
            sensitivity: 5,
            interval: 180,
            over: function() {
                if (loadMenuContent) {
                    loadMenuContent(); // Inject content on hover
                }
                showDropdown = true;
                showMenu($("ul#primary-nav li.user-selected"));
            },
            timeout: 150,
            out: function() {
                if (menu.data('notClicked')) {
                    showDropdown = false;
                }
            }
        });

        menuItem.hover(
            function() {
                showMenu(this);
            },
            function() {
                hideMenu(this);
            }
        );

        menu.hover(
            function() { },
            function() {
                if (menu.data('notClicked')) {
                    setTimeout(function() {
                        $("ul#primary-nav li.top-level.removed-selected").addClass("selected");
                        $("ul#primary-nav li.top-level.selected").removeClass("removed-selected");
                    }, 150);
                }
            }
        );
    }

    function showMenu(menuItemSelector) {
        if (showDropdown && menu.data('notClicked')) {
            $(menuItemSelector).children("ul").show();
            $(menuItemSelector).children("div").show();
        }
    }

    function hideMenu(menuItemSelector) {
        if (menu.data('notClicked')) {
            $(menuItemSelector).children("ul").hide();
            $(menuItemSelector).children("div").hide();
        }
        else {
            $("ul#primary-nav li").removeClass("selected");
            $(menuItemSelector).addClass("selected");
        }
    }

    /********************************************************/
    /* Menu Html Injecting content to reduce links for SEO  */
    /********************************************************/
    var residentialMenuHtml = HtmlDecode("&lt;li class=&quot;sub-menu-left&quot;&gt;    &lt;ul&gt;        &lt;li class=&quot;title&quot;&gt;Search&lt;/li&gt;        &lt;li class=&quot;text-bold&quot;&gt;&lt;a href=&quot;/residential/search&quot;&gt;Property&lt;/a&gt;&lt;/li&gt;        &lt;li class=&quot;text-bold last&quot;&gt;&lt;a href=&quot;/residential/search/new-homes&quot;&gt;New Homes&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/residential/estate-agents&quot;&gt;Estate Agents&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/mortgages&quot;&gt;Mortgages&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/area-guides&quot;&gt;Area Guides&lt;/a&gt;&lt;/li&gt;        &lt;li class=&quot;advertise-with-us&quot;&gt;&lt;a href=&quot;/residential/advertise&quot;&gt;Sell your Home&lt;/a&gt;&lt;/li&gt;    &lt;/ul&gt;&lt;/li&gt;&lt;li class=&quot;sub-menu-right&quot;&gt;    &lt;ul&gt;        &lt;li class=&quot;title&quot;&gt;Useful Links&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/residential/advice&quot;&gt;Residential Advice&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/residential/advice/buying&quot;&gt;Buying&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/residential/advice/selling&quot;&gt;Selling&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/residential/advice/finance&quot;&gt;Finance&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/residential/advice/improving&quot;&gt;Improving&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/calculators&quot;&gt;Calculators&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/user&quot;&gt;Property Alerts&lt;/a&gt;&lt;/li&gt;    &lt;/ul&gt;&lt;/li&gt;");
    var lettingsMenuHtml = HtmlDecode("&lt;li class=&quot;sub-menu-left dropdown-menu&quot;&gt;    &lt;ul&gt;        &lt;li class=&quot;title&quot;&gt;Search&lt;/li&gt;        &lt;li class=&quot;text-bold&quot;&gt;&lt;a href=&quot;/lettings/search&quot;&gt;Properties to Rent&lt;/a&gt;&lt;/li&gt;        &lt;li class=&quot;text-bold&quot;&gt;&lt;a href=&quot;/lettings/search/share&quot;&gt;Shared Accommodation&lt;/a&gt;&lt;/li&gt;        &lt;li class=&quot;text-bold&quot;&gt;&lt;a href=&quot;/lettings/search/colleges&quot;&gt;Colleges&lt;/a&gt;&lt;/li&gt;        &lt;li class=&quot;text-bold last&quot;&gt;&lt;a href=&quot;/lettings/search/holiday-homes&quot;&gt;Holiday Homes&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/lettings/estate-agents&quot;&gt;Lettings Agents&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/area-guides&quot;&gt;Area Guides&lt;/a&gt;&lt;/li&gt;        &lt;li class=&quot;advertise-with-us&quot;&gt;&lt;a href=&quot;/lettings/advertise&quot;&gt;Rent your Property&lt;/a&gt;&lt;/li&gt;    &lt;/ul&gt;&lt;/li&gt;&lt;li class=&quot;sub-menu-right&quot;&gt;    &lt;ul&gt;        &lt;li class=&quot;title&quot;&gt;Useful Links&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/lettings/advice&quot;&gt;Rental Advice&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/lettings/advice/tenants&quot;&gt;Tenant&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/lettings/advice/landlords&quot;&gt;Landlord&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/lettings/advice/investors&quot;&gt;Investor&lt;/a&gt;&lt;/li&gt;    &lt;/ul&gt;&lt;/li&gt;");
    var commercialMenuHtml = HtmlDecode("&lt;li class=&quot;sub-menu-left dropdown-menu&quot;&gt;    &lt;ul&gt;        &lt;li class=&quot;title&quot;&gt;Search&lt;/li&gt;        &lt;li class=&quot;text-bold last&quot;&gt;&lt;a href=&quot;/commercial/search&quot;&gt;Commercial Property&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/commercial/estate-agents&quot;&gt;Commercial Agents&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/area-guides&quot;&gt;Area Guides&lt;/a&gt;&lt;/li&gt;        &lt;li class=&quot;advertise-with-us&quot;&gt;&lt;a href=&quot;/commercial/advertise&quot;&gt;Advertise your Commercial Property&lt;/a&gt;&lt;/li&gt;    &lt;/ul&gt;&lt;/li&gt;&lt;li class=&quot;sub-menu-right&quot;&gt;    &lt;ul&gt;        &lt;li class=&quot;title&quot;&gt;Useful Links&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/commercial/advice&quot;&gt;Commercial Advice&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/commercial/advice/market-news&quot;&gt;Market News&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/commercial/advice/help-guides&quot;&gt;Help &amp;amp; Guides&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/user&quot;&gt;Property Alerts&lt;/a&gt;&lt;/li&gt;    &lt;/ul&gt;&lt;/li&gt;");
    var overseasMenuHtml = HtmlDecode("&lt;li class=&quot;sub-menu-left&quot;&gt;    &lt;ul&gt;        &lt;li class=&quot;title&quot;&gt;Search&lt;/li&gt;        &lt;li class=&quot;text-bold&quot;&gt;&lt;a href=&quot;/overseas/search&quot;&gt;Overseas to Buy&lt;/a&gt;&lt;/li&gt;        &lt;li class=&quot;text-bold last&quot;&gt;&lt;a href=&quot;/overseas/search/holiday-homes&quot;&gt;Holiday Rentals&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/overseas/estate-agents&quot;&gt;Overseas Agents&lt;/a&gt;&lt;/li&gt;        &lt;li class=&quot;advertise-with-us&quot;&gt;&lt;a href=&quot;/overseas/advertise&quot;&gt;Advertise your Overseas Property&lt;/a&gt;&lt;/li&gt;    &lt;/ul&gt;&lt;/li&gt;&lt;li class=&quot;sub-menu-right&quot;&gt;    &lt;ul&gt;        &lt;li class=&quot;title&quot;&gt;Useful Links&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/overseas/advice&quot;&gt;Overseas Advice&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/overseas/advice/country-guides&quot;&gt;Country Guides&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/overseas/advice/help-guides&quot;&gt;Help &amp;amp; Guides&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/user&quot;&gt;Property Alerts&lt;/a&gt;&lt;/li&gt;    &lt;/ul&gt;&lt;/li&gt;");
    var homeServicesMenuHtml = HtmlDecode("&lt;li class=&quot;sub-menu-left&quot;&gt;    &lt;ul&gt;        &lt;li class=&quot;title&quot;&gt;Search&lt;/li&gt;        &lt;li class=&quot;text-bold&quot;&gt;&lt;a href=&quot;/home-services&quot;&gt;Services&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/home-services/movers&quot;&gt;Movers&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/home-services/solicitors&quot;&gt;Solicitors&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/home-services/trades-people&quot;&gt;Tradesmen&lt;/a&gt;&lt;/li&gt;        &lt;li class=&quot;advertise-with-us&quot;&gt;&lt;a href=&quot;/home-services/advertise&quot;&gt;Advertise your Service&lt;/a&gt;&lt;/li&gt;    &lt;/ul&gt;&lt;/li&gt;&lt;li class=&quot;sub-menu-right&quot;&gt;    &lt;ul&gt;        &lt;li class=&quot;title&quot;&gt;Useful Links&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/residential/advice&quot;&gt;Advice Centre&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/home-services/#tenderme&quot;&gt;Get the best Quote&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/residential/advice/improving&quot;&gt;Interior Design&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;/residential/advice/improving/garden-outdoors &quot;&gt;Gardening Tips&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href=&quot;http://blog.myhome.ie/&quot;&gt;MyHome.ie Blog&lt;/a&gt;&lt;/li&gt;    &lt;/ul&gt;&lt;/li&gt;");

    var residentialMenu = $("ul#primary-nav li.top-level.residential > ul");
    var lettingsMenu = $("ul#primary-nav li.top-level.lettings > ul");
    var commercialMenu = $("ul#primary-nav li.top-level.commercial > ul");
    var overseasMenu = $("ul#primary-nav li.top-level.overseas > ul");
    var homeServicesMenu = $("ul#primary-nav li.top-level.home-services > ul");

    function loadMenuContent() {
        // Checking length over two as C# inline can add a space sometimes 
        if (residentialMenu.html().length < 1) {
            residentialMenu.append(residentialMenuHtml);
        }
        if (lettingsMenu.html().length < 1) {
            lettingsMenu.append(lettingsMenuHtml);
        }
        if (commercialMenu.html().length < 1) {
            commercialMenu.append(commercialMenuHtml);
        }
        if (overseasMenu.html().length < 1) {
            overseasMenu.append(overseasMenuHtml);
        }
        if (homeServicesMenu.html().length < 1) {
            homeServicesMenu.append(homeServicesMenuHtml);
        }
        loadMenuContent = false;
    }

    /* A trick to get html to encode/decode */
    function HtmlEncode(html) {
        return $('<div/>').text(html).html();
    }

    function HtmlDecode(text) {
        return $('<div/>').html(text).text();
    }


