function strpos (haystack, needle, offset) {
    // Finds position of first occurrence of a string within another  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/strpos    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Onno Marsman    
    // +   bugfixed by: Daniel Esteban
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: strpos('Kevin van Zonneveld', 'e', 5);    // *     returns 1: 14
    var i = (haystack+'').indexOf(needle, (offset || 0));
    return i === -1 ? false : i;
}

$(function(){
	
	$(".removeMe").remove();
	
	/*
	$(".mailingListForm label").hide();
	
	$(".mailingListForm label").each(function(){
		var el = $(this).attr('for');
		var val = $(this).html();
		
		$("#"+el).val(val);
	});
	
	$(".mailingListForm input[name='mailingListName']").focus(function() {
		if($(this).val() == 'Name') {
			$(this).val('');
		}
	});

	$(".mailingListForm input[name='mailingListName']").focusout(function() {
		if($(this).val() == '') {
			$(this).val('Name');
		}
	});

	$(".mailingListForm input[name='mailingListEmail']").focus(function() {
		if($(this).val() == 'Email') {
			$(this).val('');
		}
	});

	$(".mailingListForm input[name='mailingListEmail']").focusout(function() {
		if($(this).val() == '') {
			$(this).val('Email');
		}
	});
	*/
	
	var dl = document.location+"";
	pts = dl.split("/");
	
	
	if(pts[3] == '') {
		$("#mainNav li a:first").parent().addClass("active").addClass("activeTemp");
		$("#mainNav").removeClass('menu-fix');
	} else {
		$("#mainNav li a").each(function(){
			var curr = $(this).attr('href');

			if(strpos(curr,pts[3])) {

				$(this).parent().addClass("active");
				$(this).parent().addClass("activeTemp");
				
				$("#mainNav").removeClass('menu-fix');
				
				return false;
			}
		});
		
		if(pts[4] != '') {
			$("#mainFooter ul li a").each(function(){
				var curr = $(this).attr('href');
				if(strpos(curr,pts[4])) {
				
					$(this).parent().addClass("active");
					
					return false;
				}
			});
		}
	}
	
	mf = false;
	
	if($("#mainNav").hasClass('menu-fix')) {
		mf = true;
	}
	
	
	$("#mainNav > li > a").hover(
		function(){
			$(this).parent().addClass("active");
			$("ul",$(this).parent()).show();
			
			if(mf) {
				$("#mainNav").removeClass('menu-fix');
			}
			
		},
		function(){
			$(this).parent().removeClass("active");
			$(".activeTemp").addClass("active");
			
			clearTimeout(ts);
			
			var ts = setTimeout(function(){
				$("#mainNav li ul").slideUp();
			},7000);
			if(mf) {
				$("#mainNav").addClass('menu-fix');
			}
		}
	);
	
	$("#mainNav li ul").bind('mouseover',function(){
		$(this).parent().addClass('active');
	});

	$("#mainNav li ul").bind('mouseout',function(){
		if(pts[3] != 'services') {
			$(this).parent().removeClass('active');
		}
	});

	$("#mainMain h1 span").hide();
	
	$("#mainMain h1 span:first").show();
	
	setInterval(function(){
		if($("#mainMain h1 span:first").is(":hidden")) {
			$("#mainMain h1 span:last").fadeOut(2000);
			
			setTimeout(function(){$("#mainMain h1 span:first").fadeIn(2000);},2000);
			
			
		} else {
			$("#mainMain h1 span:first").fadeOut(2000);
			
			setTimeout(function(){$("#mainMain h1 span:last").fadeIn(2000);},2000)
			
		}
	},7000);
	
	$("p.role").hide();
	
	$("h3.role a").click(function(){
		
		
		
		var el = $("p"+$(this).attr('href'));
		
		if($(el).is(':visible')) {
			$(el).slideUp();
		} else {
			$("p.role").slideUp();
			$(el).slideDown();
		}
		
		return false;
	});

	$('#mainRight #container').jScrollPane({
	//$('#container').jScrollPane({
		scrollbarWidth:10,
		scrollbarMargin:10,
		dragMinHeight:8,
		dragMaxHeight:8
	});

	$("#mainNav li:first").addClass('first');

});
