jQuery(document).ready(function() {
	
	Cufon.replace('h1, h2, h3, h4, h5', { fontFamily: 'Frutiger LT 45 Light', fontWeight: 700, hover: true }); 
	Cufon.replace('#nav a, .tabs a', { fontFamily: 'Frutiger LT 45 Light', hover: true, fontWeight: 700 }); 

	if (jQuery('#photos').length > 0) {
		jQuery('#photos').galleryView({
			panel_width: 585,
			panel_height: 370,
			frame_width: 90,
			frame_height: 70,
			overlay_opacity: 1.0,
			overlay_color: '#000000',
			overlay_text_color: 'white',
			caption_text_color: '#3d373d',
			background_color: '#e5e5e5',
			border: 'none',
			nav_theme: 'light',
			easing: 'easeInOutQuad',
			pause_on_hover: true
		});
	}

	if (jQuery('#nav').length > 0) {
		var z = 10;
		jQuery('#nav').find('li').each(function() {
			jQuery(this).css('zIndex',z);
			z--;
		});
	}
	
	
	if (jQuery('#slide-box').length > 0) {

		jQuery('.slide-tabs').find('a.btn-about').each(function() {
		
			jQuery(this).click(function() {
			
				if (jQuery('#slide-box').css('marginTop') == '0px') {
					jQuery('#slide-box').animate({marginTop:-260}, 500);
				}
				
				if (jQuery('#slide-box').css('marginTop') == '-260px') {
					jQuery('#slide-box').find('.about').css('zIndex','220');
					jQuery('#slide-box').find('.listen').css('zIndex','219');
					jQuery('#slide-box').animate({marginTop:0}, 500);
				}
				return false;
			});
		});
			}

	if (jQuery('#photos').length > 0) {
		var img = jQuery('#path').text();
		jQuery('#photos').find('.strip_wrapper').attr('id','strip_wrapper');
		jQuery('#pointer').css('left','3px');
		jQuery('#strip_wrapper').css({left: '3.5px', width: '578px', top: '375px'});
		jQuery('#pointer').css('left','3px');
		jQuery('#pointer').children('img').attr('src',img+'slide-arrow.png').css({top: '-19px', height: '10px'});
		jQuery('#photos').children('img.nav-next').attr('src',img+'slide-arrow-right.png').css({width: '29px', height: '55px', top: '123px', left: '557px'});
		jQuery('#photos').children('img.nav-prev').attr('src',img+'slide-arrow-left.png').css({width: '29px', height: '55px', top: '123px', left: '0px'});
	}
	
	if (jQuery('#tabbed').length > 0) {
		jQuery('#tabbed').children(jQuery('#tabbed').find('li.selected').children('a').attr('href')).fadeIn();
	
		jQuery('#tabbed').children('.tabs').find('a').click(function() {
			jQuery('#tabbed').children('.tabs').find('.selected').removeClass('selected');
			jQuery(this).parent('li').addClass('selected');
			jQuery('#tabbed').children('.tab-content').hide();
			jQuery('#tabbed').children(jQuery(this).attr('href')).fadeIn();
			return false;
		});
	}

	if (jQuery('#event-list').length > 0) {
		jQuery('#event-list').find('.event-date').each(function() {
			var arr = jQuery(this).text().split(' ');
			jQuery(this).find('td').empty().append('<h3>'+arr[0]+'</h3>'+arr[1]);
		});
	}	
	
	if (jQuery('.foot-navs').length > 0){
		jQuery('.foot-navs').find('li:not(:last)').after('<li> | </li>');
	}

	if (jQuery('.ngg_slideshow').length > 0){
		jQuery('.ngg_slideshow').parent('div').append(jQuery('ul#plainslide'));
		jQuery('.ngg_slideshow').remove();
	}

	if (jQuery('.ngg-galleryoverview').length > 0){
		var c = 1;
		jQuery('.ngg-galleryoverview').children('.ngg-gallery-thumbnail-box').each(function() {
			if (c==4){
				jQuery(this).addClass('right');
				c=1;
			}else{
				c++;
			}
			
		});
	}

	if (jQuery('.dig-in').length > 0) {
		jQuery('.dig-in a').attr('href', 'http://'+location.hostname+'/whats-up');
	}

	if (jQuery('.wp-polls-form').length > 0){
		jQuery('.wp-polls-form').children('p:eq(1)').wrapInner('<h3 />');
	}

	if (jQuery('ul.upcoming').length > 0){
		jQuery('ul.upcoming li').each(function() {
			jQuery(this).children('div.when').before(jQuery(this).children('div.event'));
			jQuery(this).children('div.event').replaceWith('<h3>'+jQuery(this).children('div.event').html()+'</h3>')
		});		
	}

	jQuery(".prettyPhoto").prettyPhoto({
		opacity: 0.80,
		allowresize: true,
		default_width: 670,
		default_height: 670,
		show_title: false,
		theme:'dark_rounded'
	});

	jQuery('.contact-form').click(function() {
		Cufon.replace('#contact-form h1,#contact-form h2', { fontFamily: 'Frutiger LT 45 Light', fontWeight: 700, hover: true }); 
	});

	jQuery('.btn-listen').popupWindow({ centerBrowser:1, width: '980', height: '248' }); 

	if (jQuery('#footer .logos').length > 0){
		jQuery('#footer .logos').find('a').each(function() {
			var imgw = jQuery(this).children('img').outerWidth();
			var imgs = jQuery(this).children('img').attr('src');
			jQuery(this).css({backgroundImage: 'url('+imgs+')'});
			jQuery(this).empty();
		});
	}
	
});

jQuery(window).load(function() {
	if (jQuery('#event-list').length > 0) {
		jQuery('#event-list .events ul li').each(function() {
			var th = jQuery(this).outerHeight() + 1;
			jQuery(this).find('.event-date table').css('height', th);
			jQuery(this).find('.event-ticket table').css('height', th);
		});
	}	

	jQuery('#news').innerfade({ animationtype: 'fade', speed: 'slow', timeout: 4000, type: 'sequence', containerheight: '1em' });

	jQuery('#plainslide').innerfade({ animationtype: 'fade', speed: 'slow', timeout: 4000, type: 'sequence', containerheight: '240px' });

	if (jQuery('#contact-form-wrap').length > 0){
		if (jQuery('.wpcf7-validation-errors, .wpcf7-mail-sent-ok').length > 0){
			jQuery('a.contact-form').click();
		}
	}

	if (jQuery('#breaking-news').length >0){
		jQuery('#breaking-news').prepend('<span class="breaking-news-logo"></span>');
	}

});
