function filterPath(string) {
    return string
            .replace(/^\//,'')
            .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
            .replace(/\/$/,'');
}

$(document).ready(function(){
	$("ul.links li:even").addClass("odd");
	$("ul.links li:even").corner("5px");
	$("#banner .button").ifixpng();
	
	$("textarea.expanding").autoResize();

	//social link tooltips
	// $("#social a").each(function(){
	// 	$(this).qtip({
	// 		content: $(this).text(),
	// 		show: "mouseover",
	// 		hide: "mouseout",
	// 		position: {
	// 			corner: {
	// 				target: "topRight",
	// 				tooltip: "bottomLeft"
	// 			}
	// 		},
	// 		style: {
	// 			"font-size": "12px",
	// 			background:"#2d2d2d",
	// 			border: {
	// 				color: "#2d2d2d",
	// 				radius: 4
	// 			},
	// 			color: "#fff",
	// 			tip: "bottomLeft",
	// 			name: "dark"
	// 		}
	// 	});
	// });
	

	var locationPath = filterPath(location.pathname);

	var scrollElement = 'html, body';
	$('html, body').each(function () {
	    var initScrollTop = $(this).attr('scrollTop');
	    $(this).attr('scrollTop', initScrollTop + 1);
	    if ($(this).attr('scrollTop') == initScrollTop + 1) {
	        scrollElement = this.nodeName.toLowerCase();
	        $(this).attr('scrollTop', initScrollTop);
	        return false;
	    }    
	});

	$('a[href*=#]').each(function() {
		
	    var thisPath = filterPath(this.pathname) || locationPath;
	    if(locationPath == thisPath && (location.hostname == this.hostname || !this.hostname) && this.hash.replace(/#/, '')){
            if ($(this.hash).length) {
                $(this).click(function(event) {
					$("#form").fadeIn(); //addition to fade in the registration form
                    var targetOffset = $(this.hash).offset().top;
                    var target = this.hash;
                    event.preventDefault();
                    $(scrollElement).animate(
                        {scrollTop: targetOffset},
                        500,
                        function() {
                            location.hash = target;
                    });
                });
            }
	    }
	});
	
	$("a.rac").each(function() {
		var href = $(this).attr("href");
		href += "?iframe=true";
		$(this).attr("href",href);
	}).prettyPhoto({
			default_width: 270,
			default_height: 410,
			iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
			markup: '<div class="pp_pic_holder">'+
						'<div class="pp_top">'+
							'<div class="pp_left"></div>'+
							'<div class="pp_middle"></div>'+
							'<div class="pp_right"></div>'+
						'</div>'+
						'<div class="pp_content_container">'+
							'<div class="pp_left">'+
							'<div class="pp_right">'+
								'<div class="pp_content">'+
									'<div class="pp_loaderIcon"></div>'+
									'<div class="pp_fade">'+
										'<div id="pp_full_res"></div>'+
										'<div class="pp_details clearfix">'+
											'<a class="pp_close" href="#">Close</a>'+
										'</div>'+
									'</div>'+
								'</div>'+
							'</div>'+
							'</div>'+
						'</div>'+
						'<div class="pp_bottom">'+
							'<div class="pp_left"></div>'+
							'<div class="pp_middle"></div>'+
							'<div class="pp_right"></div>'+
						'</div>'+
					'</div>'+
					'<div class="pp_overlay"></div>'+
					'<div class="ppt"></div>'
	});
	$("a.external").click(function() {
		window.open(this.href,'_blank');
		return false;
	});
	
	//temporary hack to track clickable links for Ashley Riddle until we get this set up in the data card
	
	$("a[href*='EMEA_10Q2_ISM_Compliance_LPs']").each(function() {
		$(this).click(function(){
			var url = $(this).attr("href");
			var id = url.split("EMEA_10Q2_ISM_Compliance_LPs=");
			
			$.ajax({
				url: '/common/inc/datacard_hack.php?id='+id[1],
				success: function(data) {
					window.location.href = url;
				}
			});
			return false;
		});
	});

});
