/*
 * Global
 */
( function globalNav() {
	$( document ).ready( function() {
		var globalNavAnchors = $( '#globalNav > ul > li > a' )
		var subNavAnchors = $( '#globalNav > ul > li > div.subNav a' );
		var subNavs = $( '#globalNav > ul > li > div.subNav' );
		globalNavAnchors.mouseover( function() {
			$( this ).parent().addClass( 'active' );
		} );
		subNavs.mouseover( function() {
			$( this ).parent().addClass( 'active' );
		} );
		globalNavAnchors.mouseout( function() {
			$( this ).parent().removeClass( 'active' );
		} );
		subNavs.mouseout( function() {
			$( this ).parent().removeClass( 'active' );
		} );
		globalNavAnchors.focus( function() {
			$( this ).parent().addClass( 'active' );
		} );
		globalNavAnchors.blur( function() {
			$( this ).parent().removeClass( 'active' );
		} );
		subNavAnchors.focus( function() {
			$( this ).parent().parent().parent().parent().addClass( 'active' );
		} );
		subNavAnchors.blur( function() {
			$( this ).parent().parent().parent().parent().removeClass( 'active' );
		} );
	} );
}() );



( function popup() {
	$( document ).ready( function () {
		var newwindow = '';
		$( '.popup' ).click( function() {
			var target = $( this ).attr( 'href' );
			if (!newwindow.closed && newwindow.location) {
				newwindow.location.href = target;
			}
			else {
				newwindow=window.open(target,'name','height=558,width=607,status=1,resizable=1');
				if (!newwindow.opener) newwindow.opener = self;
			}
			if (window.focus) {newwindow.focus()}
			return false;
		} );
	} );
}() );

( function ajaxModal() {
	$( document ).ready( function() {
	 	var contentContainer = $( '#modal div.content' );
		var overlay = $( '#modal div.overlay' );
		var getURL = $( 'a.modal_window' ).attr("rel");
		$( 'a.modal_window' ).click( function() {
			if ( document.body.scrollHeight > screen.height - 200 ) {
				overlay.height( document.body.scrollHeight + 20 );
			} else {
				overlay.height( screen.height - 200 );	
			}
			overlay.show();
			$( '#modal .content div' ).load( getURL );
			contentContainer.show();
			return false;
		});

		$( '#modal div.content p.close a' ).click( function() {
			contentContainer.hide();
			overlay.hide();
			return false;
		} );
	} );
}() );
