
var j$ = jQuery.noConflict();

j$(document).ready(function(){
	// apply popup styles.
	j$('#gnavi > li > ul').each(function(i){
		var w = 0;
		// calc child elements width.
		j$(this).show().children('li').each(function(e){
			w += j$(this).width();
		});
		j$(this).hide().css({'width': w +'px', 'opacity': '0.8'});
		// right based popup (wedding guide only).
		if (i == 3)
			j$(this).css({'left':'auto', 'right':0});
	});

	// define popup behavior.
	j$('#gnavi > li').hover(
		function(){
			j$(this).children('ul').slideDown(128);
			document["aexternal"].setOver(j$('#gnavi > li').index(this) + 1);
		},
		function(){
			j$(this).children('ul').slideUp(128);
			document["aexternal"].setOver(0);
		}
	);
	j$('#gnavi > li > ul').hover(
		function(){
			var imgSrc = j$(this).siblings('a').children('img.over').attr('src');
			j$(this).siblings('a').children('img.over').attr('src', imgSrc.replace(/^(.+)(\.[a-z]+)$/, '$1_over$2'));
		},
		function(){
			var imgSrc = j$(this).siblings('a').children('img.over').attr('src');
			j$(this).siblings('a').children('img.over').attr('src', imgSrc.replace(/^(.+)_over(\.[a-z]+)$/, '$1$2'));
		}
	);

	// set year in copyrights.
	j$('#navi-footer .copy').html('&copy;'+ (new Date().getFullYear() || '2009') +' Chapelle des Anges.  All Rights Reserved.');

	// set rollover.
	j$('img.over').hover(
		function(){
			this.src = this.src.replace(/^(.+)(\.[a-z]+)$/, '$1_over$2');
		},
		function(){
			this.src = this.src.replace(/^(.+)_over(\.[a-z]+)$/, '$1$2');
		})
		.each(function(){
			this.preloaded = new Image;
			this.preloaded.src = this.src.replace(/^(.+)(\.[a-z]+)$/, '$1_over$2');
		}
	);
		
	// popup
	j$('a.popup').click(
		function(){
			window.open(this.href, 'popup2', 'status=yes,toolbar=no,location=yes,menubar=yes,scrollbars=yes,width=630');
			return false;
		}
	)
	
});

// open popup for flash.
function win(url){
	window.open(url, 'popup2', 'status=yes,toolbar=no,location=yes,menubar=yes,scrollbars=yes,width=630');
}
