//The PopUp (this gets around  pop-up blockers)
var win=null;function NewWindow(mypage,myname,w,h,scroll){LeftPosition=(screen.width)?(screen.width-w)/2:0;TopPosition=(screen.height)?(screen.height-h)/2:0;settings='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+','
win=window.open(mypage,myname,settings)}

var occManualCarousel = 0;
var occTimeout = 1;
var occAjaxTimeout = 1;
var frontPageNum = 1;
var frontPageRotating = 1;

function doOCCReady() {
	
	$j = jQuery.noConflict();

	
	jQuery( "#flickr-photos a").fancybox();
	jQuery( "a.inline" ).fancybox( {
		'frameWidth': 600,
		'frameHeight': 500,
		'hideOnContentClick': false
	});
		
	// hack to get IE 7 to handle z-index properly

	
	// hack to get Safari to layout the page before continuing
	var ignoreMe = document.body.offsetWidth;
	
	var c = $j("#section ul#section-menu li a").size() - 1;
	$j("#section ul#section-menu li a").each( function( d ) { if ( d == c ) $j(this).css( "border", "none" ); } );
	
	
	$j("ul#menu li ul").hide();
	$j("ul#ment li.current_page_item ul").hide();
	
	var selectedItem = $j("ul#menu > li");
	
	/*if ( selectedItem ) {
		selectedItem.bind( "mouseenter", function() { 
			$j(this).find("ul").show().dropShadow( { left: 2, top: 2, color: '#000' } ).bind( "mouseleave", function() { 
				$j(this).fadeOut( 250 ).removeShadow(); 
				selectedItem.bind( "mouseleave", function() { } );
			}) 
		});
		
		selectedItem.bind( "mouseleave", function() { $j(this).find("ul").fadeOut( 250 ).removeShadow(); } );
	}*/
	
	if ( selectedItem) {
		selectedItem.bind( "mouseenter", function() { 
			$j(this).find("ul").show().bind( "mouseleave", function() { 
				$j(this).fadeOut( 250 ); 
				selectedItem.bind( "mouseleave", function() { } );
			}) 
		});
		
		selectedItem.bind( "mouseleave", function() { $j(this).find("ul").fadeOut( 250 ); } );
	}
	
	var item = $j("ul#menu li.current_page_parent");	
	if ( item.size() == 0 ) {
		item = $j("ul#menu li.current_page_item");
	}
	
	if ( item ) {
		var h = item.html();
		h = h + '<div id="left-curve"></div><div id="right-curve"></div>';
		item.html( h );
	}	
	
 	$j("#menu").show();	
 
	// preload the hover images
	$j.preload( [ 'menu-hovers' ], {
 		base: stylesheet_dir + '/images/',
 		ext: '.png'
 	});
 	
	$j.preload( occCarouselImages, {
 		base: stylesheet_dir + '/images/front-carousel/',
 		ext: '.jpg'
 	}); 

	jQuery( '#carousel' ).css( "background", "url(" + stylesheet_dir + "/images/front-carousel/" + occCarouselImages[ occCarouselNum ] + ".jpg) no-repeat" );
 	
 	doFrontPageAJAX( 'news', document.getElementById('news') );
 	occTimeout = setTimeout( doOCCCarouselRotation, 11000 );
 	occAjaxTimeout = setTimeout( doFrontPageTimer, 17000 );
 	
 	jQuery("li#carousel-count-" + occCarouselNum).addClass("carousel-active");
 	jQuery("#member-carousel").jcarousel( {  
		auto: 5,
		wrap: 'last' 
	} );
 	
 	jQuery( '#carousel' ).attr( 'href', occCarouselLinks[occCarouselNum] );
 	if ( occCarouselNotes[occCarouselNum] ) {
 		// jQuery( '#carousel' ).attr( 'onclick', occCarouselNotes[1] );	
 		jQuery( '#carousel' ).click( function() {  eval( occCarouselNotes[occCarouselNum] ); return false;  } );	
 	}
 	jQuery(this).css( "background", "url(" + stylesheet_dir + "/images/front-carousel/" + occCarouselImages[ occCarouselNum ] + ".jpg) no-repeat" );
	
}

function doOCCCarouselRotation() {
	
	//occCarouselNum = Math.floor( Math.random() * occTotalCarouselImages );
	
	if ( occCarouselNum >= occTotalCarouselImages ) {
			occCarouselNum = 0;	
		}	

	occCarouselNum = (occCarouselNum + 1);	
	jQuery("#mid-section a#carousel").animate( { opacity: '0.0' }, 750, function() {
		//alert(occCarouselNum + "  " + stylesheet_dir + "/images/front-carousel/" + occCarouselImages[ occCarouselNum ] + ".jpg");
		jQuery(this).css( "background", "url(" + stylesheet_dir + "/images/front-carousel/" + occCarouselImages[ occCarouselNum ] + ".jpg) no-repeat" ).animate( { opacity: '1.0' }, 750);
		//alert( occCarouselLinks[ occCarouselNum ] );
		jQuery( '#carousel' ).attr( 'href', occCarouselLinks[ occCarouselNum ] );
	 	//if ( occCarouselNotes[occCarouselNum].length > 0 ) {
	 	////	jQuery( '#carousel' ).click(  function() { alert( 'here' ); /* occCarouselNotes[occCarouselNum]; */ } );	
	 	//	jQuery( '#carousel' ).unbind('click');
	 	//	jQuery( '#carousel' ).click( function() {  eval( occCarouselNotes[occCarouselNum] ); return false;  } );	
	 	//  // jQuery( '#carousel' ).attr( 'onclick', occCarouselNotes[occCarouselNum] );
	 	//} else {
	 	//	jQuery( '#carousel' ).unbind('click');
	 	//}
		
		if ( occManualCarousel == 0 ) {
			occTimeout = setTimeout( doOCCCarouselRotation, 10000 );
		}
		
		jQuery("li.carousel-item").removeClass("carousel-active");
		jQuery("li#carousel-count-" + occCarouselNum ).addClass("carousel-active");
		
		if ( occCarouselNum >= occTotalCarouselImages ) {
			occCarouselNum = 0;	
		}	
				
	} );	
}

function doFrontPageAJAX( pageName, item, cancel ) {
	$j = jQuery.noConflict();
	$j.get( wordpress_url + '/?occ=' + pageName, function( d ) { 
		$j("#section li a").removeClass( "selected" ); 
		$j("#ajax-content").hide().html( d ).fadeIn(); $j( item ).addClass( "selected" );	
	});
	
	if ( cancel == 1 ) {
		frontPageRotating = 0;	
	}
}

function doFrontPageTimer() {
	var page;
	if ( frontPageRotating == 1 ) {
		frontPageNum = frontPageNum + 1;
		if ( frontPageNum == 5 ) {
			frontPageNum = 1;
		}
		
		if ( frontPageNum == 1) {
			page = 'news';
		} else if ( frontPageNum == 2 ) {
			page = 'events'
		} else if ( frontPageNum == 3 ) {
			page = 'press';
		} else if ( frontPageNum == 4 ) {
			page = 'featured';
		}
		
		var docId = document.getElementById( page );
		doFrontPageAJAX( page, docId, 0 );
	}		
}

function doOCCSwitchCarousel( item ) {
	var page;
	
	occManualCarousel = 1;
	clearTimeout( occTimeout );
	
	occCarouselNum = item - 1;
	doOCCCarouselRotation();

}

function doOCCRotate() {
	occManualCarousel = 1;
	clearTimeout( occTimeout );	
	
	doOCCCarouselRotation();
}

jQuery(document).ready( function() { 
	doOCCReady(); 
} );
