$(document).ready(function() {
	
	
	// position home page top left and right column boxes
	function positionHomeColumns() {
	
		if( $("#hp_top .left").length ) {
			
			// if there is a hp_top left class, we're on the home page
			
			var leftObj = $("#hp_top .left")
			var rightObj = $("#hp_top .right")
			
			// handle left side
			var posLeft = $(leftObj).position(); 
			var relLeft = $(window).width()*.5 - (960*.5); 
			if(relLeft > posLeft.left) {
				
				var adjLeft = parseInt(relLeft + posLeft.left)
				adjLeft = (posLeft.left - adjLeft) + 30;
				$(leftObj).css('left',adjLeft+'px');
				
			}
			
			// handle right side
			var posRight = $(rightObj).position();
			var relRight = $(window).width()*.5 + (960*.5); //alert(relRight + " -> " + posRight.left);
			
			if(relRight > posRight.left) {
				
				var delta = $(window).width()*.5 - (960*.5);
				
				var adjRight = parseInt( $(window).width() - $(rightObj).width() - delta - 30 );
				$(rightObj).css('left',adjRight+'px');
				
			}
			
		}
		
	}
	
	positionHomeColumns();
	
	
	$(".about-tryptych").click(function() {
		
		if(!$(this).hasClass('selected')) {
			
			
			// turn off the active button
			$(".about-tryptych").each(function() { 
				if($(this).hasClass('selected')) {
					$(this).removeClass('selected') 
					$(this).css({"background":"none","color":"#251E18"});
				}
				
			});
			
			// make this the active button
			$(this).addClass('selected');
			$(this).css({"background":"#9cb888","color":"#fef7e7"});
			
			// grab the current <div>
			var current = "";
			$(".tryptych .inside").each(function() { if($(this).is(":visible")) current = $(this); });
			
			// grab the next <div>
			var idx = $(".about-tryptych").index($(this));
			var next = $(".tryptych .inside").get(idx);
			
			// turn off the old, turn on the new	
			$(current).hide();
			$(next).show();
			
		}
		
	});
	
	
	$(".donation").click(function() {
		
		// turn off the active button
		$(".donation").each(function() { 
			if($(this).hasClass('selected')) {
				$(this).removeClass('selected');
				$(this).css({"background":"none","color":"#251E18"});
			}
		});
		
		// make this the active button
		$(this).addClass('selected');
		$(this).css({"background":"#9cb888","color":"#fef7e7"});
		
		// grab the current <div>
		var current = "";
		$(".list-area").each(function() { if($(this).is(":visible")) current = $(this); });
		
		// grab the next <div>
		var idx = $(".donation").index($(this));
		var next = $(".list-area").get(idx);
		
		// turn off the old, turn on the new	
		$(current).hide();
		$(next).show();
		
	});
	
	$(".donation").hover(
		function() { if(!$(this).hasClass("selected")) $(this).css("color","#46593F") },
		function() { if(!$(this).hasClass("selected")) $(this).css("color","#251E18") }
	);
	
	
	
	$(".about-tryptych").hover(
		function() { if(!$(this).hasClass("selected")) $(this).css("color","#46593F") },
		function() { if(!$(this).hasClass("selected")) $(this).css("color","#251E18") }
	);
	
	// VIDEO DISPLAY
	
	// make sure the video and blanket always fits the document
	function positionVideo() {
		
		$("#blanket").width('100%');
		$("#blanket").height($(document).height());
		
		var box = $("#blanket .player");
		var center = $(window).width() * .5;
		var boxLeft = center - ( $(box).width() * .5 );
		
		$(box).css("left",boxLeft+"px");
		
	}
	
	positionVideo();
	
	
	function sizeBG() {
		
		var w = $("#background").width(); 
		var h = $("#background").height();
		var delta = 0;
		
		if(w<1200 && h>0) {
			var delta = 770 - h;
			delta*= -1;
			
			var cols = $("#hp_three_cols");
			$(cols).css({'position':'relative','top':delta+'px'});
		}
		
		//console.log(delta)
		
		
		
	}
	sizeBG()
	
	$(window)
		.resize(positionVideo)
		.resize(positionHomeColumns)
		.resize(sizeBG)
		//.scroll(adjustInner)
	
	$(".watch-video").click(function() {
		
		$("#blanket").show();
		// play the video
		//$("#jquery_jplayer_1").jPlayer("play");
		
		
		//document.getElementById('vimeo_player').api_play();
		
	});
	
	$(".img-btn-watch-video").click(function() {
		
		$("#blanket").show();
		
	});
	
	$(".close-X").click(function() {
		// stop the video
		//$("#jquery_jplayer_1").jPlayer("stop");
		//document.getElementById('vimeo_player').api_pause();
		
		//$(".video-js").get(0).pause();
		$("#blanket").hide();
		
		
	});
	
	
	
	// IMG SWAP
	// swap product images
	$(".swap").hover(
		
		function(){ if(!$(this).hasClass('active')) this.src = this.src.replace("_off","_on") },
		function(){ if(!$(this).hasClass('active')) this.src = this.src.replace("_on","_off")
		
		});
		
	var overVideo = false;
		
	// volunteer video
	/*$(".img-btn-volunteer").hover(
		
		function(){ 
			//document.overVideo = true;
			var src = $(".btn-volunteer").attr("src").replace("_off", "_on");
            $(".btn-volunteer").attr("src", src);
		},
		function(){ 
			//document.overVideo = false;
			var src = $(".btn-volunteer").attr("src").replace("_on", "_off");
            if(!document.overVideo) $(".btn-volunteer").attr("src", src);
		}
	
	);*/
	
	
});
