//flash check
var MM_contentVersion = 6;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if (plugin)
{
	var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	for (var i = 0; i < words.length; ++i)
	{
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion = words[i]; 
	}
	var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1))
{
	document.write('<scr' + 'ipt language=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</scr' + 'ipt\> \n');
}

function getXMLHTTP() {
	if (typeof ActiveXObject!="undefined"){
		try {
			return new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(a){}
	}
	if(typeof XMLHttpRequest!="undefined"){
		return new XMLHttpRequest();
	}
	return null;
}

var ajaxEnabled = false;
function checkAjax() {
	// check for required DOM methods
	var hasDOM  = (document.getElementById && document.createElement) ? true : false;
	// check for XMLHTTP
	var hasXMLHTTP = ( getXMLHTTP() ) ? true : false;
	// check for Windows
	// temporarily not enabled in Mac; requires further debugging
	var detect = navigator.userAgent.toLowerCase();
	var isWin = (detect.indexOf('win') + 1) ? true : false;
	var isNotWin98 = ((detect.indexOf("win98") == -1) && (detect.indexOf("windows 98") == -1) ) ? true : false;
	var isIE50 = (detect.indexOf("msie 5.0")!=-1) ? true : false;
	// combine results into global variable
	if (hasDOM && hasXMLHTTP && isWin && isNotWin98 && (! isIE50) ) ajaxEnabled = true;
}
checkAjax();

// Function to put collection in array
function collectionToArray() {
	// get collection list
	var collection_list = getCookie("TP_USER_COLLECTION");
	// check that this list exists
	if(collection_list!=null) {
		collectionArray = collection_list.split(",");
	}
	// if doesn't exists, set to empty
	else {
		collectionArray = '';
	}
}
// Run collectionToArray
collectionToArray();

// Check that item isn't in collection array
function checkCollection (item,type) {
	var exists = false;
	for (var i=0; i<collectionArray.length; i++) {
		itemArray = collectionArray[i].split("|");
		if(itemArray[0]==item && itemArray[1]==type) {
			exists = true;	
		}	
	}
	return exists;
}

// Function to determine user type
function getSettings() {
	// bookmark total
	bookmarkTotal = getCookie("TP_USER_BOOKMARK_COUNT");
	if(bookmarkTotal==null) bookmarkTotal = 0;
	// collection total
	if(getCookie('TP_USER_COLLECTION_SIZE')==null) collectionTotal = 0;
	else collectionTotal = getCookie('TP_USER_COLLECTION_SIZE');
	// user type
	userType = getCookie("TP_USER_TYPE");
	// user name
	userName = getCookie("TP_USER_NAME");
	/*wrappedUserName = '';
	breakEvery = 5;
	if (userName) {
		for(var i=0; i<= Math.floor(userName.length / breakEvery); i++) {
			wrappedUserName += userName.substring(i*breakEvery, (i+1)*breakEvery);
			wrappedUserName += '<span class="tpBreaker"> </span>';
		}
	}
	userName = wrappedUserName;*/
	/*wrapd = '';
	wrapOn = 10;
	if (userName) {
		userName = userName.replace(/\./g, " ");
		words = userName.split(" ");
		for(var i=0; i<words.length; i++) {
			word = words[i];
			if (word) {
				wrapd += ' ';
				wrapd += word.substring(0,wrapOn);
				while (word.length > wrapOn) {
				  wrapd += '<span class="tpBreaker"> </span>';
				  word = word.substring(wrapOn,word.length);
				  wrapd += word.substring(0,wrapOn);
				}
			}
		}
		wrapd = wrapd.substring(1, wrapd.length);
	}
	userName = wrapd;*/
}
// Run settings
getSettings();

/*--------------------------------------------------------------------------*/
/* Commented out as it interferes with other Javascript Libraries

var Class = {
  create: function() {
    return function() { 
      this.initialize.apply(this, arguments);
    }
  }
}

var Abstract = new Object();

Object.prototype.extend = function(object) {
  for (property in object) {
    this[property] = object[property];
  }
  return this;
}
*/

function addToCollection(item_id,item_category,item_type,lang) {
	if(cookiesEnabled) document.write( tpBuildAddButton( item_id, item_category, item_type, !checkCollection(item_id,item_type), lang ) );
}

function tpBuildAddButton(item_id, item_category, item_type, enabled, lang) {
	if(lang=='en') { addText = 'Add to Travel Planner'; addedText = 'Added to Travel Planner'; width=138; }
	if(lang=='ja') { addText = 'トラベル・プランナーへ追加'; addedText = 'トラベル・プランナーへ追加済み'; width=166; }
	if(lang=='ko') { addText = '트래블 플래너에 추가'; addedText = '트래블 플래너에 추가되었습니다'; width=166; }
	if(lang=='zhs') { addText = '添加到旅行计划'; addedText = '已添加到旅行计划'; width=166; }	
	if (enabled && ajaxEnabled) return '<a href="javascript:void(0)" id="' + item_id + '" onClick="ajaxAddToCollection(' + item_id + ',' + item_category + ',' + item_type + ',\'' + lang + '\'); return false;" title="' + addText + '"><img src="images/travelplanner/listing_addoperator_' + lang + '.gif" width="' + width + '" height="18" class="searchResultTPadd" alt="' + addText + '" title="' + addText + '" border="0"></a>';			
	else if ( enabled && !ajaxEnabled) return '<a class="tpAddButton" href="/travel/app_templates/travel_planner/add_item.cfm?item_id=' + item_id + '&signup_lang=' + lang + '&item_type=' + item_type +'" id="' + item_id + '" title="' + addText + '"><img src="images/travelplanner/listing_addoperator_' + lang + '.gif" width="' + width + '" height="18" class="searchResultTPadd" alt="' + addText + '" title="' + addText + '" border="0"></a>';
	else return '<img src="images/travelplanner/listing_addedoperator_' + lang + '.gif" width="' + width + '" height="18" class="searchResultTPadd" alt="' + addedText + '" title="' + addedText + '" border="0">';
}

function ajaxAddToCollection (item_id, item_category, item_type, lang) {
	if (! ajaxEnabled) {
		window.alert('AJAX 004: You shouldnt be seeing this');
		document.location = '/travel/app_templates/travel_planner/add_item.cfm?item_id=' + item_id + '&item_type=' + item_type + '&signup_lang=' + lang ;
	} else {
		var btnElm = document.getElementById(item_id);
		btnElm.btnSize = 'small'; // or 'large'
		btnElm.btnType = item_type;
		newsrc =  '/travel/images/travelplanner/';
		newsrc += (btnElm.btnSize == 'small') ? 'listing' : 'widget';
		newsrc += '_addingoperator_' + lang + '.gif';
		btnElm.firstChild.src = newsrc;
		//btnElm.onclick=function(){window.alert('Waiting for server...')};
		//btnElm.t = setTimeout(ajaxProcessAddResponse, 1500, btnElm);
		btnElm.updater = function(){
			// only if req shows "complete"
			if (btnElm.req.readyState == 4) {
				// only if "OK"
				if(btnElm.req){
					// turn the JSON response into a result object
					eval('btnElm.result = ' + btnElm.req.responseText);
					if (!btnElm.result.status) {
						window.alert("AJAX 001: Error connecting to server");
					} else {
						//window.alert('Starting ajaxProcessAddResponse()');

						var s=s_gi(s_account); 
						s.linkTrackVars='eVar7,products,events'; 
						s.linkTrackEvents='event9'; 
						s.products=';'+item_id; 
						switch (item_category) {
						case 1:
							s.eVar7='Transportation'; 
						break;
						case 2:
							s.eVar7='Accommodation'; 
						break;
						case 3:
							s.eVar7='Other Activities'; 
						break;
						case 4:
							s.eVar7='Travel & Tours'; 
						break;
						case 5:
							s.eVar7='Tours and Sightseeing'; 
						break;
						default: 
							switch (item_type) {
								case 2:
									s.eVar7='Town'; 							
								break;
								case 4:
									s.eVar7='Scenic Highlight'; 							
								break;
								default: 
									s.eVar7='Other'; 
								
							}
						}
						s.events='event9'; 
						s.tl(this,'o',s.eVar7+' Add to Planner');

						ajaxProcessAddResponse(btnElm, lang);
					}
				} else {
					window.alert("AJAX 005: There was a problem retrieving the XML data:\n" + req.statusText);
				}
			}
		}

		//window.alert('Sending the AJAX request');
		url = '/travel/app_templates/travel_planner/add_item_ajax.cfm';
		postString = 'item_id=' + item_id + '&item_type=' + item_type + '&signup_lang=' + lang;
		url += '?' + postString;
		// branch for native XMLHttpRequest object
		if (window.XMLHttpRequest) {
			btnElm.req = getXMLHTTP();
			btnElm.req.onreadystatechange = btnElm.updater.bind(btnElm);
			btnElm.req.open("GET", url, true);
			btnElm.req.send(null);
		// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			btnElm.req = getXMLHTTP();
			if (btnElm.req) {
				btnElm.req.onreadystatechange = btnElm.updater.bind(btnElm);
				btnElm.req.open("GET", url, true);
				btnElm.req.send();
			}
		}
	}
}

function ajaxAddBookmark (page_title, lang) {
	if (! ajaxEnabled) {
		window.alert('AJAX 003: deprecated function');
		document.location = '/travel/app_templates/travel_planner/add_bookmark.cfm?page_title=' + page_title + '&signup_lang=' + lang;
	} else {
		//document.location = '/travel/app_templates/travel_planner/add_bookmark_ajax.cfm'; //?page_title=' + page_title;
		btnElm = document.getElementById('bookmarkBtn');
		btnElm.btnSize = 'large'; // bookmark buttons only come in large size
		btnElm.btnType = 'bookmark';
		newsrc =  '/travel/images/travelplanner/widget_addingbookmark_' + lang + '.gif';
		btnElm.firstChild.src = newsrc;
		//btnElm.onclick=function(){window.alert('Waiting for server...')};
		
		btnElm.updater = function(){
			// only if req shows "complete"
			if (btnElm.req.readyState == 4) {
				// only if "OK"
				if (btnElm.req.status == 200) {
					// turn the JSON response into a result opbect
					eval('btnElm.result = ' + btnElm.req.responseText);
					if (!btnElm.result.status) {
						window.alert("AJAX 002: Error connecting to server");
					} else {
						//window.alert('Starting ajaxProcessAddResponse()');
						ajaxProcessAddResponse(btnElm, lang);
					}
				} else {
					window.alert("There was a problem retrieving the XML data:\n" + req.statusText);
				}
			}
		}

		//window.alert('Sending the AJAX request');
		url = '/travel/app_templates/travel_planner/add_bookmark_ajax.cfm';
		postString = 'page_title=' + page_title + '&ref=' + escape(document.location.href) + '&page_hash=' + tp_page_hash(document.location.href) + '&signup_lang=' + lang;
		
		url += '?' + postString;
		// branch for native XMLHttpRequest object
		if (window.XMLHttpRequest) {
			btnElm.req = getXMLHTTP();
			btnElm.req.onreadystatechange = btnElm.updater.bind(btnElm);
			btnElm.req.open("GET", url, true);
			btnElm.req.send(null);
		// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			btnElm.req = getXMLHTTP();
			if (btnElm.req) {
				btnElm.req.onreadystatechange = btnElm.updater.bind(btnElm);
				btnElm.req.open("GET", url, true);			
				btnElm.req.send();
			}
		}
	}
}

function ajaxProcessAddResponse(btnElm, lang) {
	//window.alert('Received the AJAX response');
	// update button
	newsrc =  '/travel/images/travelplanner/';
	newsrc += (btnElm.btnSize == 'small') ? 'listing' : 'widget';
	newsrc += '_added';
	newsrc += (btnElm.btnType == 'bookmark') ? 'bookmark_' + lang + '.gif' : 'operator_' + lang + '.gif';
	btnElm.firstChild.src=newsrc;
	if(lang=='en') { addedText = 'This has already been added to your Travel Planner.'; }
	if(lang=='ja') { addedText = 'このコレクションは、あなたのトラベル・プランナーにすでに登録されています。'; }
	if(lang=='ko') { addedText = '이미 트래블 플래너에 추가된 내용입니다.'; }
	if(lang=='zhs') { addedText = '已添加到旅行计划'; }	
	btnElm.onclick=function(){window.alert(addedText)};
	// create flying disc
	var discElm = document.createElement('img');
	discElm.btn = btnElm;
	discElm.src = '/travel/images/travelplanner/widget_add_disc.gif';
	newsize = (btnElm.btnSize == 'small') ? 16 : 18;
	discElm.width = newsize;
	discElm.height = newsize;
	discElm.style.position = 'absolute';
	//new stuff
	discElm.style.left = findPosX(btnElm) + ((btnElm.btnSize == 'small') ? 2 : 8 )+'px';
	discElm.style.top = findPosY(btnElm) + ((btnElm.btnSize == 'small') ? -19 : -18 )+'px';
	// attatch disc to document
	widg = document.getElementById('tpWidget');
	widg.parentNode.insertBefore(discElm, widg);
	buttonAnim(discElm);
}

Function.prototype.bind = function(object) {
  var method = this;
  if (method.apply) {
	  return function() {
		method.apply(object, arguments);
	  }
  } else { return false }
}

function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) curtop += obj.y;
	return curtop;
}

function buttonAnim(elm) {
	var targetElm = '';
	if (elm.btn.btnType == 'bookmark') {
		targetElm = document.getElementById("tpBookmarkedNumBg");
	} else {
		targetElm = document.getElementById("tpCollectedNumBg");
	}
	if (! targetElm) targetElm = document.getElementById("tpCollectedNoneBg"); 
	elm.toLeft = findPosX(targetElm) + 6;
	elm.toTop  = findPosY(targetElm) - 16; // 16
	elm.startLeft = findPosX(elm);
	elm.startTop  = findPosY(elm);
	elm.startSize = elm.width;
	elm.counter = 0;
	elm.stepper = function(){
		elm.counter += .05;
		if (elm.counter > 1.0) elm.counter = 1.0;
		frac1 = 1 - (Math.cos(elm.counter * Math.PI) +1) /2; // bumpered from 0 => 1
		frac2 = 2 * Math.sin(elm.counter * Math.PI); // unbumpered from 0 => 2 => 0
		//window.alert('step:'+elm.counter+', frac1:'+frac1);
		leftd = (elm.toLeft - elm.startLeft) * frac1;
		topd = (elm.toTop - elm.startTop) * frac1;
		elm.style.position = 'absolute';
		elm.style.zIndex = 10;
		elm.style.left = elm.startLeft + leftd - (elm.startSize * frac2 /2) + 'px';
		elm.style.top  = elm.startTop  + topd  - (elm.startSize * frac2 *2) + 'px';
		elm.style.width  = elm.startSize * (1+frac2) + 'px';
		elm.style.height = elm.startSize * (1+frac2) + 'px';
		if (elm.counter < 1.0) {
			elm.timer = setTimeout(elm.stepper.bind(elm), 50);
		}
		else {
			//window.alert('done stepping');
			elm.counter = 0;
			elm.timer = setTimeout(elm.stopper.bind(elm), 50)
		}
	}
	elm.stopper = function(){
		elm.counter += .2;
		if (elm.counter > 1.0) elm.counter = 1.0;
		zoom = 5 * elm.counter;//Math.sin(elm.counter * Math.PI );//elm.counter * 5;
		opac = (1 - elm.counter) * 100;
		opac = (opac == 100) ? 99.999 : opac;
		elm.style.filter = "alpha(opacity:"+opac+")";
		elm.style.opacity = opac/100 /*//*/;
		elm.style.width  = elm.startSize * (1+zoom) + 'px';
		elm.style.height = elm.startSize * (1+zoom) + 'px';		
		elm.style.left = elm.toLeft - (elm.startSize * zoom /2) + 'px';
		elm.style.top  = elm.toTop  - (elm.startSize * zoom /1.5) + 'px';
		if (elm.counter < 1.0) {
			elm.timer = setTimeout(elm.stopper.bind(elm), 50);
		}
		else {
			//window.alert('done stopping');
			elm.counter = 0;
			elm.style.display = 'none';
			collectionToArray();
			getSettings();
			tpRenderPalette();
		}
	}	
	elm.stepper();
}


function addLoadEvent(func) {
	$(func());
}

function addResizeEvent(func) {
  var oldonresize = window.onresize;
  if (typeof window.onresize != 'function') {
    window.onresize = func;
  } else {
    window.onresize = function() {
      oldonresize();
      func();
    }
  }
}

function tpUpdatePosition(){
	ww = document.body.clientWidth;
	tpDiv = document.getElementById('tpWidget');
	jafeatureDiv = document.getElementById('jafeature');
	aufeatureDiv = document.getElementById('aufeature');
	compDiv = document.getElementById('tpCompetitionWidget');
	footerSizeDiv = document.getElementById('footerSizeContainer');

	if (tpDiv) {
		if (ww < 948) {
			if (tpDiv.className != 'widget-narrow') tpDiv.className = 'widget-narrow';
			if (compDiv != null) {
				compDiv.style.display = 'none';
			} 
			
			if (aufeatureDiv != null) {
				aufeatureDiv.style.display = 'none';
				$("#tpWidget").css({margin:"0 0 0 0"})
			} 
			
			// added by Glenn to adjust the footer size
			if (footerSizeDiv != null) {
				footerSizeDiv.className = 'footerSlim';
			}
			
			
			
		} else {
			if (tpDiv.className != 'widget-wide') tpDiv.className = 'widget-wide';
			if (compDiv != null) {
				compDiv.style.display = 'block';
			} 
			
			if (aufeatureDiv != null) {
				aufeatureDiv.style.display = 'block';
				$("#tpWidget").css({margin:"-15px 0 0 0"})
			} 

			if (aufeatureDiv != null) {
				aufeatureDiv.style.display = 'block';
			} 
			
			// added by Glenn to adjust the footer size
			if (footerSizeDiv != null) {
				footerSizeDiv.className = 'footerWide';
			}
						
		}
	}
}

//DOM-ready watcher
//use to safely trigger events earlier than the window.onLoad event
//see: http://www.codingforums.com/showthread.php?t=58882
function domFunction(f, a)
{
	var n = 0;
	var t = setInterval(function(){
		var c = true;
		n++;
		if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null)){
			c = false;
			if(typeof a == 'object'){
				for(var i in a){
					if( (a[i] == 'id' && document.getElementById(i) == null) || (a[i] == 'tag' && document.getElementsByTagName(i).length < 1) ) { 
						c = true; 
						break; 
					}
				}
			}
			if(!c) { 
				f(); 
				clearInterval(t);
			}
		}
		if(n >= 60){ 
			clearInterval(t);
		}
	}, 200);
};

if ((navigator.userAgent.toLowerCase().indexOf("win98") == -1) && (navigator.userAgent.toLowerCase().indexOf("windows 98") == -1) ) {
	// not Win98
	if (navigator.userAgent.toLowerCase().indexOf("msie 5.0") == -1) {
		// not IE 5.0
		var quickloader = new domFunction(tpUpdatePosition, {'tpWidget':'id'});
		addLoadEvent(tpUpdatePosition);
		addResizeEvent(tpUpdatePosition);
	}
}


/*
* Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5.
* Modified by CT 22-7-2005
*/

var hexcase=0;  
var b64pad="";
var chrsz=8;
function b64_md5(s){return m5b(core_md5(m5s2b(s),s.length*chrsz));}
function core_md5(x, len)
{
x[len >> 5] |= 0x80 << ((len)%32);
x[(((len+64) >>> 9) << 4)+14]=len;
var a=1732584193;
var b=-271733879;
var c=-1732584194;
var d=271733878;
for(var i=0;i<x.length;i+=16)
{
var olda=a;
var oldb=b;
var oldc=c;
var oldd=d;
a=m5f(a,b,c,d,x[i+0],7,-680876936);
d=m5f(d,a,b,c,x[i+1],12,-389564586);
c=m5f(c,d,a,b,x[i+2],17,606105819);
b=m5f(b,c,d,a,x[i+3],22,-1044525330);
a=m5f(a,b,c,d,x[i+4],7,-176418897);
d=m5f(d,a,b,c,x[i+5],12,1200080426);
c=m5f(c,d,a,b,x[i+6],17,-1473231341);
b=m5f(b,c,d,a,x[i+7],22,-45705983);
a=m5f(a,b,c,d,x[i+8],7,1770035416);
d=m5f(d,a,b,c,x[i+9],12,-1958414417);
c=m5f(c,d,a,b,x[i+10],17,-42063);
b=m5f(b,c,d,a,x[i+11],22,-1990404162);
a=m5f(a,b,c,d,x[i+12],7,1804603682);
d=m5f(d,a,b,c,x[i+13],12,-40341101);
c=m5f(c,d,a,b,x[i+14],17,-1502002290);
b=m5f(b,c,d,a,x[i+15],22,1236535329);
a=m5g(a,b,c,d,x[i+1],5,-165796510);
d=m5g(d,a,b,c,x[i+6],9,-1069501632);
c=m5g(c,d,a,b,x[i+11],14,643717713);
b=m5g(b,c,d,a,x[i+0],20,-373897302);
a=m5g(a,b,c,d,x[i+5],5,-701558691);
d=m5g(d,a,b,c,x[i+10],9,38016083);
c=m5g(c,d,a,b,x[i+15],14,-660478335);
b=m5g(b,c,d,a,x[i+4],20,-405537848);
a=m5g(a,b,c,d,x[i+9],5,568446438);
d=m5g(d,a,b,c,x[i+14],9,-1019803690);
c=m5g(c,d,a,b,x[i+3],14,-187363961);
b=m5g(b,c,d,a,x[i+8],20,1163531501);
a=m5g(a,b,c,d,x[i+13],5,-1444681467);
d=m5g(d,a,b,c,x[i+2],9,-51403784);
c=m5g(c,d,a,b,x[i+7],14,1735328473);
b=m5g(b,c,d,a,x[i+12],20,-1926607734);
a=m5h(a,b,c,d,x[i+5],4,-378558);
d=m5h(d,a,b,c,x[i+8],11,-2022574463);
c=m5h(c,d,a,b,x[i+11],16,1839030562);
b=m5h(b,c,d,a,x[i+14],23,-35309556);
a=m5h(a,b,c,d,x[i+1],4,-1530992060);
d=m5h(d,a,b,c,x[i+4],11,1272893353);
c=m5h(c,d,a,b,x[i+7],16,-155497632);
b=m5h(b,c,d,a,x[i+10],23,-1094730640);
a=m5h(a,b,c,d,x[i+13],4,681279174);
d=m5h(d,a,b,c,x[i+0],11,-358537222);
c=m5h(c,d,a,b,x[i+3],16,-722521979);
b=m5h(b,c,d,a,x[i+6],23,76029189);
a=m5h(a,b,c,d,x[i+9],4,-640364487);
d=m5h(d,a,b,c,x[i+12],11,-421815835);
c=m5h(c,d,a,b,x[i+15],16,530742520);
b=m5h(b,c,d,a,x[i+2],23,-995338651);
a=m5i(a,b,c,d,x[i+0],6,-198630844);
d=m5i(d,a,b,c,x[i+7],10,1126891415);
c=m5i(c,d,a,b,x[i+14],15,-1416354905);
b=m5i(b,c,d,a,x[i+5],21,-57434055);
a=m5i(a,b,c,d,x[i+12],6,1700485571);
d=m5i(d,a,b,c,x[i+3],10,-1894986606);
c=m5i(c,d,a,b,x[i+10],15,-1051523);
b=m5i(b,c,d,a,x[i+1],21,-2054922799);
a=m5i(a,b,c,d,x[i+8],6,1873313359);
d=m5i(d,a,b,c,x[i+15],10,-30611744);
c=m5i(c,d,a,b,x[i+6],15,-1560198380);
b=m5i(b,c,d,a,x[i+13],21,1309151649);
a=m5i(a,b,c,d,x[i+4],6,-145523070);
d=m5i(d,a,b,c,x[i+11],10,-1120210379);
c=m5i(c,d,a,b,x[i+2],15,718787259);
b=m5i(b,c,d,a,x[i+9],21,-343485551);
a=m5sa(a,olda);
b=m5sa(b,oldb);
c=m5sa(c,oldc);
d=m5sa(d,oldd);
}
return Array(a,b,c,d);
}

function m5c(q,a,b,x,s,t)
{
return m5sa(m5br(m5sa(m5sa(a,q),m5sa(x,t)),s),b);
}
function m5f(a,b,c,d,x,s,t)
{
return m5c((b & c)|((~b) & d),a,b,x,s,t);
}
function m5g(a,b,c,d,x,s,t)
{
return m5c((b & d)|(c & (~d)),a,b,x,s,t);
}
function m5h(a,b,c,d,x,s,t)
{
return m5c(b^c^d,a,b,x,s,t);
}
function m5i(a,b,c,d,x,s,t)
{
return m5c(c^(b|(~d)),a,b,x,s,t);
}

function m5sa(x,y)
{
var lsw=(x & 0xFFFF)+(y & 0xFFFF);
var msw=(x >> 16)+(y >> 16)+(lsw >> 16);
return (msw << 16)|(lsw & 0xFFFF);
}

function m5br(num, cnt){return(num << cnt) | (num >>> (32 - cnt));}

function m5s2b(str)
{
var bin=Array();
var mask=(1 << chrsz) - 1;
for(var i=0; i<str.length*chrsz;i+=chrsz)
bin[i>>5] |= (str.charCodeAt(i/chrsz) & mask) << (i%32);
return bin;
}

function m5b(b)
{
var tab="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
var str="";
for(var i=0;i<b.length*4;i+=3)
{
var t=(((b[i >> 2] >> 8*(i %4)) & 0xFF) << 16)|(((b[i+1 >> 2] >> 8*((i+1)%4)) & 0xFF) << 8 )|((b[i+2 >> 2] >> 8*((i+2)%4)) & 0xFF);
for(var j=0; j < 4; j++)
{
if(i * 8 + j * 6 > b.length * 32) str += b64pad;
else str += tab.charAt((t >> 6*(3-j)) & 0x3F);
}
}
return str;
}

function tp_page_hash(s){
	h = b64_md5(s);
	return  h.substring(0,16); // return first 16 chars
}
function tp_is_bookmarked(h) {
	h = tp_page_hash(h); // turn into hash
	if (cookiesEnabled) {
		c = getCookie('TP_USER_BOOKMARKS');
		if (c) {
			return (c.indexOf(h) != -1);
		}
	}
	return false;
}