$(document).ready(function() {

	// Local Scroll
	function filterPath(string) {
		return string
			.replace(/^\//,'') 
			.replace(/(index|default).[a-zA-Z]{3,4}$/,'') 
			.replace(/\/$/,'');
		}
		$('a[href*=#]').each(function() {
			if ( filterPath(location.pathname) == filterPath(this.pathname)
			&& location.hostname == this.hostname
			&& this.hash.replace(/#/,'') ) {
			var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
			var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
			if ($target) {
				var targetOffset = $target.offset().top;
				$(this).click(function() {
					$('html, body').animate({scrollTop: targetOffset}, 400);
					return false;
				});
			}
		}
	});


	// Add a class for menu items with submenu's
	$('#nav li').has('ul').addClass('hassub');
	$('#nav li').hover(function(){$(this).addClass('over');},function(){$(this).removeClass('over');});
	
	// Change the opactiy of submenu background in compatible browsers
	if(jQuery.support.opacity){
		$('#nav li ul').css({'background':'rgba(255, 255, 255, 0.8)'});
	}
	
	// Open links in a new window if rel is set to external
	$('a[rel="external"]').click( function() { window.open( $(this).attr('href') ); return false; });

	// Hide border on last news item
	$('.grid_4 .news-item:last').addClass('last');
	
	// Add a class to the first breadcrumb item
	if($('#breadcrumbs a').length > 0){$('#breadcrumbs a:first').addClass('first');}
	
	
	// Module demonstration popups
	$('li.page-item-722 a').attr('rel', 'popup');
	$('li.page-item-724 a').attr('rel', 'popup');
	$('li.page-item-726 a').attr('rel', 'popup');

	var winl = (screen.width-950)/2;
	var wint = (screen.height-565)/2;

    $('a[rel="popup"]').click(function(){
        var features = "height=565,width=950,scrollTo,resizable=0,scrollbars=0,location=0,top=" + wint + ",left=" + winl;
        newwindow=window.open(this.href, 'popupwindow', features);
        return false;
    });
    
    // Fix breadcrumbs
    $('#breadcrumbs .grid_12 a').after(' <span>&gt;</span> ');

});
