
/* Index flash player
==================================================================*/
var flashvars = {}
var params = {
	base: ".",
	allowscriptaccess: "always",
	wmode: "transparent"
	}
var attributes = {}

function loadVideo() {swfobject.embedSWF("/assets/flash/commercial_6-24-11.swf", "video_player", "535", "276", "9.0.0", false, flashvars, params, attributes);}
function loadVideoWLOH() {swfobject.embedSWF("/assets/flash/weLoveOurHouse_updated.swf", "video_player", "535", "276", "9.0.0", false, flashvars, params, attributes);}

function closeVideo() {
	$("#popup_video").trigger("endVideo");
}

$("#popup_video").live("endVideo", function(e) {
	$(this).fadeOut('fast');
	$('object#video_player').remove();
	$('div#upcoming_playa > p').fadeIn('fast');
	$(this).html('<div id="video_player"></div>');
});
/*================================================================*/

$(function(){

	/* slideFadeToggle Menus
	==================================================================*/
	jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
	  return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
	};

	$("p#close_notification a").click(function (){
		$("#notification").slideFadeToggle('slow');
		return false;
	});

	/* $("p.meta.toggle").remove(); <img src="/assets/images/show_hide.png" /> */

	$("h1.toggle").before('<p class="meta toggle"><a href="#">hide / show</a></p>');

	$("p.meta.toggle").click(function (){
		$("div.top_border").slideFadeToggle('slow');
		return false;
	});
	/*================================================================*/

	/* Index Slideshow
	==================================================================*/
	$('div#features').cycle({
				speed: 500,
				prev: '#prev',
				next: '#next',
				before: onBefore,
				pause: 1
		    });
	function onBefore() {$('#title').html(this.title);}

	$('div#features a.video_feature').click(function (){
		$('div#upcoming_playa > p').fadeOut('fast', function() {
			$('#popup_video').fadeIn('fast');
			loadVideo();
		});
		return false;
	});

	$('div#features a.video_we_love_our_house').click(function (){
		$('div#upcoming_playa > p').fadeOut('fast', function() {
			$('#popup_video').fadeIn('fast');
			loadVideoWLOH();
		});
		return false;
	});

	$('#popup_video p a').click(function () {
		$('#popup_video').fadeOut('fast', function() {
			$('div#upcoming_playa > p').fadeIn('fast');
		});
		return false;
	});
	/*================================================================*/

	/* Media Player Stuff
	==================================================================*/
	$('a.watch_popup').live('click', function() {
		$(this).popupWindow({ centerScreen: 1, width: 500, height: 357});
		$.fn.colorbox.close()
		return false;
	});

	$('a.watch_popup.details').click(function() {
		$(this).popupWindow({ centerScreen: 1, width: 500, height: 370});
		//var player = "player";
		//player.sendEvent("PLAY","true");
		return false;
	});

	$('a.listen_popup').live('click', function() {
		$(this).popupWindow({ centerScreen: 1, width: 500, height: 115});
		$.fn.colorbox.close()
		return false;
	});

	jQuery.fn.fadeToggle = function(speed, easing, callback) {
	  return this.animate({opacity: 'toggle'}, speed, easing, callback);
	};

	var page_h = $(document).height();

	$('div#lights').css({height: page_h + 'px'});

	$('ul#mediaplayer_icons li a#lights').click(function() {
		$('div#lights').fadeToggle();
		$(this).toggleClass('lights_off');
		return false;
	});

	/*
	==================================================================*/
	$(".f1").colorbox({width:"755px", height:"80%", iframe:true});
	$(".spt").colorbox({width:"755px", height:"595px", iframe:true});
	$("a.colorbox").colorbox({width:"430px", opacity:".7"});
	$("a.colorbox_video").colorbox({opacity:".7"});
	$("a.colorbox_video_announcement").colorbox({width:"539px", height:"356px", opacity:".7", iframe:true});
	$("a[title='Service Times']").colorbox({width:"400px", opacity:".7"});
	$("a.open_campus_maps").colorbox({width:"866px", height:"632px", opacity:".7", inline:true, href:"#campus_map", title:"Campus Map"});
	$("a[title='Mission Statement']").colorbox({width:"350px", opacity:".7"});
	$("a[title='Statement of Faith - What We Believe'], a[title='Seven Pillars of The Rock']").colorbox({width:"600px", opacity:".7"});

	$("a[title='The Story - SPT']").colorbox({width:"500px", height:"650px", opacity:".7"});
	$("a[title='SPT Bulletin Board']").colorbox({width:"602px", height:"530px", opacity:".7"});
	$("a[title='SPT Newsletters']").colorbox({width:"400px", opacity:".7"});
	$("#volunteer_vid").colorbox({href:"/assets/video/volunteer.php", opacity:".7"});
	$("a.listen, a.video").colorbox({opacity:".7"});


	$("a.listen.alt_domain").colorbox({width:"545px", height:"190px", iframe:true});
	$("a.video.alt_domain").colorbox({width:"545px", height:"450px", iframe:true});

	$("a.sp_easter").colorbox({width:"449px", height:"608px", iframe:true});

  $(".tip").tipTip({edgeOffset: 5, maxWidth: "150px"});

  /*
	var mensConf = new Date();
	mensConf = new Date(mensConf.getFullYear() + 0, 3 - 1, 5, 19, 0, 0);
	$('#countdown').countdown({until: mensConf});
	*/

	var addShortTitle = $('ul#mediaplayer_add_links li.short_url');
	var addShortLink = $('p.short_url');

	addShortTitle.click(function() {
		console.log("toggle click");
		addShortTitle.toggleClass("hover");
		addShortLink.slideToggle();
	});

	$('input#short_url').click(function() {
		this.select();
	});


	var smallgroupLeaders = $('div.content_item.small_groups');
		    smallgroupLeaders.hide().filter('.featured_item').show();

		    $('ul.smallgroup_leaders li a.link').click(function () {
		    	//bioContainers.fadeOut('slow').slideUp('slow').animate({opacity: 1.0}, 1100);
		    	smallgroupLeaders.hide();
				smallgroupLeaders.filter(this.hash).fadeIn('slow').slideDown('slow');
		    	return false;
		    }).filter('.featured_item').click();



	var msie6 = $.browser == 'msie' && $.browser.version < 7;

  	if (!msie6) {
  	  var tall, diff, max, aT, aH, cH;

  	  aT = $('#aside').offset().top;
  	  //console.log('aside top:' + aT);
  	  aH = $('#aside').height();
  	  //console.log('aside height:' + aH);
  	  cH = $('#content_wrapper').height();
  	  //console.log('content Height:' + cH);

  	  // Check for home page
  	  if ($("#content_home").length > 0){
  	  // If it is, get the height of Life thumbnails
  	  	jc = $('.jcarousel-skin-trc').height();
  	  	//console.log('carasel: ' + jc)
  	  // Subtract Life height from cH and add 114
  	  	cH = (cH - jc) + 114;
  	  //return new value for cH
  	  	//console.log('new ch: ' + cH);
	  }

  	  diff = cH - aH;
  	  max = aT + diff;
  	  tall = (cH > aH) ? true : false;
  	  //console.log('diff: ' + diff + ' -- max: ' + max + '  -- tall: ' + tall);

  	  $(window).scroll(function (event) {
  	  var y = $(this).scrollTop();
  	  //console.log(y);
  	      if (tall) {
  	      	if ( y >= aT && y < max ) {
  	      		if (!$('#aside').hasClass('fixed_aside')) {
  	      	    	//console.log('add fixed class');
  	      			$('#aside').removeClass('bottom_aside').addClass('fixed_aside');
  	      		}
  	      	} else if ( y > max) {
  	      		if (!$('#aside').hasClass('bottom_aside')) {
  	      	    	//console.log('add bottom class');
  	      	    	$('#aside').removeClass('fixed_aside').addClass('bottom_aside');
  	      		}
  	      	} else {
  	      		$('#aside').removeClass('fixed_aside bottom_aside');
  	      	}
  	      }
  	  });
  	 }




// MAP
//==============================================================================================
//==============================================================================================
	$('#campus_map').zoommap({
			// Width and Height of the Map
			width: '823px',
			height: '560px',

			//Misc Settings
			blankImage: 'http://www.rockchurch.com/assets/images/campus_map/blank.png',
			zoomDuration: 1000,
			bulletWidthOffset: '10px',
			bulletHeightOffset: '10px',

			//ids and classes
			zoomClass: 'zoomable',
			popupSelector: 'div.popup',
			popupCloseSelector: 'a.close',

			//Return to Parent Map Link
			showReturnLink: true,
			returnId: 'returnlink',
			returnText: 'return to campus map',

			//Initial Region to be shown
			map: {
				id: 'campus',
				image: 'http://www.rockchurch.com/assets/images/campus_map/campus_v2.jpg'
				//data: '/lib/campus_map/campus.html'
				//maps: [
				//{
				//	id: 'quads',
				//	parent: 'campus',
				//	image: '/assets/images/campus_map/quads.png',
				//	data: '/lib/campus_map/quads.html',
				//	width: '69px',
				//	height: '103px',
				//	top: '57px',
				//	left: '134px'
					/* More maps can be nested
					maps : [ ]
					*/
				//}
				//]
			}
		});

});

