// JavaScript Document
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-391093-16']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();


/**
 * jQuery.timers - Timer abstractions for jQuery
 * Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com)
 * Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
 * Date: 2009/10/16
 *
 * @author Blair Mitchelmore
 * @version 1.2
 *
 **/

jQuery.fn.extend({everyTime:function(interval,label,fn,times){return this.each(function(){jQuery.timer.add(this,interval,label,fn,times)})},oneTime:function(interval,label,fn){return this.each(function(){jQuery.timer.add(this,interval,label,fn,1)})},stopTime:function(label,fn){return this.each(function(){jQuery.timer.remove(this,label,fn)})}});jQuery.extend({timer:{global:[],guid:1,dataKey:"jQuery.timer",regex:/^([0-9]+(?:\.[0-9]*)?)\s*(.*s)?$/,powers:{'ms':1,'cs':10,'ds':100,'s':1000,'das':10000,'hs':100000,'ks':1000000},timeParse:function(value){if(value==undefined||value==null)return null;var result=this.regex.exec(jQuery.trim(value.toString()));if(result[2]){var num=parseFloat(result[1]);var mult=this.powers[result[2]]||1;return num*mult}else{return value}},add:function(element,interval,label,fn,times){var counter=0;if(jQuery.isFunction(label)){if(!times)times=fn;fn=label;label=interval}interval=jQuery.timer.timeParse(interval);if(typeof interval!='number'||isNaN(interval)||interval<0)return;if(typeof times!='number'||isNaN(times)||times<0)times=0;times=times||0;var timers=jQuery.data(element,this.dataKey)||jQuery.data(element,this.dataKey,{});if(!timers[label])timers[label]={};fn.timerID=fn.timerID||this.guid++;var handler=function(){if((++counter>times&&times!==0)||fn.call(element,counter)===false)jQuery.timer.remove(element,label,fn)};handler.timerID=fn.timerID;if(!timers[label][fn.timerID])timers[label][fn.timerID]=window.setInterval(handler,interval);this.global.push(element)},remove:function(element,label,fn){var timers=jQuery.data(element,this.dataKey),ret;if(timers){if(!label){for(label in timers)this.remove(element,label,fn)}else if(timers[label]){if(fn){if(fn.timerID){window.clearInterval(timers[label][fn.timerID]);delete timers[label][fn.timerID]}}else{for(var fn in timers[label]){window.clearInterval(timers[label][fn]);delete timers[label][fn]}}for(ret in timers[label])break;if(!ret){ret=null;delete timers[label]}}for(ret in timers)break;if(!ret)jQuery.removeData(element,this.dataKey)}}}});jQuery(window).bind("unload",function(){jQuery.each(jQuery.timer.global,function(index,item){jQuery.timer.remove(item)})});



$(document).ready(function() {

	$("a.mailto").attr("href","mailto:enquiries@internationalpathfindersolutions.com");
	$("a.mailto").attr("onClick","javascript:_gaq.push([\'_trackPageview\', \'/Mail-to-link/contact-us\']);");
	
	$("#searchLink").click(function(){
		if ($("#searchForm").is(":hidden")){
			$("#searchForm").fadeIn("fast");
		}
		else{
			$("#searchForm").fadeOut("fast");
		}
	});

	$("#subnav").css("height",248);
	// Add 'external' CSS class to all external links
	$("a:external").attr("target","_blank");
	$("a:external").attr("rel","no_follow");
	if (window.location.href.match(/services\.html/gi)) {
	//$("#subnav").css("height",300);
	}
	if (window.location.href.match(/pathfinder-services\.html/gi)) {
	$(".submenu a[title='Pathfinder']").parent().append("<ul><li>Ground Truth Intelligence</li> <li>Liaison</li> <li>Due diligence</li> <li>Advice</li> <li>Briefs</li> <li>Implementation</li> <li>Integrity Protection</li> <li>Corporate Social Responsibility</li> </ul>");
	$("#subnav").css("height",300);
	}
	if (window.location.href.match(/information-services\.html/gi)) {
	$(".submenu a[title='Information']").parent().append("<ul><li>Commercial Business Intelligence</li> <li>Country Profiles</li> <li>Situation &amp; Location Briefs</li> <li>Commodity &amp; Natural Resources Intelligence</li> <li>Confidential Background Vetting</li> <li>News summary</li>  </ul>");
	$("#subnav").css("height",300);
	}
	if (window.location.href.match(/operational-services\.html/gi)) {
	$(".submenu a[title='Operational']").parent().append("<ul><li>Discreet Asset Recovery</li> <li>Intellectual Property Protection</li> <li>Duty of Care Services (Security)</li>  </ul>");
	$("#subnav").css("height",300);
	}
	if (window.location.href.match(/gatekeeper\.html/gi)) {
	$(".submenu a[title='Gatekeeper']").parent().append("<ul><li>Exposure Management</li> <li>Risk Assessment</li> <li>Due Diligence</li>  </ul>");
	$("#subnav").css("height",300);
	}
	$("img[src='/assets/images/ban-2.jpg'], img[src='/assets/images/ban-3.jpg'], img[src='/assets/images/ban-4.jpg']").attr("height","300");
	$("img[src='/assets/images/ban-1.jpg'], img[src='/assets/images/ban-5.jpg'], img[src='/assets/images/ban-6.jpg']").attr("height","248");
	$(".eq1").equalHeights();
	$(".eq2").equalHeights();
	
	jQuery('div.newscats').accordion({ 
    header: 'h3.categories', 
    active: false, 
    alwaysOpen: false, 
    autoheight: false 
});
});




var divs_to_fade = new  Array('#f1', '#f2', '#f3', '#f4');
var imgs_to_fade = new  Array('#fi1', '#fi2', '#fi3', '#fi4');
var divcount = 0;
var i = 0;




function swapFade() {
	//$(divs_to_fade[divcount]).fadeIn(speed, function() { $(imgs_to_fade[divcount]).fadeIn(); });
	$(divs_to_fade[divcount]).fadeIn(speed);
	divcount++;
	if (divcount == 4) divcount = 0;
	//$(imgs_to_fade[divcount]).fadeOut(speed, function() { $(divs_to_fade[divcount]).fadeOut(); });
	$(divs_to_fade[divcount]).fadeOut(speed);
}


	if ($(".homeimg").length) {
		var wait = 7000;
		var speed = 1000;
		//swapFade();
		$(document).everyTime(wait,function() {
			$cur=$(".current").attr("id").replace("f","");
			$nex=parseInt($cur)+1;
			if ($nex==5) { $nex=1; }
			//alert($nex);
			$("#f"+$cur).removeClass("current");
			$("#f"+$nex).addClass("current");
//			$("#f"+$nex).fadeIn(speed, function() { 
//				$("#fi"+$nex).fadeIn(speed, function() {
//					$("#fi"+$nex).fadeOut(speed, function() { $("#f"+$cur).fadeOut(speed); });								 
//				}); });
			
			$("#fi"+$cur).fadeOut(speed, function() { 
				$("#f"+$cur).fadeOut(speed, function() {
					$("#f"+$nex).fadeIn(speed, function() { $("#fi"+$nex).fadeIn(speed); });								 
				}); });
			
			
			
			//swapFade();
		});

		//setInterval("swapFade()",wait);
//		swapFade();
	}
// Creating custom :external selector
$.expr[':'].external = function(obj){
    return !obj.href.match(/^mailto\:/)
            && (obj.hostname != location.hostname);
};





(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css("overflow","auto");
		});
	}
})(jQuery);





