﻿function alertdialog() {

if ($('#alertdialog-content').length>0) {

di= $("#alertdialog").jqm({modal: true, closeClass: "alertdialog-close", overlay: 80, onHide: adhide});
$('#alertdialog-contentarea').append($('#alertdialog-content').css('display','block'));
	
if (! $.cookie('alerted')) {
	di.jqmShow();
	}	
}
}

function adhide(hash) {
	$.cookie('alerted','true');
	hash.w.hide();
	hash.o.remove();
}


// ** Login Menu **
$(function(){ // (executes when the dom is ready)

	// change last top link
	$("#top-links li:last").addClass("last");
	
	// make logo a link to go back to home page
	$("#loginlink").hover(function(){
		$("#loginmenu").show();
		return false;
	})

	$("#loginmenu").hoverIntent(function(){
		$("#loginmenu").show();
		return false;
	}, function() {
		$("#loginmenu").hide();
		return false;
		
	})	
	
	alertdialog();
});


$(function(){
	//fix top nav in ie
	$("#topnav ul li:last-child").addClass("ielast");
	
	//add accent shadow

	$(".accentbox").each(function(){
		if(!($(this).hasClass("nojq"))) {
				$(this).wrap('<div class="accentboxborder"></div>');
			}
		});
	
}); 

/*
$(function(){
if ($("#pdb-announce p").html().length >10) {
	$("#pdb-announce").slideDown('slow');
	}
});
*/

$(function(){
/*
var loadInIframeModal = function(hash){
	var $trigger = $(hash.t);
	var $modal = $(hash.w);
	var myUrl = $trigger.attr('href');
	dlID= myUrl.substring(myUrl.lastIndexOf('/')+1,myUrl.lastIndexOf('.'))
	var myUrl = "http://login.pervasive.com/download/index/"+dlID+"?lid=mini"
	var $modalContent = $("iframe", $modal);
	$modalContent.html('').attr('src', myUrl);
	$modal.show();
}
// initialise jqModal
$("#dldialog").jqm({modal: true, trigger: "a:regex(href,download/pages/[0-9]+[.]aspx)", closeClass: "dldialog-close", overlay: 80, onShow: loadInIframeModal});

});
*/


$("a:regex(href,download/pages/[0-9]+[.]aspx)").click(function(){
	var myUrl = $(this).attr('href');
	dlID= myUrl.substring(myUrl.lastIndexOf('/')+1,myUrl.lastIndexOf('.'));
	var myUrl = "https://login.pervasive.com/download/index/"+dlID+"?lid=mini";
	window.open(myUrl, "download", "height=480,width=600,location=no,menubar=no,resizeable=no,scrollbars=yes,status=no,toolbar=no", true);
	return false;
});
});
// ** Search box **
// **     (.e.which==13)       **
$(function(){ // (executes when the dom is ready)
	$("#search-box input").keypress(function(e) {
		if (e.which==13) {
			doSearch();
			return false;
		}
	});

	$("#search-box a").click(function(){
		doSearch();
		return false;
	});
	
});

function doSearch() {
	searchURL= "/pages/results.aspx?k="+ document.getElementById("k").value;
	window.location.href= searchURL
}



/**
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

//regex filter
jQuery.expr[':'].regex=function(elem,index,match){var matchParams=match[3].split(','),validLabels=/^(data|css):/,attr={method:matchParams[0].match(validLabels)?matchParams[0].split(':')[0]:'attr',property:matchParams.shift().replace(validLabels,'')},regexFlags='ig',regex=new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''),regexFlags);return regex.test(jQuery(elem)[attr.method](attr.property));}

jQuery.cookie=function(key,value,options){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():'',options.path?'; path='+options.path:'',options.domain?'; domain='+options.domain:'',options.secure?'; secure':''].join(''));}
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;};

