// Initialize jQuery

$(document).ready(function(){

// OVERLABEL
	$("label.overlabel").overlabel();

// ACTIVE TABS
	$(function() {
		var classname = $('#content').attr('class');
		$('#nav').addClass(classname);
	});

// CONTENT SWAP
	$('ul.swap li:first-child').addClass('active');
	$('div.hidden:eq(0)').show();
	$('ul.swap a').click(function(){
		var $this = $(this);
		$('ul.swap li').removeClass('active');
		$('div.hidden').hide();
		$($this.attr('href')).fadeIn();
		$this.parent().addClass('active');
		return false;
	});

// SLIDER SWAP
	$('#subnav a').click( function( ){
		var $this = $(this);
		switch_im_a($this.attr('href'));
		return false;
	});
	$('.slider .close').click( function( ){
		$('div.slider').slideUp( );
		$.cookie('slider', null, { path: '/' });
	});

	if (value = $.cookie('slider')) {
		switch_im_a(value);
	}

// HOME VIDEO SWAP
	$('div.video:eq(0)').show();
	$('#videos .nav a').click(function(){
		var $this = $(this);
		$('div.video').hide();
		$($this.attr('href')).fadeIn();
		return false;
	});

// HOME SLIDESHOW MODAL
	$('#close').click(function(){
		$('#microsoft').hide();
		$('#iframe').fadeOut('slow');
		return false;
	});

// MAP SCRIPT
	$('.reps #find').click(function(){
		$(this).fadeOut();
		$('.reps #repform').fadeIn();
	});
	$('.reps #submit').click(function(){
		$('.reps #repform').fadeOut();
		$('.reps #represults').fadeIn();
	});

// PRESS FILTER
//	$('.press #sidenav a').click(function(){
//		$('.press .articles div').hide();
//		$($(this).attr('rel')).fadeIn();
//	});
//	$('.press #sidenav a.all').click(function(){
//		$('.press .articles div').fadeIn();
//	});

	// CYCLE
	$('#home_pics')
	    .cycle({
	        fx:     'fade',
	        speed:  'slow',
	        timeout: 10000,
	        pager:  '#bottom_nav',
	        pagerAnchorBuilder: function(idx, slide) {
	            // return selector string for existing anchor
	            return '#bottom_nav li:eq(' + idx + ') a';
	        },
	        before: function(curEl, nextEl, opts, fwFl) {
	            var next = nextEl.tagName.toUpperCase() == 'A' ? $(nextEl).find('img').get(0) : nextEl;
	            //$('#paragraph').html(window.paratext[next.id.replace(/img/,'')]);
	        }
	    });

	$('#testimonials')
	    .cycle({
	        fx:     'fade',
	        speed:  'slow',
	        timeout: 8000,
	        pager:  '#pager'
	    });


	// FANCYBOX
	$("a.zoom").fancybox( );

	// Fancybox groups
	$("div.entry_image_group").each( function( ) {
		$(this).find("a[rel^=group]").fancybox({
			'titlePosition' : 'over',
			'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
			    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
			}
		});
	});


// FLASH
// http://jquery.lukelutman.com/plugins/flash/example-basic.html

	// $('#ad').flash({
	// 	src: 'folder/file.swf',
	// 	width: 180,
	// 	height: 190
	// },
	// {
	// 	version: 8
	// });

});

function switch_im_a(hash) {
	$('div.slider').not(hash).slideUp( );
	$(hash).slideToggle( );

	// remove any previous cookies
	$.cookie('slider', null, { path: '/' });

	// add our new cookie
	$.cookie('slider', ($('div'+hash).is(':visible') ? hash : null), { path: '/' });
}
