$(document).ready(function() {

     $(function() {
               $('a[title]').removeAttr('title');
     });

     $(".lightbox").lightbox({
			    fitToScreen: true,
			    imageClickClose: false
		    });
	
	$("#lpromoblock").html(base64_decode($("#lpromoblock").html()));
    $("#bpromoblock").html(base64_decode($("#bpromoblock").html()));

    $("#lpromoblock a").attr("href",'/connect.php?link='+base64_encode($("#lpromoblock a").attr("href")));
    $("#bpromoblock a").attr("href",'/connect.php?link='+base64_encode($("#bpromoblock a").attr("href")));
     
    $("#lpromoblock").css("display","block");
    $("#bpromoblock").css("display","block");

    
	// METANAV
	if ( $("#metanav").length ) {
		$("#metanav > li").hover(function() {

			var thisposition = $(this).position().left;
			var thiswidth = $(this).width();
			var posfromleft = thisposition + ((thiswidth / 2) - 10);

			var child = $(".dropdown",$(this));
			var arrow = $(".arrow_down",$(this));
			arrow.css("left",posfromleft);

			if ( child.hasClass("dropdown") ) {
				var siteheight = $("html").height();
				$("#layer").height(siteheight).show();
				child.show();
				arrow.show();

				// ADJUST VERTICAL BORDERS IN MAINNAV

				if ( $(".bookinglinks",child) ) {
					
					var linkblock = $(".booking_links .linkblock",child);
					var lblength = linkblock.length;
					var maxheight = 0;

					for ( j=0; j<lblength; j++ ) {
						var currentlb = $(".linkblock:eq("+j+")",child);
						var clbheight = currentlb.height();
						if ( clbheight > maxheight ) {
							maxheight = clbheight;
						}
					}
					
					linkblock.height(maxheight);

				}

			}
			if ( child.hasClass("simple")) {
				child.css("left",thisposition+1);
			}
		},
		function() {
			var child = $(".dropdown",$(this));
			var arrow = $(".arrow_down",$(this));
			child.hide();
			arrow.hide();
			$("#layer").hide();
		});
	}

});



/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

var mouseX;
var mouseY;
jQuery(document).ready(function(){
   $(document).mousemove(function(e){
      mouseX = e.pageX
      mouseY = e.pageY;
   }); 
})

function gotolink(val,rewrite){
	if(base64_decode(val)!=''){
		window.location.href='/connect.php?link='+val;
	}
    else{ window.location.href='/index.php';}
    return false;
}    
    
function deletecat(ids,catid) {
	$.post(  
            '/ajax.php',  
            {ids: ids, catid: catid},  
            function(responseText){  
               alert(responseText);  
               window.location.reload();
            },  
            "html"  
        );  
}    
    
function sitesearch(){
	safestring=safestring($("#sinput").val());
	searchurl='/search/'+safestring+'.html';
	if(strlen(safestring)<4){alert("Search query is too low");$("#sinput").val('Search ...');return false;
}
document.location.href=searchurl;return false;}



function AddReview(pid,ptitle,pimage){
    alert("Sorry, but review feature is temporary disabled");
}



function safestring(unsafe_string){unsafe_string=strtolower(unsafe_string);for(k=0;k<48;k++)unsafe_string=str_replace(chr(k),"-",unsafe_string);for(k=58;k<97;k++)unsafe_string=str_replace(chr(k),"-",unsafe_string);for(k=123;k<255;k++)unsafe_string=str_replace(chr(k),"-",unsafe_string);safe_string=str_replace("----","-",unsafe_string);safe_string=str_replace("---","-",unsafe_string);safe_string=str_replace("--","-",unsafe_string);safe_string=ltrim(safe_string,"-");safe_string=rtrim(safe_string,"-");return safe_string;}
function strtolower(str){return(str+'').toLowerCase();}
function chr(codePt){if(codePt>0xFFFF){codePt-=0x10000;return String.fromCharCode(0xD800+(codePt>>10),0xDC00+(codePt&0x3FF));}else{return String.fromCharCode(codePt);}}
function ltrim(str,charlist){charlist=!charlist?' \\s\u00A0':(charlist+'').replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g,'$1');var re=new RegExp('^['+charlist+']+','g');return(str+'').replace(re,'');}
function rtrim(str,charlist){charlist=!charlist?' \\s\u00A0':(charlist+'').replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g,'\\$1');var re=new RegExp('['+charlist+']+$','g');return(str+'').replace(re,'');}
function stristr(haystack,needle,bool){var pos=0;haystack+='';pos=haystack.toLowerCase().indexOf((needle+'').toLowerCase());if(pos==-1){return false;}else{if(bool){return haystack.substr(0,pos);}else{return haystack.slice(pos);}}}
function str_replace(search,replace,subject,count){var i=0,j=0,temp='',repl='',sl=0,fl=0,f=[].concat(search),r=[].concat(replace),s=subject,ra=r instanceof Array,sa=s instanceof Array;s=[].concat(s);if(count){this.window[count]=0;}for(i=0,sl=s.length;i<sl;i++){if(s[i]===''){continue;}for(j=0,fl=f.length;j<fl;j++){temp=s[i]+'';repl=ra?(r[j]!==undefined?r[j]:''):r[0];s[i]=(temp).split(f[j]).join(repl);if(count&&s[i]!==temp){this.window[count]+=(temp.length-s[i].length)/f[j].length;}}}return sa?s:s[0];}
function base64_decode(data){var b64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var o1,o2,o3,h1,h2,h3,h4,bits,i=0,ac=0,dec="",tmp_arr=[];if(!data){return data;}
data+='';do{h1=b64.indexOf(data.charAt(i++));h2=b64.indexOf(data.charAt(i++));h3=b64.indexOf(data.charAt(i++));h4=b64.indexOf(data.charAt(i++));bits=h1<<18|h2<<12|h3<<6|h4;o1=bits>>16&0xff;o2=bits>>8&0xff;o3=bits&0xff;if(h3==64){tmp_arr[ac++]=String.fromCharCode(o1);}else if(h4==64){tmp_arr[ac++]=String.fromCharCode(o1,o2);}else{tmp_arr[ac++]=String.fromCharCode(o1,o2,o3);}}while(i<data.length);dec=tmp_arr.join('');dec=this.utf8_decode(dec);return dec;}
function base64_encode(data){var b64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var o1,o2,o3,h1,h2,h3,h4,bits,i=0,ac=0,enc="",tmp_arr=[];if(!data){return data;}
data=this.utf8_encode(data+'');do{o1=data.charCodeAt(i++);o2=data.charCodeAt(i++);o3=data.charCodeAt(i++);bits=o1<<16|o2<<8|o3;h1=bits>>18&0x3f;h2=bits>>12&0x3f;h3=bits>>6&0x3f;h4=bits&0x3f;tmp_arr[ac++]=b64.charAt(h1)+b64.charAt(h2)+b64.charAt(h3)+b64.charAt(h4);}while(i<data.length);enc=tmp_arr.join('');switch(data.length%3){case 1:enc=enc.slice(0,-2)+'==';break;case 2:enc=enc.slice(0,-1)+'=';break;}
return enc;}
function utf8_decode(str_data){var tmp_arr=[],i=0,ac=0,c1=0,c2=0,c3=0;str_data+='';while(i<str_data.length){c1=str_data.charCodeAt(i);if(c1<128){tmp_arr[ac++]=String.fromCharCode(c1);i++;}else if((c1>191)&&(c1<224)){c2=str_data.charCodeAt(i+1);tmp_arr[ac++]=String.fromCharCode(((c1&31)<<6)|(c2&63));i+=2;}else{c2=str_data.charCodeAt(i+1);c3=str_data.charCodeAt(i+2);tmp_arr[ac++]=String.fromCharCode(((c1&15)<<12)|((c2&63)<<6)|(c3&63));i+=3;}}
return tmp_arr.join('');}
function utf8_encode(argString){var string=(argString+'');var utftext="";var start,end;var stringl=0;start=end=0;stringl=string.length;for(var n=0;n<stringl;n++){var c1=string.charCodeAt(n);var enc=null;if(c1<128){end++;}else if(c1>127&&c1<2048){enc=String.fromCharCode((c1>>6)|192)+String.fromCharCode((c1&63)|128);}else{enc=String.fromCharCode((c1>>12)|224)+String.fromCharCode(((c1>>6)&63)|128)+String.fromCharCode((c1&63)|128);}
if(enc!==null){if(end>start){utftext+=string.substring(start,end);}
utftext+=enc;start=end=n+1;}}
if(end>start){utftext+=string.substring(start,string.length);}
return utftext;}
function strlen(string){var str=string+'';var i=0,chr='',lgth=0;var getWholeChar=function(str,i){var code=str.charCodeAt(i);var next='',prev='';if(0xD800<=code&&code<=0xDBFF){if(str.length<=(i+1)){throw'High surrogate without following low surrogate';}
next=str.charCodeAt(i+1);if(0xDC00>next||next>0xDFFF){throw'High surrogate without following low surrogate';}
return str.charAt(i)+str.charAt(i+1);}else if(0xDC00<=code&&code<=0xDFFF){if(i===0){throw'Low surrogate without preceding high surrogate';}
prev=str.charCodeAt(i-1);if(0xD800>prev||prev>0xDBFF){throw'Low surrogate without preceding high surrogate';}
return false;}
return str.charAt(i);};for(i=0,lgth=0;i<str.length;i++){if((chr=getWholeChar(str,i))===false){continue;}
lgth++;}
return lgth;}
