$(document).ready(function(){  
	
	//extend jquery to add a check for an element
	$.fn.extend({
  		inDOM : function() { return !!$(this).parents('html').length; }
	});
	
	verse_listener();
	
	$("#article img").dropShadow({
			left: 0,
			top: 1,
			blur: 2,
			opacity: .5,
			color: "black",
			swap: false
	});
	
	
	
	if(!$('#cb_wufoo').inDOM()){
		if($('#article').inDOM()){
			new_height = $('#footer').position().top - $('#article').position().top - 80;
			$('#article').height(new_height);
		}
	}
		
	
	$("#all-series img").removeShadow();
	$(".video-series img").removeShadow();	
	
	//launch the worship player
	$("#worship_player").click(function () {
		window.open('http://crossbridge.cc/worship_player/player.php','player','width=355,height=261');
		return false;
	});
	
	//launch the talks player
	$(".talks_player").click(function () {
		rel = $(this).attr("rel").split("~~|~~");
		window.open('http://www.crossbridge.cc/talks_player/player.php?queryValue='+rel[0]+'&start='+rel[1],'player','width=355,height=261');
		return false;
	});


	//jumpmenu for series slection
	$(".jumpmenu").change(function(){
		location.href = $(this).val();
	});
	
	//Series Description slider
	$('.description').click(function () {
		$('.series_descr').slideToggle();
		return false;
	});
	
	//Series Single slider
	$('.play').click(function () {
		$('.current_series_player').slideToggle();
		return false;
	});
	
    $(".video_overlay").click(function() {
        
        $.fancybox({
            'padding'       : 0,
            'autoScale'     : false,
            'title'         : this.title,
            'width'         : 640,
            'height'        : 360,
            'href'          : this.href,
            'overlayOpacity': 0.9,  
            'overlayColor'  : '#000',
            'type'          : 'swf'
        });
    
        return false;
    });     
	
	
	//New here scripts
	$('.new_here ul').kwicks({max: 310, duration: 350, easing: 'easeInOutCubic'});

	$("#questions a").click(function () {
		$("#new_here_header").html('Questions?');
		$("#new_here_content").html('Loading...').load("/new-here/ #new_here_content", '', function(){
			bottom = $('#new_here_content').position().top + $("#new_here_content").height()
			$('#article').height(bottom);
		});
		return false;
	});

	$("#staff a").click(function () {
		$("#new_here_header").html('Our Staff');
		$("#new_here_content").html('Loading...').load("/connect/staff/ #staff_content", '', function(){
			bottom = $('#staff_content').position().top + $("#staff_content").height()
			$('#article').height(bottom);	
		});
		return false;
	});

	$("#story a").click(function () {		
		$("#new_here_header").html('Our Story');
		$("#new_here_content").html('Loading...').load("/new-here/our-story/ #our_story", '', function(){
			bottom = $('#our_story').position().top + $("#our_story").height()
			$('#article').height(bottom);
		});
		return false;
	});
	
	$("#mission a").click(function () {		
		$("#new_here_header").html('Mission & Beliefs');
		$("#new_here_content").html('Loading...').load("/new-here/mission-beliefs/ #mission_beliefs", '', function(){
			verse_listener();
			bottom = $('#mission_beliefs').position().top + $("#mission_beliefs").height()
			$('#article').height(bottom);
		});
		return false;
	});
	
	//homepage news items
	$("ul#news_items li:nth-child(odd)").addClass("odd");
		
}); 

function verse_listener(){
	//set up the verses popouts
	$('.verse_tip').simpletip({
 	 	
	 	onBeforeShow: function(){
	 		
	  		this.update( this.getParent().attr("rel") );
	  		
	  		var tt_height = this.getTooltip().height();
			
			if(tt_height > 250){
				this.getTooltip().children('.tooltip_body').height(190);
			}  
		}
	});
}

function video(vimeo_id){
	dom_add = '<object width="640" height="368"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id='+vimeo_id+'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id='+vimeo_id+'&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="640" height="368"></embed></object>';
	$('#promo_video').empty().append(dom_add);
	tb_show('','#TB_inline?height=368&width=640&inlineId=promo_video',false);
}