$(document).ready(function(){
	var timeout;
	sliding = false;
	showing = false;
	
	//mouse events for map action
	$("div.action_btn[id!=drag_action]").mousedown(function(){
		$(this).addClass("sel");
	});
	$("div.action_btn[id!=drag_action]")
		.mouseup(function(){$(this).removeClass("sel");});
	$("a.tab").each(function(index){
		$(this).click(function(e){
			e.preventDefault();
			$("a.tab").removeClass("sel");
			$(this).addClass("sel");
			$(".content").hide();
			$(".content:eq("+index+")").show();
		});
	});
	//event for map link
	$("a.link").click(function(e){
		e.preventDefault();
		$(".link_dropdown").fadeIn();
	});
	//close drop down
	$("a#close_linkdd").click(function(e){
		e.preventDefault();
		$(".link_dropdown").fadeOut();
	});
	//event for show me drop down
	$("#show_action").click(function(e){
		e.preventDefault();
		if(showing==false){
			$(this).addClass("sel");
			$("#show_dd").fadeIn('fast',function(){
				showing = true;
			});
		}
	});
	//hide drop down after 1 second when mouseout
	$("#show_dd").mouseout(function(){
		timeout = setTimeout("hideDropDown()", 1000);
	}).mouseover(function(){
		clearTimeout(timeout);
	});
	//hide drop down when clicked anywhere outside drop down
	$(document).mouseup(function(e) {
		if($(e.target).parent("#show_action").length==0) {
			hideDropDown();
		}
	});
	$("fieldset#show_dd_fs").mouseup(function() {
		return false
	});

	//hide slideshow arrows
	$(".slideshow .arrows").css("visibility","hidden");

	totalSlides = $(".scroller_item").length;
	if(totalSlides > 3){
		$("#scroller_item_flow1").html($("#scroller_item_1").html());
		$("#scroller_item_flow2").html($("#scroller_item_2").html());
		$("#scroller_item_flow3").html($("#scroller_item_3").html());
		
		$(".slideshow .arrows").css("visibility","visible");
		
		//event for slideshow previous button
		$(".prev_slide").click(function(e){
			e.preventDefault();
			
			if (!sliding){
				sliding = true;
				var scroller_pos = $('#scroller_list').offset();
				var scroller_pos = scroller_pos.left;
				if (scroller_pos == 51)
				{
					$('#scroller_list').css( "left", (-(138*(totalSlides)))+'px' );
				}
				$("#scroller_list").animate({"left": "+=138px"}, "fast", function(){ sliding = false; });
			}
		});
		//event for slideshow next button
		$(".next_slide").click(function(e){
			e.preventDefault();
			
			if (!sliding){
				sliding = true;
				var scroller_pos = $('#scroller_list').offset();
				var scroller_pos = scroller_pos.left;
				
				if (scroller_pos == (-(138*(totalSlides-1))-87))
				{
					$('#scroller_list').css('left', '0px' );
				}
				$("#scroller_list").animate({"left": "-=138px"}, "fast", function(){ sliding = false; });
				//alert(scroller_pos);
			}
		});
	}
	//change video content when clicked on video thumbnail
	$(".scroller_item a").each(function(index){
		$(this).click(function(e){
			e.preventDefault();
			$("#scroller_list a").removeClass("sel");
			$(".vid_container").hide();
			
			$(".scroller_item a:eq("+index+"), .scroller_item_flow a:eq("+index+")").addClass("sel");
			$("#vid_"+index).show();
		});
	});
	$(".scroller_item_flow a").each(function(index){
		$(this).click(function(e){
			e.preventDefault();
			$("#scroller_list a").removeClass("sel");
			$(".vid_container").hide();
			
			$(".scroller_item a:eq("+index+"), .scroller_item_flow a:eq("+index+")").addClass("sel");
			$("#vid_"+index).show();
		});
	});
			//popups
			$(".popup a.close").click(function(e){
				e.preventDefault(e);
				var popupWindow = $(this).parents(".popup");
				
				popupWindow.hide();
			});
			$(".popup-links").click(function(e){
				e.preventDefault();
				hidePopups();
			});
			$("#link-event").click(function(e){
				e.preventDefault();
				hidePopups();
				
				$("#pop-event-1").show();
			});
			$("#link-intro").click(function(e){
				e.preventDefault();
				hidePopups();
				
				$("#pop-intro").show();
			});
			$("#link-picture").click(function(e){
				e.preventDefault();
				hidePopups();
				
				$("#pop-picture-1").show();
			});
			$("#link-link").click(function(e){
				e.preventDefault();
				hidePopups();
				
				$("#pop-link-1").show();
			});
			$("#link-add").click(function(e){
				e.preventDefault();
				hidePopups();
				
				$("#pop-add-1").show();
			});
					//popup add
					$("#add-pic").click(function(e){
						var popupWindow = $(this).parents(".popup");
						popupWindow.addClass("expanded pop-add-pic");
						popupWindow.removeClass("pop-add-link pop-add-event");
					});
					$("#add-link").click(function(e){
						var popupWindow = $(this).parents(".popup");
						popupWindow.addClass("expanded pop-add-link");
						popupWindow.removeClass("pop-add-pic pop-add-event");
					});
					$("#add-event").click(function(e){
						var popupWindow = $(this).parents(".popup");
						popupWindow.addClass("expanded pop-add-event");
						popupWindow.removeClass("pop-add-pic pop-add-link");
					});
					$("#go-back").click(function(e){
						e.preventDefault();
						var popupWindow = $(this).parents(".popup");
						popupWindow.removeClass("expanded comments pop-add-pic pop-add-event pop-add-link");
					});
				
			//maximize
			$(".maximize").click(function(e){
				e.preventDefault();
				var popupWindow = $(this).parents(".popup");
				$(".tab-desc").addClass("sel");
				popupWindow.removeClass("expanded comments event-photos event-videos event-enlarge");
				popupWindow.addClass("expanded");
			});
			$(".see_more, .tab-desc, .tab-photo").click(function(e){
				e.preventDefault();
				var popupWindow = $(this).parents(".popup");
				$(".fb-tabbed-nav a").removeClass("sel");
				$(".tab-desc, .tab-photo").addClass("sel");
				popupWindow.removeClass("comments event-photos event-videos event-rsvp event-enlarge");
				popupWindow.addClass("expanded");
			});
			//minimize
			$(".minimize").click(function(e){
				e.preventDefault();
				var popupWindow = $(this).parents(".popup");
				$(".fb-tabbed-nav a").removeClass("sel");
				$(".tab-desc").removeClass("sel");
				popupWindow.removeClass("expanded comments pop-add-pic pop-add-event pop-add-link");
			});
			$(".see_less").click(function(e){
				e.preventDefault();
				var popupWindow = $(this).parents(".popup");
				popupWindow.removeClass("expanded");
			});
			//comments
			$(".see_comments, .tab-wall").click(function(e){
				var popupWindow = $(this).parents(".popup");
				$(".fb-tabbed-nav a").removeClass("sel");
				$(".tab-wall").addClass("sel");
				popupWindow.removeClass("event-photos event-videos event-rsvp event-enlarge");
				popupWindow.addClass("expanded comments");
			});
			//event photos
			$(".tab-photos").click(function(e){
				var popupWindow = $(this).parents(".popup");
				$(".fb-tabbed-nav a").removeClass("sel");
				$(".tab-photos").addClass("sel");
				popupWindow.removeClass("comments event-videos event-rsvp event-enlarge");
				popupWindow.addClass("expanded event-photos");
			});
				//enlarge photo
				$(".photos_sec a").click(function(e){
					var popupWindow = $(this).parents(".popup");
					$(".fb-tabbed-nav a").removeClass("sel");
					$(".tab-photos").addClass("sel");
					popupWindow.removeClass("comments event-videos event-rsvp event-photos");
					popupWindow.addClass("expanded event-enlarge");
					
					var imgsrc = $(this).children('img').attr('src');
					var imgext = imgsrc.slice(-4);
					
					if(imgext == ".jpg"){
						imgsrc = imgsrc.replace(".jpg","_large.jpg");
					}else if(imgext == "jpeg"){
						imgsrc = imgsrc.replace(".jpeg","_large.jpeg");
					}else if(imgext == ".gif"){
						imgsrc = imgsrc.replace(".gif","_large.gif");
					}else if(imgext == ".png"){
						imgsrc = imgsrc.replace(".png","_large.png");
					}else{
						return false;
					}
					
					$(".event_enlarge").html("<img src='"+ imgsrc +"' alt=''/>");
				});
				//back to photos
				$(".back a").click(function(e){
					var popupWindow = $(this).parents(".popup");
					$(".fb-tabbed-nav a").removeClass("sel");
					$(".tab-photos").addClass("sel");
					popupWindow.removeClass("comments event-videos event-rsvp event-enlarge");
					popupWindow.addClass("expanded event-photos");
				});
			//event videos
			$(".tab-videos").click(function(e){
				var popupWindow = $(this).parents(".popup");
				$(".fb-tabbed-nav a").removeClass("sel");
				$(".tab-videos").addClass("sel");
				popupWindow.removeClass("comments event-photos event-rsvp event-enlarge");
				popupWindow.addClass("expanded event-videos");
			});
			//event rsvp
			$(".tab-rsvp").click(function(e){
				var popupWindow = $(this).parents(".popup");
				$(".fb-tabbed-nav a").removeClass("sel");
				$(".tab-rsvp").addClass("sel");
				popupWindow.removeClass("comments event-photos event-videos event-enlarge");
				popupWindow.addClass("expanded event-rsvp");
			});
});
function hideDropDown(){
	if(showing){
		$("#show_dd").fadeOut('fast',function(){
			showing = false;
		});
		$("#show_action").removeClass("sel");
	}
}
function hidePopups(){
	$(".popup").hide();
	$(".popup").removeClass("expanded comments event-photos event-videos event-enlarge pop-add-pic pop-add-link pop-add-event");
	$(".fb-tabbed-nav a").removeClass("sel");
}
