// JavaScript Document
function doMail(name, company, domain) {
      locationstring = 'mai' + 'lto:' + name + '@' + company + '.' + domain;
      window.location.replace(locationstring);
   }
  
$(document).ready(function() {
	/* $activateSIFR 		= false; 
	$activateAbout 		= false;
	$activateCalendar 	= false;
	$activateLegal 		= false;
	$activatePhotobooth = false;*/
	
	$(".readmorelink a").click(function(){
		if ($(this).hasClass("active")){
			// close it
			$(this).removeClass("active").text("Read More").css("opacity",1);
			$(".readmore").slideUp();
		} else {
			// open it
			$(this).addClass("active").text("Read Less").css("opacity",.3);
			$(".readmore").slideDown();
		}
		return false;
	});
	
	
	// SPECIAL EVENTS
	var $special = $("body#special-events");
	if ($special.exists()){
		// fancybox
		$("body#special-events .gallery a").fancybox();
		
		
		// setup sidebar
		$("body#special-events .sidebar ul li a").click(function(){
			var $li = $(this).parents('li');
			var $ul = $(this).parents('ul');
			var num = $ul.children().index($li);
	
			mercy.slideDiv("special-events","outerMask", "innerMask", num);
			
			mercy.activateNav("special-events","sidebar",num);
			
			return false;
		});
		// setup individual "next" buttons
		$("body#special-events .entry a.features-and-services").click(function(){
			mercy.slideDiv("special-events","outerMask","innerMask",1);
			mercy.activateNav("special-events","sidebar",1);
			return false;
		});
		$("body#special-events .entry a.accommodations").click(function(){
			mercy.slideDiv("special-events","outerMask","innerMask",2);
			mercy.activateNav("special-events","sidebar",2);
			return false;
		});
		$("body#special-events .entry a.viewing").click(function(){
			mercy.slideDiv("special-events","outerMask","innerMask",3);
			mercy.activateNav("special-events","sidebar",3);
			return false;
		});
		$("body#special-events .entry a.gallery").click(function(){
			mercy.slideDiv("special-events","outerMask","innerMask",4);
			mercy.activateNav("special-events","sidebar",4);
			return false;
		});
		
		// if there's a value for SWF address coming in, lets pull it up
		if (SWFAddress.getValue() != "/"){
			var seo = SWFAddress.getValue().substr(1);
			var location = $("body#special-events .sidebar ul li").find("a."+seo);
			location.click();
			//slideThumbs("posterThumbs", SWFAddress.getValue().substr(1));
		}
		
		
	}
	
	// ABOUT - FAQ
	var $faq = $("body#about .faq-block");
	if ($faq.exists()){
		$("body#about .faq-block ol li a.query").click(function(){
			var $li = $(this).parents('li');
			var $ans = $li.find(".answer");
			
			if ($ans.css("display") == "block"){
				$ans.slideUp();
			} else {
				$ans.slideDown();
			}
	
	
			return false;
		});
	}
	
	// PHOTO PAGE
	var $photo = $("body#media .photo-block");
	if ($photo.exists()){
		// thumb clicks
		$("body#media .thumbs ul li a").click(function(){
			var $id = $(this).attr("rel");
			
			if ($("#currentImage").val() != $id){
				$.post("_lib/func_gallery.php",
				{targ: $id, sec: "gallery", action:"fetch"},
				function(data)
				{
					if (data){
						var results = data.split("::");
						var $html 	= "<strong>"+results[1]+"</strong><br />Credit: "+results[2]+"<br />"+results[3];
						var $img 	= "<img rel='"+$id+"' src='_img/_photo/"+results[0]+".jpg' />";
						var $top 	= $(".thegallery").css("margin-top");
						$top 		= $top.replace("px","");
						var $margin= $(".main-image").css("margin-bottom");
						$margin		= $margin.replace("px","");
						var dest 	= $top - 395;
						
						$("#currentImage").val($id);
						
						// append new item
						$(".thegallery").append("<li>"+$img+"</li>");
						// animate it
						$(".thegallery").animate({ 
							marginTop: dest
						  }, 400 );
						// update caption
						$("#img-caption").html($html);
						
					} 
				});
			}
			
			return false;
		});
	
		
		
		var totalPages = $("body#media .thumbMask ul").size();
		var newWidth = totalPages * $("body#media .thumbMask").width();
		$(".innerMask").css("width",newWidth);
		
		// pagination clicks
		$("body#media .pagination a.next").click(function(){
														  
			var width = $("body#media .thumbMask").width();
			var thisPage = parseInt($("body#media #thumbPage").val());
			nextPage = thisPage + 1;
			$("body#media #thumbPage").val(nextPage);
			if (nextPage <= totalPages){
				mercy.pagination("body#media .thumbMask .innerMask", width, nextPage, totalPages);	
			}
			return false;
		});
		// pagination clicks
		$("body#media .pagination a.prev").click(function(){
														  
			var width = $("body#media .thumbMask").width();
			var thisPage = parseInt($("body#media #thumbPage").val());
			prevPage = thisPage - 1;

			$("body#media #thumbPage").val(prevPage);
			if (prevPage > 0){
				mercy.pagination("body#media .thumbMask .innerMask", width, prevPage, totalPages);	
			}
			return false;
		});
		
	}
	
	var $cal	= $("body#calendar");
	if($cal.exists()){
		
		//$activateSIFR = true;
		//$activateCalendar = true;
		
		$("body#calendar .venues li a").toggle(
			/* turn OFF all the opposite venue */
			function(){
				if ($("body#calendar .venues li a").hasClass("active")){
					$curVenue = $("body#calendar .venues li a.active");
					$curVenue.click();
				}
				var $li = $(this).parents('li');
				var $venue = $li.attr("class");
				// different targs depending on view mode
				var $mode = $("#viewMode").val();
				if ($mode == "list"){
					var $targ = $("ul.calendar > li:not(."+$venue+")");
				} else {
					var $targ	= $(".calendar-meat .day .event div:not(."+$venue+")").parent('div.event');
				}
				//alert($targ);
				$targ.slideUp();
				$(this).addClass("active");
				
				return false;
			},
			/* turn ON all the opposite event */
			function(){
				var $li = $(this).parents('li');
				var $venue = $li.attr("class");
				
				// different targs depending on view mode
				var $mode = $("#viewMode").val();
				if ($mode == "list"){
					var $targ = $("ul.calendar > li:not(."+$venue+")");
				} else {
					var $targ	= $(".calendar-meat .day .event div:not(."+$venue+")").parent('div.event');
				}
				//alert($targ);
				$targ.slideDown();
				$(this).removeClass("active");
				
				return false;
			}
		);
		$fancy = $("body#calendar .flyer a");
		if ($fancy.exists()){
			// setup fancy box
			$("body#calendar .flyer a").fancybox();
		}
		
		
		$musicList = $("body#calendar .music ul li a");
		if ($musicList.exists()){
			$musicList.click(function(){ return false; } );
		}
		
	}
	
	/*var $legalPage  = $("body#home .legal");
	if ($legalPage.exists()){
		$activateSIFR = true;
		$activateLegal = true;
	}
	
	var $aboutPages  = $("body#about");
	if ($aboutPages.exists()){
		$activateSIFR = true;
		$activateAbout = true;
	}*/
	
	var $photobooththumbs	= $("body#media .photobooth-thumbs a");
	if($photobooththumbs.exists()){
		
		$fancy = $("body#media .photobooth-thumbs a");
		if ($fancy.exists()){
			// setup fancy box
			$("body#media .photobooth-thumbs a").fancybox();
		}
		
	}
	
	var $mediaSignup	= $("body#media.signup");
	if($mediaSignup.exists()){
		
		$(".bigButton a").click(function(){
			// check the birthday
			var day = $("#coppa-day").val();
			var month = $("#coppa-month").val();
			var year = $("#coppa-year").val();
			var theirDate = new Date(year, month-1, day);
			
			var today = new Date();
			
			var diff = Math.ceil(theirDate.getFullYear() - today.getFullYear()) * -1;
			
			if (diff >= 13){
				var dest = "http://mm.ticketmaster.com/brand/userlogin.aspx?b=mercylounge2&l=17";
				window.location = dest;
			} else {
				$.cookie('mercyRestriction', diff, { expires: 30, path: '/', domain: '.mercylounge.com', secure: false });
				$("#birthError").slideDown();
				$(".bigButton a").slideUp();
				$(".birthday").slideUp();
				$(".getmusic").slideUp();
			}
			
			return false;
		});
		
	}
	
	
	if ($activateSIFR = true)
	{
	/*	sIFR.compatMode = true;
		sIFR.activate(rockwell);
		 
		if ($activateAbout){
			// About page TITLES
			sIFR.replace(rockwell, {
			  selector: 'h2.sifr'
			  ,css: {
				'.sIFR-root': { 'background-color': '#e6ebee' }
			  }
			  ,selectable: true
			  ,wmode: 'transparent'
			});
		}
		
		
		 if ($activateCalendar){
			// this is /calendar
			sIFR.replace(rockwell, {
			  selector: 'h2.calendarsifr'
			  ,css: {
				'.sIFR-root': { 'background-color': '#e6ebee', 'color':'#5e5e5e', 'text-align':'center','text-transform': 'uppercase' }
			  }
			  ,selectable: true
			  ,wmode: 'transparent'
			});
			
			// this is /calendar/venue/someevent
			sIFR.replace(rockwell, {
			  selector: 'h1.titlesifr'
			  ,css: {
				'.sIFR-root': { 'background-color': '#FFFFFF', 'color':'#5e5e5e', 'text-align':'left'}
			  }
			  ,selectable: true
			  ,wmode: 'transparent'
			});
		 }
		 
		 
		 
		 if ($activateLegal){
			// this is privacy policy and terms of use
			sIFR.replace(rockwell, {
			  selector: 'h1.legalsifr'
			  ,css: {
				'.sIFR-root': { 'background-color': '#e6ebee' }
			  }
			  ,selectable: true
			});
		 }
		 
		 */
	}//end SIFR if
	
	
	
});



var mercy = {};

mercy.slideDiv = function(bodyID, mask, container, iteration){
	var width = $("body#"+bodyID+" ."+mask).width();
	var dest = parseInt(width * iteration) * -1;

	var margin = (iteration) * 10;
	var dest = dest - margin;
	
	$("body#"+bodyID+" ."+container).animate({ 
			marginLeft: dest
		  }, 700 );
	
}
mercy.activateNav = function(bodyID, targ, iteration){
	$("body#"+bodyID+" ."+targ+" ul li a").removeClass("active");	
	$("body#"+bodyID+" ."+targ+" ul li:eq("+iteration+") a").addClass("active");	
	
	var title = $("body#"+bodyID+" ."+targ+" ul li:eq("+iteration+") a").attr("href");
	var title = title.replace(bodyID, "");
	
	SWFAddress.setValue(title);

}

mercy.pagination = function(divID, height, page, totalPages){

	altPage	= page -1;
	var dest = (height * altPage) * -1;

	$(divID).animate({ 
			marginLeft: dest
		  }, 500 );
	
	
	
	if (page > 0){
		$("body#media .pagination a.prev").removeClass("inactive");	
	} 
	if (page == 1){
		$("body#media .pagination a.prev").addClass("inactive");
		$("body#media .pagination a.next").removeClass("inactive");
	}
	if (page >= totalPages){
		$("body#media .pagination a.next").addClass("inactive");
	}
	
}



/* SIFR
 var rockwell = {
      src: '/_js/rockwell.swf'
      ,ratios: [6, 1.41, 9, 1.35, 15, 1.29, 21, 1.25, 22, 1.22, 27, 1.24, 29, 1.21, 34, 1.22, 41, 1.21, 45, 1.2, 46, 1.21, 59, 1.2, 68, 1.19, 69, 1.2, 96, 1.19, 97, 1.18, 102, 1.19, 103, 1.18, 107, 1.19, 108, 1.18, 112, 1.19, 114, 1.18, 116, 1.19, 120, 1.18, 121, 1.19, 1.18]
    };
*/
/* jQUERY */
/*	******************************
		PLUGIN - Utility Functions 
		Author: Jack Lukic - KNI (all plugins)
		Notes: Used to extend jQuery functionality and shorten code
	******************************	*/

jQuery.fn.extend({
	// test if el exists
	exists: function() {
		if(this.size() > 0) {
			return true;
		}
		else {
			return false;	
		}
	}
});
