function openHotelLightBox(hotelId,catId){
    $("select.start-page-select-country-and-resort").hide();
    $("div#light-box").removeClass("light-box-layer").addClass("unique-lightbox").css("height", $(document).height() + 630 + "px").show();
    $("div#light-box-content").css("top", "10px").load(String.format("/BlueSites/Templates/DynamicContent/BlueUnique.aspx?hotel={0}&cat={1}", hotelId, catId), function() {
        $.getScript(oBaseAppSettings.IncludeSiteDirectory+"/Js/JQuery/reflection.js", function() {
            setTimeout('addReflections()', 100);
            Cufon.replace('span.blue-unique-second-heading', { fontFamily: 'TUIType' })('span.grade', { fontFamily: 'TUIType' })('span.cityname', { fontFamily: 'TUIType' })('span#image-counter', { fontFamily: 'TUIType' });
        });
    }).fadeIn("slow");
    scroll(0,0);
}
function openLightBox(id,catId){
    $("select.start-page-select-country-and-resort").hide();
    $("div#light-box").removeClass("light-box-layer").addClass("unique-lightbox").css("height", $(document).height() + 680 + "px").show();
    $("div#light-box-content").css("top", "10px").load(String.format("/BlueSites/Templates/DynamicContent/BlueUnique.aspx?index={0}&cat={1}", id, catId), function() {
        $.getScript(oBaseAppSettings.IncludeSiteDirectory+"/Js/JQuery/reflection.js", function() {
            $.getScript(oBaseAppSettings.IncludeSiteDirectory+"/Js/JQuery/jquery.scrollfollow.js", function() {
                addReflections();
                Cufon.replace('span.blue-unique-second-heading', { fontFamily: 'TUIType' })('span.grade', { fontFamily: 'TUIType' })('span.cityname', { fontFamily: 'TUIType' })('span#image-counter', { fontFamily: 'TUIType' });
                $('img.unique-arrow-left').scrollFollow({ speed: 300, offset: 200 });
                $('img.unique-arrow-right').scrollFollow({ speed: 300, offset: 200 });
            });
        });
    }).fadeIn("slow");
    scroll(0,0);
}
function openGenericLightBox(epiId, width){
    var w=0;
    if (typeof (width) != 'undefined'){
        w=width;
    }

    $("select.start-page-select-country-and-resort").hide();
    $("div#light-box").removeClass("light-box-layer").addClass("unique-lightbox").css("height", $(document).height() + 100 + "px").show();
    $("div#light-box-content").css("top", "10px").load("/BlueSites/Templates/DynamicContent/GenericContent.aspx?epiid=" + epiId + "&width=" + w, function() {

    }).fadeIn("slow");
    scroll(0,0);
}
$(document).ready(function() {
    $("a#open-light-box").click(function() {
        var rel = $(this).attr("rel");
        if (rel.indexOf("|") == -1) {
            rel = rel + "|" + 324;
        }
        var arr = rel.split("|");
        openHotelLightBox(arr[0], arr[1]);
    });
    $("#toggler-container a").click(function() {
        $("#toggler-container a").removeClass("selected");
        $(this).addClass("selected");

        var currentId = $(this).attr("id").replace("listItem_", "");
        $("#expandPanelImage").attr("src", $("#hidden_" + currentId).attr("value"));

        $(".box-extra-info-expand").removeClass("display-block").addClass("display-none");
        $("#container_" + currentId).removeClass("display-none").addClass("display-block");
    });
    $("a.close-expand-panel-JS, a.close-link").click(function() {
        var currentId = $(this).attr("id").replace("close_", "");
        $("#container_" + currentId).removeClass("display-block").addClass("display-none");
        $("#listItem_" + currentId).removeClass("selected");
        return false;
    });
    $('div#flash-map-small div#flash-container a.map-link, #page #select-country-or-map a').click(function(event) {
        event.preventDefault();
        if ($("div.dialog-google-maps").length == 0) {
            var mapsUrl = "/BlueSites/Templates/DynamicContent/GoogleMapsOverView.aspx";
            var dialogControl = TUI.Web.UI.WebControls.Dialog.createNewGlobalDialog({ 'innerHtmlCenter': '<iframe frameborder="0" scrolling="no" src="' + mapsUrl + '"></iframe>', 'showOverlay': true, 'isDraggable': true }, 'dialog-google-maps');
            $("div#light-box").css("height", $(document).height() + 100 + "px").show();
            dialogControl.show();
            $("div.dialog-google-maps").css({ zIndex: "101", position: "absolute" }).find("a.dialog-top-close-link").click(function() {
                $("div#light-box").hide();
            });
            $("div.dialog-overlay").hide();
        }
        else {
            $("div#light-box, div.dialog-google-maps").css("visibility", "visible").show();
        }
        return false;
    });
});
function triggerOpenLightBox2(){openLightBox(this.id);}
function triggerOpenLightBox(id,catId){openLightBox(id,catId);}
function triggerOpenGenericLightBox(id, width){openGenericLightBox(id,width);}
    
/** SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php */
if(typeof deconcept=="undefined")var deconcept=new Object();if(typeof deconcept.util=="undefined")deconcept.util=new Object();
if(typeof deconcept.SWFObjectUtil=="undefined")deconcept.SWFObjectUtil=new Object();deconcept.SWFObject=function(swf,id,w,h,ver,c,quality,xiRedirectUrl,redirectUrl,detectKey){
	if(!document.getElementById){return;}this.DETECT_KEY=detectKey?detectKey:'detectflash';this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();
	this.attributes=new Array();if(swf){this.setAttribute('swf',swf);}if(id){this.setAttribute('id',id);}if(w){this.setAttribute('width',w);}
	if(h){this.setAttribute('height',h);}
	if(ver){this.setAttribute('version',new deconcept.PlayerVersion(ver.toString().split(".")));}
	this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();
	if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}
	if(c){this.addParam('bgcolor',c);}var q=quality?quality:'high';
	this.addParam('quality',q);this.setAttribute('useExpressInstall',false);
	this.setAttribute('doExpressInstall',false);var xir=(xiRedirectUrl)?xiRedirectUrl:window.location;
	this.setAttribute('xiRedirectUrl',xir);this.setAttribute('redirectUrl','');
	if(redirectUrl){this.setAttribute('redirectUrl',redirectUrl);}}
deconcept.SWFObject.prototype={useExpressInstall: function(path){this.xiSWFPath=!path?"expressinstall.swf":path;
		this.setAttribute('useExpressInstall',true);},setAttribute: function(name,value){this.attributes[name]=value;
	},getAttribute: function(name){return this.attributes[name];},addParam: function(name,value){this.params[name] = value;},getParams: function(){
		return this.params;},addVariable: function(name,value){this.variables[name]=value;},getVariable: function(name){return this.variables[name];
	},getVariables: function(){return this.variables;},getVariablePairs: function(){var variablePairs=new Array();var key;var variables=this.getVariables();
		for(key in variables){variablePairs[variablePairs.length]=key+"="+variables[key];}return variablePairs;},getSWFHTML: function(){var swfNode="";
		if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");
				this.setAttribute('swf', this.xiSWFPath);}
			swfNode='<embed type="application/x-shockwave-flash" src="'+this.getAttribute('swf')+'" width="'+this.getAttribute('width')+'" height="'+this.getAttribute('height')+'" style="'+this.getAttribute('style')+'"';
			swfNode+=' id="'+this.getAttribute('id')+'" name="'+this.getAttribute('id')+'" ';var params=this.getParams(); for(var key in params){swfNode+=[key]+'="'+params[key]+'" ';}
			var pairs=this.getVariablePairs().join("&");if(pairs.length>0){swfNode+='flashvars="'+pairs+'"';}swfNode+='/>';}else{if(this.getAttribute("doExpressInstall")){
				this.addVariable("MMplayerType","ActiveX");this.setAttribute('swf',this.xiSWFPath);}swfNode='<object id="'+this.getAttribute('id')+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+this.getAttribute('width')+'" height="'+this.getAttribute('height')+'" style="'+this.getAttribute('style')+'">';
			swfNode+='<param name="movie" value="'+this.getAttribute('swf')+'" />';var params=this.getParams();	for(var key in params){swfNode+='<param name="'+key+'" value="'+params[key]+'" />';}
			var pairs=this.getVariablePairs().join("&");if(pairs.length>0){swfNode+='<param name="flashvars" value="'+pairs+'" />';}swfNode+="</object>";}return swfNode;
	},write: function(elementId){if(this.getAttribute('useExpressInstall')){var expressInstallReqVer=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(expressInstallReqVer)&&!this.installedVer.versionIsValid(this.getAttribute('version'))){
				this.setAttribute('doExpressInstall',true);this.addVariable("MMredirectURL",escape(this.getAttribute('xiRedirectUrl')));document.title=document.title.slice(0,47)+" - Flash Player Installation";
				this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute('doExpressInstall')||this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n=(typeof elementId=='string')?document.getElementById(elementId):elementId;n.innerHTML=this.getSWFHTML();return true;}else{
			if(this.getAttribute('redirectUrl')!=""){document.location.replace(this.getAttribute('redirectUrl'));}}return false;}}
deconcept.SWFObjectUtil.getPlayerVersion=function(){var PlayerVersion=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){
		var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){PlayerVersion=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}
	}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var counter=3;while(axo){try{counter++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+counter);
				PlayerVersion=new deconcept.PlayerVersion([counter,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{
				var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");PlayerVersion=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";
			}catch(e){if(PlayerVersion.major==6){return PlayerVersion;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){PlayerVersion=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}
	}return PlayerVersion;}
deconcept.PlayerVersion=function(arrVersion){
	this.major=arrVersion[0]!=null?parseInt(arrVersion[0]):0;this.minor=arrVersion[1]!=null?parseInt(arrVersion[1]):0;this.rev=arrVersion[2]!=null?parseInt(arrVersion[2]):0;}
deconcept.PlayerVersion.prototype.versionIsValid=function(fv){
	if(this.major<fv.major)return false; if(this.major>fv.major)return true; if(this.minor<fv.minor)return false; if(this.minor>fv.minor)return true; if(this.rev<fv.rev)return false; return true;}
deconcept.util={
	getRequestParameter: function(param){
		var q=document.location.search||document.location.hash;
		if(param==null){return q;}
		if(q){var pairs=q.substring(1).split("&");
			for(var i=0;i<pairs.length;i++){if(pairs[i].substring(0,pairs[i].indexOf("="))==param){return pairs[i].substring((pairs[i].indexOf("=")+1));}}}return "";}}
deconcept.SWFObjectUtil.cleanupSWFs=function(){
	var objects=document.getElementsByTagName("OBJECT");
	for(var i=objects.length-1;i>=0;i--){
		objects[i].style.display='none';
		for(var x in objects[i]){if(typeof objects[i][x]=='function'){objects[i][x]=function(){};}}}}
if(deconcept.SWFObject.doPrepUnload){
	if(!deconcept.unloadSet){
		deconcept.SWFObjectUtil.prepUnload=function(){
			__flash_unloadHandler=function(){};
			__flash_savedUnloadHandler=function(){};
			window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);}
		window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
		deconcept.unloadSet=true;}}
if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];}}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

/** getXML - sets text for specified object from call to specified url
* @param strURL					- url to get
* @param oElmToPresentContentIn	- element to set innerHTML for
* @param doAfterCompletion			- optional. function to call after completion /TS (T1)
*/
function getXML(strURL, oElmToPresentContentIn, doAfterCompletion) {
    if (!oElmToPresentContentIn)
        return;

    var oXMLHTTPRequest;
    var strHTML;
    if (typeof XMLHttpRequest != "undefined") { oXMLHTTPRequest = new XMLHttpRequest(); }
    else if (typeof window.ActiveXObject != "undefined") {
        try { oXMLHTTPRequest = new ActiveXObject("Msxml2.XMLHTTP.4.0"); }
        catch (e) {
            try { oXMLHTTPRequest = new ActiveXObject("MSXML2.XMLHTTP"); }
            catch (e) {
                try { oXMLHTTPRequest = new ActiveXObject("Microsoft.XMLHTTP"); }
                catch (e) { oXMLHTTPRequest = null; alert(strSorryXmlHttp); } 
            } 
        } 
    }
    else { alert(strSorryXmlHttp); }
    if (oXMLHTTPRequest) {
        oXMLHTTPRequest.onreadystatechange = function() {
            if (oXMLHTTPRequest.readyState == 4) {
                try {
                    strHTML = oXMLHTTPRequest.responseText;
                    oElmToPresentContentIn.innerHTML = strHTML;
                    if (doAfterCompletion)	// perform extra task after load?
                        doAfterCompletion();
                    this.onreadystatechange = new function() { };
                    if (oXMLHTTPRequest && typeof oXMLHTTPRequest.abort == "function") {
                        oXMLHTTPRequest.abort();
                        oXMLHTTPRequest = null;
                    } 
                }
                catch (e) { }
                return true;
            } 
        }
        oXMLHTTPRequest.open("GET", strURL, true);
        oXMLHTTPRequest.send(null);
    }
    return oXMLHTTPRequest;
}
function getJavaScriptArray(strURL, oFunctionToCall) {
    var oXMLHTTPRequest;
    var strHTML;
    if (typeof XMLHttpRequest != "undefined") { oXMLHTTPRequest = new XMLHttpRequest(); }
    else if (typeof window.ActiveXObject != "undefined") {
        try { oXMLHTTPRequest = new ActiveXObject("Msxml2.XMLHTTP.4.0"); }
        catch (e) {
            try { oXMLHTTPRequest = new ActiveXObject("MSXML2.XMLHTTP"); }
            catch (e) {
                try { oXMLHTTPRequest = new ActiveXObject("Microsoft.XMLHTTP"); }
                catch (e) { oXMLHTTPRequest = null; alert(strSorryXmlHttp); } 
            } 
        } 
    }
    else { alert(strSorryXmlHttp); }
    if (oXMLHTTPRequest) {
        oXMLHTTPRequest.onreadystatechange = function() {
            if (oXMLHTTPRequest.readyState == 4) {
                strJavaScript = oXMLHTTPRequest.responseText;
                strJavaScript = strJavaScript.substring(0, strJavaScript.lastIndexOf(']') + 1);
                if (oFunctionToCall)
                    eval(oFunctionToCall + "(" + strJavaScript.replace(/[\n\r\t]/g, "") + ")");
                this.onreadystatechange = new function() { };
                if (oXMLHTTPRequest && typeof oXMLHTTPRequest.abort == "function") {
                    oXMLHTTPRequest.abort();
                    oXMLHTTPRequest = null;
                }
                return true;
            } 
        }
        oXMLHTTPRequest.open("GET", strURL, true);
        oXMLHTTPRequest.send(null);
    } 
}
function getJavaScriptArrayWithIdentifier(strId, strURL, oFunctionToCall) {
    var oXMLHTTPRequest;
    var strHTML;
    if (typeof XMLHttpRequest != "undefined") { oXMLHTTPRequest = new XMLHttpRequest(); }
    else if (typeof window.ActiveXObject != "undefined") {
        try { oXMLHTTPRequest = new ActiveXObject("Msxml2.XMLHTTP.4.0"); }
        catch (e) {
            try { oXMLHTTPRequest = new ActiveXObject("MSXML2.XMLHTTP"); }
            catch (e) {
                try { oXMLHTTPRequest = new ActiveXObject("Microsoft.XMLHTTP"); }
                catch (e) { oXMLHTTPRequest = null; alert(strSorryXmlHttp); } 
            } 
        } 
    }
    else { alert(strSorryXmlHttp); }
    if (oXMLHTTPRequest) {
        oXMLHTTPRequest.onreadystatechange = function() {
            if (oXMLHTTPRequest.readyState == 4) {
                strJavaScript = oXMLHTTPRequest.responseText;
                if (oFunctionToCall) {
                    strJavaScript = strJavaScript.substring(0, strJavaScript.lastIndexOf(']') + 1);
                    var toDo = oFunctionToCall + "('" + strId + "'," + strJavaScript.replace(/[\n\r\t]/g, "") + ")";
                    try { eval(toDo); }
                    catch (e) { }
                }
                this.onreadystatechange = new function() { };
                if (oXMLHTTPRequest && typeof oXMLHTTPRequest.abort == "function") {
                    oXMLHTTPRequest.abort();
                    oXMLHTTPRequest = null;
                }
                return true;
            }
        }
        oXMLHTTPRequest.open("GET", strURL, true);
        oXMLHTTPRequest.send(null);
    } 
}

//Humany
$(document).ready(function() {
    $("#humanySuggestSearchInput").keyup(function(event) {
        clearTimeout(timer);
        if (event.keyCode == 13) {
            var selectedIndex = $("div#humanySuggestResult div.entry-item").index($("div#humanySuggestResult div.hover"));
            if (selectedIndex > -1) {
                browseToItem(selectedIndex);
            } else {
                browseToLargeSearch();
            }
            return;
        } else if (event.keyCode == 38 || event.keyCode == 40) {
            step(event.keyCode);
            return;
        }
        timer = setTimeout("initHumanySearch()", 500);
        $("#humanySuggestSearchInput").addClass("searching");
    });

    // For notfound page
    $("#not-found #search-field").keyup(function(event) {
        clearTimeout(timer);
        if (event.keyCode == 13) {            
                browseToLargeSearch();           
            return;
        } else if (event.keyCode == 38 || event.keyCode == 40) {
            step(event.keyCode);
            return;
        }
    });

    $("#humanySearchInput").keyup(function() {
        clearTimeout(timer);
        timer = setTimeout("initHumanySearchLarge()", 500);
        $("#humanySearchInput").addClass("searching");
    });

    $("input#humanySearchSubmit, input.search-humany-button").click(function(event) {
        event.preventDefault();
        browseToLargeSearch();
        //$("div#humanySuggestResult").show();
        return false;
    });

    $("#humanySuggestSearchInput, #humanySearchInput").keydown(function(event) {
        return (event.keyCode != 13);
    });

    $("#humanySuggestSearchInput").focus(function() {
        if (($("div#humanySuggestResult").children("div").length > 0) && ($.trim($(this).val()) != "") && ($.trim($(this).val()) != initialTextValue)) {
            $("div#humanySuggestResult").show();
            $("#panorama-container").css("visibility", "hidden");
        }
        else {
            $("#panorama-container").css("visibility", "visible");
        }
    });

    oTabHelper = new TabHelper();
    oTabHelper.listItemsTop.children("a").click(toggleTabContent);
    oTabHelper.listItemsRight.children("a").click(toggleTabContent);

    $("div.tab-content div.section-header span.item-count a").click(function() {
        selectedTab = $("ul.tabs-large li a").eq(($("div.tab-content div.section-container").index($(this).parents("div.section-container:first")) + 1));
        $(document).scrollTo(250, 500, function() {
            selectedTab.trigger("click");
        });
    });

    initialTextValue = getInitialTextValue();
});

HumanyEventTracker = function() {
    this.SearchType = "Search box";
    this.NoResult = false;
    this.NoResultURIAttr = "&gaCat2=No result";
    this.SetSearchType = function() {
        if ($("div#search-box input#humanySearchInput").length > 0) { this.SearchType = "Actual search page"; }
    }
    this.NoOfHits = 0;
    this.SearchPhrase = "";
    this.SearchPhrasePrevious = this.SearchPhrase;
    this.SetSearchPhrase = function(searchPhrase) {
        this.SearchPhrase = $.trim(searchPhrase);
    }
    this.SetCountryResult = function(numberOfHits) {
        this.NoOfHits += numberOfHits;
    }
    this.SetDestinationResult = function(numberOfHits) {
        this.NoOfHits += numberOfHits;
    }
    this.SetHotelResult = function(numberOfHits) {
        this.NoOfHits += numberOfHits;
    }
    this.SetFaqResult = function(numberOfHits) {
        this.NoOfHits += numberOfHits;
    }
    this.SetExcursionResult = function(numberOfHits) {
        this.NoOfHits += numberOfHits;
    }
    this.SendEvent = function(pageNum) {
        if (this.SearchPhrase == "" || this.SearchPhrase == "undefined" || typeof (this.SearchPhrase) == "undefined") {
            return;
        }
        if ((pageNum == 1) && (this.SearchPhrase != this.SearchPhrasePrevious)) {
            this.SetSearchType();
            this.NoResult = (!this.NoOfHits > 0);
            try {
                var siteSearchURI = encodeURI(WebGuideStrings.showAllLinkUrl + "?gaEntry=" + this.SearchPhrase + "&gaCat1=" + this.SearchType + ((this.NoResult) ? this.NoResultURIAttr : "") + "&view=" + Math.ceil(999999 * Math.random()));
                //$("body").prepend("<b>" + this.SearchType + ", " + this.NoOfHits + ", " + siteSearchURI + "</b><br/>");
                _gaq.push(['_trackPageview', siteSearchURI]);
            } catch (err) { }
        }
        this.SearchPhrasePrevious = this.SearchPhrase;
        this.NoOfHits = 0;
    }
}
humanyEventTracker = new HumanyEventTracker();

var defaultItemsPerPage = 10;
var itemsPerPage = 10;
var itemsPerSuggestion = 2;
var oTabHelper = null;
TabHelper = function() {
    this.selectedIndex = 1;
    this.listTop = $("ul.tabs-large");
    this.listItemsTop = this.listTop.children("li");
    this.listRight = $("div.right-column ul.tab-links");
    this.listItemsRight = this.listRight.children("li");
}

toggleTabContent = function(event) {
    event.preventDefault();
    if ($(this).parent("li").hasClass("disabled")) {
        return false;
    }
    oTabHelper.selectedIndex = $(this).parents("ul:first").find("li a").index(this);
    oTabHelper.listItemsTop.removeClass("selected");
    oTabHelper.listItemsRight.removeClass("selected");

    oTabHelper.listItemsTop.eq(oTabHelper.selectedIndex).addClass("selected");
    oTabHelper.listItemsRight.eq(oTabHelper.selectedIndex).addClass("selected");

    $("div#tab-box-large").attr("class", "tab-box-large-left tab-selected-" + (oTabHelper.selectedIndex + 1));

    if (oTabHelper.selectedIndex == 0) {
        itemsPerPage = 10;
        if (typeof ($("div.countries div.country-result")[0].itemsPerPage) != "undefined" && $("div.countries div.country-result")[0].itemsPerPage != itemsPerPage && $("div.countries div.country-result")[0].numberOfHits > defaultItemsPerPage) {
            getPagedCountries($("div.countries div.country-result").html("").addClass("searching"), 1);
        }
        if (typeof ($("div.destinations div.destination-result")[0].itemsPerPage) != "undefined" && $("div.destinations div.destination-result")[0].itemsPerPage != itemsPerPage && $("div.destinations div.destination-result")[0].numberOfHits > defaultItemsPerPage) {
            getPagedDestinations($("div.destinations div.destination-result").html("").addClass("searching"), 1);
        }
        if (typeof ($("div.hotels div.hotel-result")[0].itemsPerPage) != "undefined" && $("div.hotels div.hotel-result")[0].itemsPerPage != itemsPerPage && $("div.hotels div.hotel-result")[0].numberOfHits > defaultItemsPerPage) {
            getPagedHotels($("div.hotels div.hotel-result").html("").addClass("searching"), 1);
        }
        if (typeof ($("div.excursions div.excursion-result")[0].itemsPerPage) != "undefined" && $("div.excursions div.excursion-result")[0].itemsPerPage != itemsPerPage && $("div.excursions div.excursion-result")[0].numberOfHits > defaultItemsPerPage) {
            getPagedExcursions($("div.excursions div.excursion-result").html("").addClass("searching"), 1);
        }
    }
    else if (oTabHelper.selectedIndex == 2) {
        itemsPerPage = 30;
        if (typeof ($("div.countries div.country-result")[0].itemsPerPage) != "undefined" && $("div.countries div.country-result")[0].itemsPerPage != itemsPerPage && $("div.countries div.country-result")[0].numberOfHits > defaultItemsPerPage) {
            getPagedCountries($("div.countries div.country-result").html("").addClass("searching"), 1);
        }
    }
    else if (oTabHelper.selectedIndex == 3) {
        itemsPerPage = 30;
        if (typeof ($("div.destinations div.destination-result")[0].itemsPerPage) != "undefined" && $("div.destinations div.destination-result")[0].itemsPerPage != itemsPerPage && $("div.destinations div.destination-result")[0].numberOfHits > defaultItemsPerPage) {
            getPagedDestinations($("div.destinations div.destination-result").html("").addClass("searching"), 1);
        }
    }
    else if (oTabHelper.selectedIndex == 4) {
        itemsPerPage = 30;
        if (typeof ($("div.hotels div.hotel-result")[0].itemsPerPage) != "undefined" && $("div.hotels div.hotel-result")[0].itemsPerPage != itemsPerPage && $("div.hotels div.hotel-result")[0].numberOfHits > defaultItemsPerPage) {
            getPagedHotels($("div.hotels div.hotel-result").html("").addClass("searching"), 1);
        }
    }
    else if (oTabHelper.selectedIndex == 5) {
        itemsPerPage = 30;
        if (typeof ($("div.excursions div.excursion-result")[0].itemsPerPage) != "undefined" && $("div.excursions div.excursion-result")[0].itemsPerPage != itemsPerPage && $("div.excursions div.excursion-result")[0].numberOfHits > defaultItemsPerPage) {
            getPagedExcursions($("div.excursions div.excursion-result").html("").addClass("searching"), 1);
        }
    }
}

var timer = null;
initHumanySearch = function() {
    clearTimeout(timer);
    timer = null;
    performHumanySearch();
}

initHumanySearchLarge = function() {
    clearTimeout(timer);
    timer = null;
    performHumanySearchLarge();
}

var loadingContainersTimer = null;
checkForLoadingContainers = function() {
    clearTimeout(loadingContainersTimer);
    loadingContainersTimer = null;
    if ($("div#humanySuggestResult").length > 0) { $("div#humanySuggestResult div.searching").removeClass("searching").addClass("empty"); }
    else if ($("div#humany-container").length > 0) { $("div#humany-container div.searching").removeClass("searching").addClass("empty"); }
}

initCheckForLoadingContainers = function() {
    if (loadingContainersTimer == null && timer == null) { loadingContainersTimer = setTimeout("checkForLoadingContainers()", 1500); }
}

getInitialTextValue = function() {
    if ($("#humanySuggestSearchInput").length > 0) {
        return $("#humanySuggestSearchInput").val();
    }
    else {
        return "";
    }
}

var currentSearchText = "";
var initialTextValue = "";
performHumanySearch = function() {
    var inputValue = $.trim($("#humanySuggestSearchInput").val()).toLowerCase();
    if (inputValue == "" || inputValue == "undefined" || typeof (inputValue) == "undefined") {
        $("#humanySuggestResult").hide();
        $("#humanySuggestSearchInput").removeClass("searching");
        currentSearchText = "";
        return;
    }
    else if ((inputValue == currentSearchText) || (inputValue == initialTextValue)) {
        $("#humanySuggestSearchInput").removeClass("searching");
        return;
    }
    currentSearchText = inputValue;
    var loadingResultHTML =
        "<div class=\"entry-top\">" +
            "<a href=\"javascript:void(0)\"><img src=\"" + oBaseAppSettings.IncludeSiteDirectory + "/Images/BlueSites/Humany/1/btn_close.png\" alt=\"\" /></a>" +
        "</div>" +
        "<div class=\"entry-middle\">" +
            "<div class=\"entry-result\"></div>" +
        "</div>" +
        "<div class=\"entry-bottom\"><a href=\"" + WebGuideStrings.showAllLinkUrl + "?humanyEntry=" + currentSearchText + "&view=" + Math.ceil(999999 * Math.random()) + "\">" + WebGuideStrings.showAllOnOwnPage + " &#187;</a></div>" +
        "<div class=\"clear\"></div>";
    $("#humanySuggestResult").html(loadingResultHTML).show();
    $("#humanySuggestResult .entry-top a").click(function() { $("#humanySuggestResult").hide(); $("#panorama-container").css("visibility", "visible"); });
    var resultHTML =
        "<div class=\"countries searching\">" +
            "<span class=\"status\"></span><h3>" + WebGuideStrings.countries + "</h3>" +
        "</div>" +
        "<div class=\"destinations searching\">" +
            "<span class=\"status\"></span><h3>" + WebGuideStrings.destinations + "</h3>" +
        "</div>" +
        "<div class=\"hotels searching\">" +
            "<span class=\"status\"></span><h3>" + WebGuideStrings.hotels + "</h3>" +
        "</div>" +
        "<div class=\"excursions searching\">" +
            "<span class=\"status\"></span><h3>" + WebGuideStrings.excursions + "</h3>" +
        "</div>" +
        "<div class=\"faq searching\">" +
            "<h3>" + WebGuideStrings.faq + "</h3>" +
        "</div>" +
        "<div class=\"all-empty\">" +
            "<h3>&#160;</h3>" +
            "<div class=\"text-item\">" + WebGuideStrings.searchNoResult + "</div>" +
        "</div>";
    var resultElems = $(resultHTML);
    $("#panorama-container").css("visibility", "hidden");
    $("#humanySuggestResult div.entry-result").html("").append(resultElems);

    humanyEventTracker.SetSearchPhrase(inputValue);

    $.getJSON("http://fritidsresor.humany.com/" + WebGuideStrings.countryCode + "/json_flat.asp?entry=" + escape(inputValue) + "&type=country&pageSize=" + itemsPerSuggestion + "&pageNumber=1&suggest=true&callback=?", function(data) {
        var entryHTML = "";
        var entryCounter = 0;
        if (data.country != null) {
            $.each(data.country, function(ientry, entry) {
                if (entryCounter < itemsPerSuggestion) {
                    entryHTML += getItemHTML(entryCounter, entry);
                }
                entryCounter++;
            });
        }
        humanyEventTracker.SetCountryResult(data.numberOfHits);
        resultElems.eq(0).children("span.status").html(String.format(WebGuideStrings.textNumberOfHits, ((entryCounter > itemsPerSuggestion) ? itemsPerSuggestion : entryCounter), data.numberOfHits));
        resultElems.eq(0).children("h3").after(entryHTML);
        if (resultElems.eq(0).children("div.entry-item").length > 0) {
            resultElems.eq(0).removeClass("searching").show();
            bindEntryItemEvents(resultElems.eq(0).children("div.entry-item"));
        } else { resultElems.eq(0).removeClass("searching").addClass("empty"); }
        if (resultElems.filter(".empty").length == 5) { $("div#humanySuggestResult div.all-empty").show(); humanyEventTracker.SendEvent(1); }
        else if (resultElems.filter(".searching").length == 0) { resultElems.find("span.status:visible").eq(0).addClass("first"); humanyEventTracker.SendEvent(1); }
        $("#humanySuggestSearchInput").removeClass("searching");
        initCheckForLoadingContainers();
    });

    $.getJSON("http://fritidsresor.humany.com/" + WebGuideStrings.countryCode + "/json_flat.asp?entry=" + escape(inputValue) + "&type=destination&pageSize=" + itemsPerSuggestion + "&pageNumber=1&suggest=true&callback=?", function(data) {
        var destinationHTML = "";
        var destinationCounter = 0;
        if (data.destination != null) {
            $.each(data.destination, function(idestination, destination) {
                if (typeof (destination.name) != "undefined") {
                    if (destinationCounter < itemsPerSuggestion) {
                        destinationHTML += getItemHTML(destinationCounter, destination);
                    }
                    destinationCounter++;
                }
            });
        }
        humanyEventTracker.SetDestinationResult(data.numberOfHits);
        resultElems.eq(1).children("span.status").html(String.format(WebGuideStrings.textNumberOfHits, ((destinationCounter > itemsPerSuggestion) ? itemsPerSuggestion : destinationCounter), data.numberOfHits));
        resultElems.eq(1).children("h3").after(destinationHTML);
        if (resultElems.eq(1).children("div.entry-item").length > 0) {
            resultElems.eq(1).removeClass("searching").show();
            bindEntryItemEvents(resultElems.eq(1).children("div.entry-item"));
        } else { resultElems.eq(1).removeClass("searching").addClass("empty"); }
        if (resultElems.filter(".empty").length == 5) { $("div#humanySuggestResult div.all-empty").show(); humanyEventTracker.SendEvent(1); }
        else if (resultElems.filter(".searching").length == 0) { resultElems.find("span.status:visible").eq(0).addClass("first"); humanyEventTracker.SendEvent(1); }
        $("#humanySuggestSearchInput").removeClass("searching");
        initCheckForLoadingContainers();
    });

    $.getJSON("http://fritidsresor.humany.com/" + WebGuideStrings.countryCode + "/json_flat.asp?entry=" + escape(inputValue) + "&type=hotel&pageSize=" + itemsPerSuggestion + "&pageNumber=1&suggest=true&callback=?", function(data) {
        var hotelHTML = "";
        var hotelCounter = 0;
        if (data.hotel != null) {
            $.each(data.hotel, function(ihotel, hotel) {
                if (hotelCounter < itemsPerSuggestion) {
                    hotelHTML += getItemHTML(hotelCounter, hotel);
                }
                hotelCounter++;
            });
        }
        humanyEventTracker.SetHotelResult(data.numberOfHits);
        resultElems.eq(2).children("span.status").html(String.format(WebGuideStrings.textNumberOfHits, ((hotelCounter > itemsPerSuggestion) ? itemsPerSuggestion : hotelCounter), data.numberOfHits));
        resultElems.eq(2).children("h3").after(hotelHTML);
        if (resultElems.eq(2).children("div.entry-item").length > 0) {
            resultElems.eq(2).removeClass("searching").show();
            bindEntryItemEvents(resultElems.eq(2).children("div.entry-item"));
        } else { resultElems.eq(2).removeClass("searching").addClass("empty"); }
        if (resultElems.filter(".empty").length == 5) { $("div#humanySuggestResult div.all-empty").show(); humanyEventTracker.SendEvent(1); }
        else if (resultElems.filter(".searching").length == 0) { resultElems.find("span.status:visible").eq(0).addClass("first"); humanyEventTracker.SendEvent(1); }
        $("#humanySuggestSearchInput").removeClass("searching");
        initCheckForLoadingContainers();
    });
    $.getJSON("http://fritidsresor.humany.com/" + WebGuideStrings.countryCode + "/json_flat.asp?entry=" + escape(inputValue) + "&type=excursion&pageSize=" + itemsPerSuggestion + "&pageNumber=1&suggest=true&callback=?", function(data) {
        var excursionHTML = "";
        var excursionCounter = 0;
        if (data.excursion != null) {
            $.each(data.excursion, function(iexcursion, excursion) {
                if (excursionCounter < itemsPerSuggestion) {
                    excursionHTML += getExcursionHTML(excursionCounter, excursion);
                }
                excursionCounter++;
            });
        }
        humanyEventTracker.SetExcursionResult(data.numberOfHits);
        resultElems.eq(3).children("span.status").html(String.format(WebGuideStrings.textNumberOfHits, ((excursionCounter > itemsPerSuggestion) ? itemsPerSuggestion : excursionCounter), data.numberOfHits));
        resultElems.eq(3).children("h3").after(excursionHTML);
        if (resultElems.eq(3).children("div.entry-item").length > 0) {
            resultElems.eq(3).removeClass("searching").show();
            bindEntryItemEvents(resultElems.eq(3).children("div.entry-item"));
        } else { resultElems.eq(3).removeClass("searching").addClass("empty"); }
        if (resultElems.filter(".empty").length == 5) { $("div#humanySuggestResult div.all-empty").show(); humanyEventTracker.SendEvent(1); }
        else if (resultElems.filter(".searching").length == 0) { resultElems.find("span.status:visible").eq(0).addClass("first"); humanyEventTracker.SendEvent(1); }
        $("#humanySuggestSearchInput").removeClass("searching");
        initCheckForLoadingContainers();
    });

    $.getJSON("http://fritidsresor.humany.com/" + WebGuideStrings.countryCode + "/json_flat.asp?entry=" + escape(inputValue) + "&type=faq&pageSize=" + itemsPerSuggestion + "&pageNumber=1&suggest=true&callback=?", function(data) {
        renderFaqResults(data, resultElems);
        initCheckForLoadingContainers();
    });
}
renderFaqResults = function(data, resultElems) {
    resultElems.eq(4).addClass("searching").find("div.entry-item-faq").remove();
    var faqHTML = "";
    var faqCounter = 0;
    if (data.faq != null && data.numberOfHits > 0) {
        $.each(data.faq, function(ifaq, faq) {
            if (faqCounter < itemsPerPage) {
                faqHTML += "<div class=\"entry-item-faq\">" + ((faq.title != "") ? "<h4>" + faq.title + "</h4>" : "") +
                            "<span>" + faq.answer + "</span>" + "</div>";
            }
            faqCounter++;
        });
    }
    resultElems.eq(4).children("h3").after(faqHTML);

    humanyEventTracker.SetFaqResult(data.numberOfHits);

    if (resultElems.eq(4).children("div.entry-item-faq").length > 0) {
        resultElems.eq(4).removeClass("searching").show();

        resultElems.eq(4).find("a").bind("click", function(e) {
            if ($(this).attr("href").indexOf("fritidsresor.humany.com") != -1) {
                $.getJSON($(this).attr("href") + "&callback=?", function(datadata) {
                    renderFaqResults(datadata, resultElems);
                });
                return false;
            }
        });

    } else { resultElems.eq(4).removeClass("searching").addClass("empty"); }
    if (resultElems.filter(".empty").length == 5) { $("div#humanySuggestResult div.all-empty").show(); humanyEventTracker.SendEvent(1); }
    else if (resultElems.filter(".searching").length == 0) { resultElems.find("span.status:visible").eq(0).addClass("first"); humanyEventTracker.SendEvent(1); }
    $("#humanySuggestSearchInput").removeClass("searching");
}

performHumanySearchLarge = function() {
    $("div.tab-content div.all-empty").hide();
    var inputValue = $.trim($("#humanySearchInput").val()).toLowerCase();
    if (inputValue == "" || inputValue == currentSearchText) {
        currentSearchText = inputValue;
        $("#humanySearchInput").removeClass("searching");
        return;
    }
    else if (inputValue == initialTextValue) {
        $("#humanySearchInput").removeClass("searching");
        return;
    }
    currentSearchText = inputValue;

    humanyEventTracker.SetSearchPhrase(inputValue);

    var faqResultHTML = "<div class=\"faq-result searching\"></div>";
    var faqResultElem = $(faqResultHTML);
    $("div.tab-content div.section-container").eq(0).children("div.section-content").html("").append(faqResultElem);
    $.getJSON("http://fritidsresor.humany.com/" + WebGuideStrings.countryCode + "/json_flat.asp?entry=" + escape(inputValue) + "&type=faq&pageSize=" + itemsPerPage + "&pageNumber=1&callback=?", function(data) {
        renderFaqResultsLarge(data, faqResultElem);
        initCheckForLoadingContainers();
    });

    var countriesResultHTML = "<div class=\"country-result searching\"></div>";
    getPagedCountries($(countriesResultHTML), 1);

    var destinationsResultHTML = "<div class=\"destination-result searching\"></div>";
    getPagedDestinations($(destinationsResultHTML), 1);

    var hotelResultHTML = "<div class=\"hotel-result searching\"></div>";
    getPagedHotels($(hotelResultHTML), 1);

    var excursionsResultHTML = "<div class=\"excursion-result searching\"></div>";
    getPagedExcursions($(excursionsResultHTML), 1);
}

renderFaqResultsLarge = function(data, faqResultElem) {
    var faqHTML = "";
    var tipHTML = "";
    var faqCounter = 0;
    if (data.faq != null) {
        $("div.tab-content div.section-container").eq(0).removeClass("number-of-hits-0").removeClass("number-of-hits-1").addClass(String.format("number-of-hits-{0}", data.numberOfHits));
        $.each(data.faq, function(i, faq) {
            if (faqCounter < itemsPerPage) {
                faqHTML += ((faq.title != "") ? "<h3>" + faq.title + "</h3>" : "") +
                            "<span>" + faq.answer + "</span>";
                tipHTML += (typeof (faq.suggestion) != "undefined" && faq.suggestion != null && faq.suggestion != "") ? "<p>" + faq.suggestion + "</p>" : "";
            }
            faqCounter++;
        });
    }
    faqResultElem.append(faqHTML);

    humanyEventTracker.SetFaqResult(data.numberOfHits);

    $("ul.tabs-large li").eq(1).find("span b").text((data.numberOfHits > 0) ? "(" + data.numberOfHits + ")" : "");
    $("div.right-column ul.tab-links li").eq(1).find("b").text((data.numberOfHits > 0) ? "(" + data.numberOfHits + ")" : "");
    $("div#tab-box-large div.right-column div.small-box div.small-box-content").html(tipHTML).find("a.suggestion").click(function() {
        $("input#humanySearchInput").val($("input#humanySearchInput").val() + " " + $(this).text());
        initHumanySearchLarge();
    });
    if (faqResultElem.children("span").length > 0) {
        faqResultElem.removeClass("searching");

        faqResultElem.find("a").bind("click", function(e) {
            if ($(this).attr("href").indexOf("fritidsresor.humany.com") != -1) {
                faqResultElem.addClass("searching").html("");
                $.getJSON($(this).attr("href") + "&callback=?", function(datadata) {
                    renderFaqResultsLarge(datadata, faqResultElem);
                });
                return false;
            }
        });

    } else { faqResultElem.removeClass("searching").addClass("empty").html(WebGuideStrings.searchNoResult); }
    if (($("div.tab-content div.section-container .empty").length == 4) || ($("div.tab-content div.section-container .searching").length == 0)) { humanyEventTracker.SendEvent(1); }
    $("#humanySearchInput").removeClass("searching");
}

getItemHTML = function(counter, item, cssClass, catalogues) {
    if (item == null) { return ""; }
    var seasonIconHTML = "";
    if (catalogues != null) {
        seasonIconHTML = getSeasonIconHTML(catalogues, item.catalogue_id);
    }
    var itemName = item.name;
    var itemText = ((typeof (item.text) != "undefined") ? item.text : "");
    if (itemText == "") { itemText = (typeof (item.info) != "undefined" && typeof (item.info.usp) != "undefined") ? item.info.usp : ""; }
    if (itemName == "" && itemText == "" && typeof (item.city) != "undefined") { itemName = item.city; }
    return "<div class=\"entry-item" + ((counter > 0) ? " delimiter" : "") + "" + ((typeof (cssClass) != "undefined") ? " " + cssClass : "") + "\">" +
            "<img src=\"" + item.media.icon_picture.replace(/w=152&h=100/gi, "cw=45&h=30&ct=0") + "\" class=\"thumb\" alt=\"\" />" +
            "<div class=\"info" + (seasonIconHTML != "" ? " info-small" : "") + "\">" +
                "<h4><a href=\"" + item.page + "\">" + itemName + ((typeof (item.grade) != "undefined") ? " " + writeHotelGrade(item.grade) : "") + "</a></h4>" +
                "<p>" + itemText + "</p>" +
            "</div>" +
            seasonIconHTML +
            "<div class=\"clear\"></div>" +
        "</div>";
}

getHotelHTML = function(counter, item, cssClass, catalogues, priceExample) {
    if (item == null) { return ""; }
    var seasonIconHTML = "";
    var priceExampleHTML = "", priceExampleInfoHTML = "";
    if (catalogues != null) {
        seasonIconHTML = getSeasonIconHTML(catalogues, item.catalogue_id);
    }
    if (priceExample != null) {
        priceExampleHTML = getPriceExampleHTML(priceExample);
        priceExampleInfoHTML = getPriceExampleTextHTML(priceExample);
    }
    var itemName = item.name;
    var itemText = ((typeof (item.text) != "undefined") ? item.text : "");
    if (itemText == "") { itemText = (typeof (item.info) != "undefined" && typeof (item.info.usp) != "undefined") ? item.info.usp : ""; }
    if (itemName == "" && itemText == "" && typeof (item.city) != "undefined") { itemName = item.city; item.city = ""; }
    return "<div class=\"entry-item" + ((counter > 0) ? " delimiter" : "") + "" + ((typeof (cssClass) != "undefined") ? " " + cssClass : "") + "\">" +
            "<img src=\"" + item.media.icon_picture.replace(/w=152&h=100/gi, "w=115&h=78&ct=0") + "\" class=\"hotel-thumb\" alt=\"\" />" +
            "<div class=\"info" + (seasonIconHTML != "" ? " info-small hotel-info-small" : "") + "\">" +
                "<div class=\"breadcrumbs\"><a href=\"" + item.country_page + "\">" + item.country + "</a>" + ((typeof (item.destination) != "undefined" && item.destination != null && item.destination != "") ? "<span class=\"pipe\">|</span><a href=\"" + item.destination_page + "\">" + item.destination + "</a>" : "") + ((typeof (item.city) != "undefined" && item.city != null && item.city != "") ? "<span class=\"pipe\">|</span><a href=\"" + item.city_page + "\">" + item.city + "</a>" : "") + "</div>" +
                "<h4><a href=\"" + item.page + "\">" + itemName + ((typeof (item.grade) != "undefined") ? " " + writeHotelGrade(item.grade) : "") + "</a></h4>" +
                "<p>" + itemText + "</p>" +
            "</div>" +
            priceExampleHTML +
            seasonIconHTML +
            "<div class=\"clear\"></div>" +
            priceExampleInfoHTML +
        "</div>";
}

getExcursionHTML = function(counter, item) {
    if (item == null) { return ""; }
    return "<div class=\"entry-item" + ((counter > 0) ? " delimiter" : "") + "\">" +
            "<img src=\"" + item.media.icon_picture.replace(/g=excursion/gi, "&g=extra").replace(/w=152&h=100/gi, "cw=45&h=30&ct=0") + "\" class=\"thumb\" alt=\"\" />" +
            "<div class=\"info\">" +
                "<h4><a href=\"" + item.page + "\">" + item.name + "</a></h4>" +
                "<p>" + item.intro + "</p>" +
            "</div>" +
            "<div class=\"clear\"></div>" +
        "</div>";
}

getSeasonIconHTML = function(catalogues, catid) {
    var seasonIconHTML = "";
    $.each(catalogues, function(icatalogue, catalogue) {
        if (catalogue.id == catid) {
            seasonIconHTML = "<div class=\"season-icon season-" + catalogue.symbol + "\">" + catalogue.name + "</div>";
            return;
        }
    });
    return seasonIconHTML;
}

getPriceExampleHTML = function(priceExample) {
    return "<span class=\"hotel-price-example\">" + WebGuideStrings.priceExamplePerAdult + "*<b>" + formatPriceExample(parseInt(priceExample.price.replace(" ", ""), 10) / 2) + "</b></span>";
}

formatPriceExample = function(n) {
    if (isNaN(n)) { return ("0"); }
    s = n.toString(); nStart = s.indexOf(" ");
    if (nStart < 0) { nStart = s.length; } nStart -= 3;
    while (nStart >= 1) { s = s.substring(0, nStart) + " " + s.substring(nStart, s.length); nStart -= 3; }
    return ((s.indexOf(WebGuideStrings.currencySign) != -1) ? s : s + WebGuideStrings.currencySign);
}

getPriceExampleTextHTML = function(priceexample) {
    var priceExampleInfoHTML = "";
    if ((typeof (priceexample) != "undefined") && (priceexample != null)) {
        priceExampleInfoHTML = "<div class=\"hotel-price-example-text\">* " + WebGuideStrings.date + " " + priceexample.departuredate + " | " + WebGuideStrings.departure + ": " + priceexample.departurecity + " | " + priceexample.lengthofstay + " " + WebGuideStrings.days + "</div>"
    }
    return priceExampleInfoHTML;
}

getHotelItemHTML = function(counter, country, destination, city, hotel) {
    return "<div class=\"c_1\">" +
            getHotelConceptHTML(hotel.category) +
            "<a href=\"#\">" + country.name + "</a> | " +
            ((typeof (destination.name) != "undefined" && destination.name != "") ? "<a href=\"#\">" + destination.name + "</a> | " : "") +
            "<a href=\"#\">" + city.name + "</a>" +
            "<h2>" + hotel.name + ((typeof (hotel.grade) != "undefined") ? " " + writeHotelGrade(hotel.grade) : "") + "</h2>" +
            "<div class=\"clear\"></div>" +
        "</div>" +
        "<div class=\"c_2\">" +
            ((typeof (hotel.info) != "undefined" && typeof (hotel.info[0]) != "undefined" && typeof (hotel.info[0].usp) != "undefined") ? "<h3 class=\"usp\"><span>" + hotel.info[0].usp + "</span></h3>" : "") +
            "<div class=\"left-container\">" +
                "<div style=\"background-image: url(" + hotel.media.icon_picture.replace(/&w=152&h=100/gi, "&w=254") + ");\" class=\"hotel-image-bg\">" +
                    "<a class=\"hotel-about-info\" href=\"javascript:void(0)\">" +
                        "<img alt=\"" + hotel.name + "\" src=\""+oBaseAppSettings.IncludeSiteDirectory+"/Images/Layout/HotelItem/hi-border.png\"/>" +
                    "</a>" +
                "</div>" +
            "</div>" +
            "<div class=\"right-container\">" +
                "<div class=\"hotel-facts-dp\">" +
                    "<table class=\"hotel-facts-dp\">" +
                        "<tbody>" +
                            getHotelFactsHTML(hotel.fact) +
                        "</tbody>" +
                    "</table>" +
                    "<a href=\"#\" class=\"read-more\">Läs mer &#187;</a>" +
                "</div> " +
                getPriceExamplePriceHTML(hotel.priceexample) +
            "</div>" +
            "<input type=\"image\" class=\"select-package-btn\" alt=\"Välj resa\" src=\""+oBaseAppSettings.IncludeSiteDirectory+"/Images/Buttons/1/select.gif\"/>" +
        "</div>" +
        getPriceExampleInfoHTML(hotel.priceexample);
}

getHotelConceptHTML = function(concept) {
    var conceptHTML = "";
    if (concept == "BlueVillage") {
        conceptHTML = "<img class=\"concept-logo\" src=\""+oBaseAppSettings.IncludeSiteDirectory+"/Images/ConceptLogo/1/BlueVillage.png\" />";
    } else if (concept == "BlueVillageExotic") {
        conceptHTML = "<img class=\"concept-logo\" src=\""+oBaseAppSettings.IncludeSiteDirectory+"/Images/ConceptLogo/1/BlueVillageExotic.png\" />";
    } else if (concept == "BlueInclusive") {
        conceptHTML = "<img class=\"concept-logo\" src=\""+oBaseAppSettings.IncludeSiteDirectory+"/Images/ConceptLogo/1/BlueInclusive.png\" />";
    } else if (concept == "BlueCouples") {
        conceptHTML = "<img class=\"concept-logo\" src=\""+oBaseAppSettings.IncludeSiteDirectory+"/Images/ConceptLogo/1/BlueCouples.png\" />";
    } else if (concept == "BlueSelection") {
        conceptHTML = "<img class=\"concept-logo\" src=\""+oBaseAppSettings.IncludeSiteDirectory+"/Images/ConceptLogo/1/BlueSelection.png\" />";
    } else if (concept == "BlueUnique") {
        conceptHTML = "<img class=\"concept-logo\" src=\""+oBaseAppSettings.IncludeSiteDirectory+"/Images/ConceptLogo/1/BlueUnique.png\" />";
    }
    return conceptHTML;
}

getHotelFactsHTML = function(facts) {
    var factHTML = "";
    if ((typeof (facts) != "undefined") && (facts != null)) {
        $.each(facts, function(ifact, fact) {
            if (ifact > 4) {
                return;
            }
            factHTML += "<tr class=\"" + ((ifact % 2 == 0) ? "odd" : "") + "\">" +
                    "<td class=\"label\">" + fact.text + ":</td><td>" + fact.value + "</td>" +
                "</tr>"
        });
    }
    return factHTML;
}

getPriceExamplePriceHTML = function(priceexample) {
    var priceExamplePriceHTML = "";
    if ((typeof (priceexample) != "undefined") && (priceexample != null)) {
        priceExamplePriceHTML = "<span class=\"hotel-price-text\">Prisex/vuxen*</span><span class=\"hotel-price\">" + priceexample.price + ":-</span>";
    }
    return priceExamplePriceHTML;
}

getPriceExampleInfoHTML = function(priceexample) {
    var priceExampleInfoHTML = "";
    if ((typeof (priceexample) != "undefined") && (priceexample != null)) {
        priceExampleInfoHTML = "<div class=\"c_3\">* Datum " + priceexample.departuredate + " | Avresa från " + priceexample.departurecity + " | " + priceexample.lengthofstay + " dagar</div>"
    }
    return priceExampleInfoHTML;
}

writeHotelGrade = function(grade) {
    var gradeLetters = "";
    var letter = "F";
    if ($("body").hasClass("brand-id-2") || $("body").hasClass("brand-id-4")) { letter = "S"; }
    for (i = 0; i < Math.floor(parseInt(grade)); i++) {
        gradeLetters += letter;
    }
    if (grade.toString().length > 1) {
        gradeLetters += "+";
    }
    return gradeLetters;
}

bindEntryItemEvents = function(entryItems) {
    entryItems.hover(
        function() {
            $(this).addClass("hover");
        },
        function() {
            $(this).removeClass("hover");
        }
    );
    entryItems.click(function(event) {
        event.stopPropagation();
        document.location.href = $(this).find("h4 a").attr("href");
    });
}

step = function(keyCode) {
    var selectedIndex = $("div#humanySuggestResult div.entry-item").index($("div#humanySuggestResult div.hover"));
    selectedIndex = (keyCode == 38) ? (selectedIndex - 1) : (selectedIndex + 1);
    if (selectedIndex < -1) { selectedIndex = ($("div#humanySuggestResult div.entry-item").length - 1); }
    else if (selectedIndex > $("div#humanySuggestResult div.entry-item").length) { selectedIndex = -1; }
    $("div#humanySuggestResult div.entry-item").removeClass("hover");
    if (selectedIndex >= 0) {
        $("div#humanySuggestResult div.entry-item").eq(selectedIndex).addClass("hover");
    }
}

browseToLargeSearch = function() {
    var entryValue = $.trim($("input#humanySuggestSearchInput").val());
    if (entryValue == "" || entryValue == "undefined" || typeof (entryValue) == "undefined") {
        $("#humanySuggestSearchInput").removeClass("searching");
        return;
    }
    if (entryValue != initialTextValue) {
        document.location.href = WebGuideStrings.showAllLinkUrl + "?humanyEntry=" + entryValue + "&view=" + Math.ceil(999999 * Math.random());
    }
    else {
        // For notfound page
        var notFoundEntryValue = $("input#search-field").val();
        if (notFoundEntryValue != initialTextValue) {
            document.location.href = WebGuideStrings.showAllLinkUrl + "?humanyEntry=" + notFoundEntryValue + "&view=" + Math.ceil(999999 * Math.random());
        }
    }
}

browseToItem = function(itemIndex) {
    $("div#humanySuggestResult div.entry-item").eq(itemIndex).trigger("click");
}

jQuery.fn.extend({
    setNumberOfHitsCssClass: function(numberOfHits) {
        if (numberOfHits == 0) {
            $(this).addClass("disabled");
        } else {
            $(this).removeClass("disabled");
        }
        return $(this);
    },
    addPaging: function(numberOfHits, searchType) {
        var itemContainer = $(this);
        if (numberOfHits <= itemsPerPage) {
            itemContainer.find("div.section-header span.item-count b").hide();
        } else {
            itemContainer.find("div.section-header span.item-count b").show();
        }
        var pagingContainer = $(this).prev("div.section-paging");
        pagingContainer.children("ul.paging-items").html("");
        var numberOfPages = Number(numberOfHits / itemsPerPage);
        if ((numberOfHits % itemsPerPage) > 0) {
            numberOfPages++;
        }
        if (numberOfPages < 2) {
            return;
        }
        var listItemsHTML = "";
        for (i = 1; i <= numberOfPages; i++) {
            listItemsHTML += "<li class=\"" + ((i == 1) ? "selected " : "") + ((i > 9) ? "two-digits " : "") + ((i > itemsPerPage) ? "overflow " : "") + "digit\"><span>" + i.toString() + "</span></li>";
        }
        var listItems = $("<li class=\"prev disabled\">&#171;&#171;</li>" + listItemsHTML + "<li class=\"next\">&#187;&#187;</li>");
        listItems.filter(".overflow:first").addClass("dotted");
        pagingContainer.show().children("ul.paging-items").append(listItems);
        listItems.filter(".digit").click(function() {
            pagingContainer.find("ul.paging-items li.digit").removeClass("selected");
            $(this).addClass("selected");
            var selectedIndex = pagingContainer.find("ul.paging-items li.digit").index($(this));
            pagingContainer.find("ul.paging-items li.prev, ul.paging-items li.next").removeClass("disabled");
            if (selectedIndex == 0) {
                pagingContainer.find("ul.paging-items li.prev").addClass("disabled");
            } else if (selectedIndex >= (pagingContainer.find("ul.paging-items li.digit").length - 1)) {
                pagingContainer.find("ul.paging-items li.next").addClass("disabled");
            }
            if ($(this).hasClass("dotted")) {
                var dir = (!$(this).prev("li.digit").hasClass("overflow")) ? (selectedIndex - 1) : (selectedIndex - itemsPerPage);
                var listItemsNext = null;
                if (dir > 0) {
                    listItemsNext = listItems.filter(".digit").removeClass("dotted").addClass("overflow").filter(":gt(" + (dir) + "):lt(" + (itemsPerPage) + ")").removeClass("overflow");
                } else {
                    listItemsNext = listItems.filter(".digit").removeClass("dotted").addClass("overflow").filter(":lt(" + (itemsPerPage) + ")").removeClass("overflow");
                }
                listItemsNext.filter(":first").prev("li.digit").addClass("dotted");
                listItemsNext.filter(":last").next("li.digit").addClass("dotted");
            }
            itemContainer.find("div.section-content").children("div").html("").addClass("searching");
            if (searchType == "countries") {
                getPagedCountries(itemContainer.find("div.section-content").children("div"), selectedIndex + 1);
            } else if (searchType == "destinations") {
                getPagedDestinations(itemContainer.find("div.section-content").children("div"), selectedIndex + 1);
            } else if (searchType == "hotels") {
                getPagedHotels(itemContainer.find("div.section-content").children("div"), selectedIndex + 1);
            } else if (searchType == "excursions") {
                getPagedExcursions(itemContainer.find("div.section-content").children("div"), selectedIndex + 1);
            }
        });
        listItems.filter(function() { return ($(this).hasClass("prev") || $(this).hasClass("next")); }).click(function() {
            if ($(this).hasClass("disabled")) {
                return;
            }
            var dir = (($(this).hasClass("next")) ? 1 : -1);
            var selectedIndex = (pagingContainer.find("ul.paging-items li.digit").index(pagingContainer.find("ul.paging-items li.digit.selected"))) + dir;
            pagingContainer.find("ul.paging-items li.digit").eq(selectedIndex).trigger("click");
        });
        return $(this);
    },
    removePaging: function() {
        var pagingContainer = $(this).prev("div.section-paging");
        pagingContainer.hide();
        pagingContainer.find("ul.paging-items li").unbind("click");
        return $(this);
    }
});

getPagedCountries = function(countryContainer, pageNum) {
    var countriesResultElem = countryContainer;
    countriesResultElem[0].itemsPerPage = itemsPerPage;
    $("div.tab-content div.section-container").eq(1).removeClass("disabled").find("div.section-header span.item-count").hide();
    if (pageNum == 1) {
        $("div.tab-content div.section-container").eq(1).children("div.section-content").html("").append(countriesResultElem);
    }
    $.getJSON("http://fritidsresor.humany.com/" + WebGuideStrings.countryCode + "/json_flat.asp?entry=" + escape(currentSearchText) + "&type=country&pageSize=" + itemsPerPage + "&pageNumber=" + pageNum + "&callback=?", function(data) {
        var entryHTML = "";
        var entryCounter = 0;
        if (data.country != null) {
            $.each(data.country, function(ientry, entry) {
                if (entryCounter < itemsPerPage) {
                    entryHTML += getItemHTML(entryCounter, entry, "", data.catalogue);
                }
                entryCounter++;
            });
        }

        humanyEventTracker.SetCountryResult(data.numberOfHits);

        $("div.tab-content div.section-container").eq(1).setNumberOfHitsCssClass(data.numberOfHits).find("div.section-header span.item-count").show().children("span").html(String.format(WebGuideStrings.textNumberOfHits, getFirstPos(pageNum), getLastPos(pageNum, data.numberOfHits), data.numberOfHits));
        $("ul.tabs-large li").eq(2).setNumberOfHitsCssClass(data.numberOfHits).find("span b").text("(" + data.numberOfHits + ")");
        $("div.right-column ul.tab-links li").eq(2).setNumberOfHitsCssClass(data.numberOfHits).find("b").text("(" + data.numberOfHits + ")");
        countriesResultElem[0].numberOfHits = data.numberOfHits;
        countriesResultElem.append(entryHTML);
        if (countriesResultElem.children("div.entry-item").length > 0) {
            countriesResultElem.removeClass("searching");
            bindEntryItemEvents(countriesResultElem.children("div.entry-item"));
            if (pageNum == 1) {
                $("div.tab-content div.section-container.countries").removePaging().addPaging(data.numberOfHits, "countries");
            }
        } else { $("div.tab-content div.section-container.countries").removePaging(); countriesResultElem.removeClass("searching").addClass("empty").html(WebGuideStrings.searchNoResult); }
        if (($("div.tab-content div.section-container.disabled").length == 4) && ($("div.tab-content div.section-container.number-of-hits-0").length == 1)) { $("div.tab-content div.all-empty").show(); humanyEventTracker.SendEvent(pageNum); }
        else if ($("div.tab-content div.section-container .searching").length == 0) { humanyEventTracker.SendEvent(pageNum); }
        $("#humanySearchInput").removeClass("searching");
        initCheckForLoadingContainers();
    });
}

getPagedDestinations = function(destinationContainer, pageNum) {
    var destinationsResultElem = destinationContainer;
    destinationsResultElem[0].itemsPerPage = itemsPerPage;
    $("div.tab-content div.section-container").eq(2).removeClass("disabled").find("div.section-header span.item-count").hide();
    if (pageNum == 1) {
        $("div.tab-content div.section-container").eq(2).children("div.section-content").html("").append(destinationsResultElem);
    }
    $.getJSON("http://fritidsresor.humany.com/" + WebGuideStrings.countryCode + "/json_flat.asp?entry=" + escape(currentSearchText) + "&type=destination&pageSize=" + itemsPerPage + "&pageNumber=" + pageNum + "&callback=?", function(data) {
        var destinationHTML = "";
        var destinationCounter = 0;
        if (data.destination != null) {
            $.each(data.destination, function(idestination, destination) {
                var cssClass = (typeof (destination.destination) != "undefined") ? "city-item" : "destination-item";
                if (typeof (destination.name) != "undefined") {
                    if (destinationCounter < itemsPerPage) {
                        destinationHTML += getItemHTML(destinationCounter, destination, cssClass, data.catalogue);
                    }
                    destinationCounter++;
                }
            });
        }

        humanyEventTracker.SetDestinationResult(data.numberOfHits);

        $("div.tab-content div.section-container").eq(2).setNumberOfHitsCssClass(data.numberOfHits).find("div.section-header span.item-count").show().children("span").html(String.format(WebGuideStrings.textNumberOfHits, getFirstPos(pageNum), getLastPos(pageNum, data.numberOfHits), data.numberOfHits));
        $("ul.tabs-large li").eq(3).setNumberOfHitsCssClass(data.numberOfHits).find("span b").text("(" + data.numberOfHits + ")");
        $("div.right-column ul.tab-links li").eq(3).setNumberOfHitsCssClass(data.numberOfHits).find("b").text("(" + data.numberOfHits + ")");
        destinationsResultElem[0].numberOfHits = data.numberOfHits;
        destinationsResultElem.append(destinationHTML);
        if (destinationsResultElem.children("div.entry-item").length > 0) {
            destinationsResultElem.removeClass("searching");
            bindEntryItemEvents(destinationsResultElem.children("div.entry-item"));
            if (pageNum == 1) {
                $("div.tab-content div.section-container.destinations").removePaging().addPaging(data.numberOfHits, "destinations");
            }
        } else { $("div.tab-content div.section-container.destinations").removePaging(); destinationsResultElem.removeClass("searching").addClass("empty").html(WebGuideStrings.searchNoResult); }
        if (($("div.tab-content div.section-container.disabled").length == 4) && ($("div.tab-content div.section-container.number-of-hits-0").length == 1)) { $("div.tab-content div.all-empty").show(); humanyEventTracker.SendEvent(pageNum); }
        else if ($("div.tab-content div.section-container .searching").length == 0) { humanyEventTracker.SendEvent(pageNum); }
        $("#humanySearchInput").removeClass("searching");
        initCheckForLoadingContainers();
    });
}

getPagedHotels = function(hotelContainer, pageNum) {
    var hotelResultElem = hotelContainer;
    hotelResultElem[0].itemsPerPage = itemsPerPage;
    $("div.tab-content div.section-container").eq(3).removeClass("disabled").find("div.section-header span.item-count").hide();
    if (pageNum == 1) {
        $("div.tab-content div.section-container").eq(3).children("div.section-content").html("").append(hotelResultElem);
    }
    $.getJSON("http://fritidsresor.humany.com/" + WebGuideStrings.countryCode + "/json_flat.asp?entry=" + escape(currentSearchText) + "&type=hotel&pageSize=" + itemsPerPage + "&pageNumber=" + pageNum + "&callback=?", function(data) {
        var hotelHTML = "";
        var hotelCounter = 0;
        if (data.hotel != null) {
            $.each(data.hotel, function(ihotel, hotel) {
                if (hotelCounter < itemsPerPage) {
                    hotelHTML += getHotelHTML(hotelCounter, hotel, "", data.catalogue, hotel.priceexample);
                }
                hotelCounter++;
            });
        }

        humanyEventTracker.SetHotelResult(data.numberOfHits);

        $("div.tab-content div.section-container").eq(3).setNumberOfHitsCssClass(data.numberOfHits).find("div.section-header span.item-count").show().children("span").html(String.format(WebGuideStrings.textNumberOfHits, getFirstPos(pageNum), getLastPos(pageNum, data.numberOfHits), data.numberOfHits));
        $("ul.tabs-large li").eq(4).setNumberOfHitsCssClass(data.numberOfHits).find("span b").text("(" + data.numberOfHits + ")");
        $("div.right-column ul.tab-links li").eq(4).setNumberOfHitsCssClass(data.numberOfHits).find("b").text("(" + data.numberOfHits + ")");
        hotelResultElem[0].numberOfHits = data.numberOfHits;
        hotelResultElem.append(hotelHTML);
        if (hotelResultElem.children("div.entry-item").length > 0) {
            hotelResultElem.removeClass("searching");
            bindEntryItemEvents(hotelResultElem.children("div.entry-item")); // remove
            if (pageNum == 1) {
                $("div.tab-content div.section-container.hotels").removePaging().addPaging(data.numberOfHits, "hotels");
            }
        } else { $("div.tab-content div.section-container.hotels").removePaging(); hotelResultElem.removeClass("searching").addClass("empty").html(WebGuideStrings.searchNoResult); }
        if (($("div.tab-content div.section-container.disabled").length == 4) && ($("div.tab-content div.section-container.number-of-hits-0").length == 1)) { $("div.tab-content div.all-empty").show(); humanyEventTracker.SendEvent(pageNum); }
        else if ($("div.tab-content div.section-container .searching").length == 0) { humanyEventTracker.SendEvent(pageNum); }
        $("#humanySearchInput").removeClass("searching");
        initCheckForLoadingContainers();
    });
}

getPagedExcursions = function(excursionContainer, pageNum) {
    var excursionsResultElem = excursionContainer;
    excursionsResultElem[0].itemsPerPage = itemsPerPage;
    $("div.tab-content div.section-container").eq(4).removeClass("disabled").find("div.section-header span.item-count").hide();
    if (pageNum == 1) {
        $("div.tab-content div.section-container").eq(4).children("div.section-content").html("").append(excursionsResultElem);
    }
    $.getJSON("http://fritidsresor.humany.com/" + WebGuideStrings.countryCode + "/json_flat.asp?entry=" + escape(currentSearchText) + "&type=excursion&pageSize=" + itemsPerPage + "&pageNumber=" + pageNum + "&callback=?", function(data) {
        var excursionHTML = "";
        var excursionCounter = 0;
        if (data.excursion != null) {
            $.each(data.excursion, function(i, excursion) {
                if (excursionCounter < itemsPerPage) {
                    excursionHTML += getExcursionHTML(excursionCounter, excursion);
                }
                excursionCounter++;
            });
        }

        humanyEventTracker.SetExcursionResult(data.numberOfHits);
        
        $("div.tab-content div.section-container").eq(4).setNumberOfHitsCssClass(data.numberOfHits).find("div.section-header span.item-count").show().children("span").html(String.format(WebGuideStrings.textNumberOfHits, getFirstPos(pageNum), getLastPos(pageNum, data.numberOfHits), data.numberOfHits));
        $("ul.tabs-large li").eq(5).setNumberOfHitsCssClass(data.numberOfHits).find("span b").text("(" + data.numberOfHits + ")");
        $("div.right-column ul.tab-links li").eq(5).setNumberOfHitsCssClass(data.numberOfHits).find("b").text("(" + data.numberOfHits + ")");
        excursionsResultElem[0].numberOfHits = data.numberOfHits;
        excursionsResultElem.append(excursionHTML);
        if (excursionsResultElem.children("div.entry-item").length > 0) {
            excursionsResultElem.removeClass("searching");
            bindEntryItemEvents(excursionsResultElem.children("div.entry-item"));
            if (pageNum == 1) {
                $("div.tab-content div.section-container.excursions").removePaging().addPaging(data.numberOfHits, "excursions");
            }
        } else { $("div.tab-content div.section-container.excursions").removePaging(); excursionsResultElem.removeClass("searching").addClass("empty").html(WebGuideStrings.searchNoResult); }
        if (($("div.tab-content div.section-container.disabled").length == 4) && ($("div.tab-content div.section-container.number-of-hits-0").length == 1)) { $("div.tab-content div.all-empty").show(); humanyEventTracker.SendEvent(pageNum); }
        else if ($("div.tab-content div.section-container .searching").length == 0) { humanyEventTracker.SendEvent(pageNum); }
        $("#humanySearchInput").removeClass("searching");
        initCheckForLoadingContainers();
    });
}

getFirstPos = function(pageNum) {
    return (((pageNum - 1) * itemsPerPage) + 1).toString();
}

getLastPos = function(pageNum, numberOfHits) {
    var lastPos = (pageNum * itemsPerPage);
    return ((lastPos > numberOfHits) ? numberOfHits : lastPos);
}
