/* Event Booking Pro - WordPress Plugin
 * Get plugin at: http://iplusstd.com/item/eventBookingPro/
 * iPlus Studio
 */




(function($){
	
$(window).resize(function() {

	
	
	$('.eventDisplayCnt').each(function(index, element) {
		
       var newWidth,imNewWidth,innerWidth
		if(parseInt($(this).parent().width(),10)<parseInt($(this).attr('data-init-width'),10)){
			 newWidth= parseInt($(this).parent().width() ,10)- parseInt($(this).css("padding-left"),10)-parseInt($(this).css("padding-right"),10);
			$(this).width(newWidth)
			//$('.calInstance')
			
			
			 imNewWidth=newWidth-(parseInt($(this).find('.eventImage').css("margin-left"),10)+parseInt($(this).find('.eventImage').css("margin-right"),10))
			$(this).find('.eventImage').width(imNewWidth)
			
			$(this).find('.calInstance').width(newWidth)
			innerWidth=newWidth-(parseInt($(this).find('.calInstance .eventContent').css("padding-left"),10)*2+parseInt($(this).find('.calInstance .eventContent').css("margin-right"),10)*2)
			$(this).find('.calInstance .eventContent').width(innerWidth)
			
			imNewWidth=innerWidth-(parseInt($(this).find('.calInstance .eventImage').css("margin-left"),10)+parseInt($(this).find('.calInstance .eventImage').css("margin-right"),10))
			$(this).find('.calInstance .eventImage').width(imNewWidth)
			
			
		}else if( parseInt($(this).attr('data-init-width'),10)!=parseInt($(this).parent().width() ,10)){
			
			var newWidth= parseInt($(this).attr('data-init-width'),10)- parseInt($(this).css("padding-left"),10)-parseInt($(this).css("padding-right"),10);
			$(this).width(newWidth)
			var imNewWidth=newWidth-(parseInt($(this).find('.eventImage').css("margin-left"),10)+parseInt($(this).find('.eventImage').css("margin-right"),10))
			$(this).find('.eventImage').width(imNewWidth)
		}
		
		
		
    });
	
	checkScroller()
});


function checkScroller(){

		$modal= $('.md-show');
		if($modal.height()>($(window).height()-40)){
			if(!$modal.hasClass("mCustomScrollbar") )
				$modal.mCustomScrollbar({set_height:($(window).height()-40)});
			else{
				$modal.height($(window).height()-40);
				$modal.mCustomScrollbar("update");
				
			}
				
		}	
}

function getMapType(mapString){
			 switch(mapString){
				 case "HYBRID":
					return google.maps.MapTypeId.HYBRID
				 	
				case "TERRAIN":
					return google.maps.MapTypeId.TERRAIN
				 
				case "SATELLITE":
					return google.maps.MapTypeId.SATELLITE
				 
				case "ROADMAP":
				default:
					return google.maps.MapTypeId.ROADMAP
				 
			 }
			 
}
function doMap(mapCanvas, address, mapformat, zoomValue, addressType, scrollwheel) {
	if(address=='')
		return;
	mapCanvas.style.display='block';
	var map;
	geocoder = new google.maps.Geocoder();
			
	var latlng = new google.maps.LatLng(-25.363882,131.044922);	
	if(scrollwheel=='false' ){
		var myOptions = {			
			center: latlng,	
			mapTypeId:mapformat,	
			zoom: zoomValue,	
			scrollwheel: false,
		}
	}else{
		var myOptions = {	
			center: latlng,	
			mapTypeId:mapformat,	
			zoom: zoomValue }
	}
	
	
	
	map = new google.maps.Map(mapCanvas, myOptions);
	
	
	// address from latlng
	if(addressType=='latlng'){
		var latlngStr = address.split(",",2);
		var lat = parseFloat(latlngStr[0]);
		var lng = parseFloat(latlngStr[1]);
		var latlng = new google.maps.LatLng(lat, lng);
		
		geocoder.geocode({'latLng': latlng}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
			map.setCenter(results[0].geometry.location);
			var marker = new google.maps.Marker({
				map: map,
				position: latlng
			});
			} else {
				mapCanvas.style.display='none';
			}
		});
		
	}else{
		geocoder.geocode( { 'address': address}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				
				map.setCenter(results[0].geometry.location);
				var marker = new google.maps.Marker({
					map: map,
					position: results[0].geometry.location
				});
				
				
			} else {
				mapCanvas.style.display='none';				
			}
		});
	}
	
	
}


$(document).ready(function(){	
	$(window).resize();
	
	
	//initialize maps
		$(".eventDisplayCnt").not(".isCalendar").find('.map_canvas').each(function(index, element) {
		    var mapType = getMapType($(this).attr("data-maptype"));
			doMap(this,$(this).attr("data-address"),mapType, parseInt($(this).attr("data-zoom"),10),  $(this).attr("data-addressType"), true)
		});
	//buy btn Modal
		
	$(document).on('click', '.md-trigger', function(e) {
		doBuyBtn($(this))	
	});

	
	//do form selects
	$('.md-content form select').each(function(index, element) {
		$(this).dropdownMoe( {
			gutter : 2,
			stack : false,
			slidingIn : 100
		});
	})
	
	//select btn
	$('.md-content .tickets select').each(function(index, element) {
		var $topLevel= $(this).parent().parent().find(".couponDiv");
		var $me=$(this)
		var eventID=$(this).parent().attr("data-id");
		
		$(this).dropdownMoe( {
					gutter : 5,
					stack : false,
					slidingIn : 100,
					onOptionSelect:function($opt){
					
					var ticketID,Dateid;
						if($me.hasClass("ticketType")){
							var cost=$opt.attr("data-cost");
							ticketID =$opt.attr("data-value")
							Dateid=$('.md-show .md-content .tickets input[name="ticketDate'+eventID+'"]').val()
							
							$topLevel.find('input[name="initialCost"]').val(cost)
							calcTotal($topLevel)
							
							
						}else{
							Dateid=$opt.attr("data-value");
							ticketID=$('.md-show .md-content .tickets input[name="ticketType'+eventID+'"]').val();		
        
						}
						
						$(".md-show .md-content .tickets .spotsleft span").text("")
						$.ajax({
							type:'POST', 
							url: $("input[name='ajaxlink']").val()+'/wp-admin/admin-ajax.php', 
							data:'action=check_spots&ticket='+ticketID+'&date_id='+Dateid, 
							success: function(response) {
								$(".md-show .md-content .tickets .spotsleft span").text(response)
								var newTotal=$(".md-show .md-content .single strong").text()
								$(".md-show .md-content .quantityBtns span").html(1)
								$('.md-show .md-content input[name="quantity"]').val(1);
								$('.md-show .md-content .total strong').html(newTotal)
								if(parseInt($(".md-show .md-content .spotsleft span").html())===0){
									$(".md-show .md-content .buy a").each(function(index, element) {
                                        if(!$(this).hasClass("deactive"))
											$(this).addClass("deactive")
                                    });
									
								}
								else if($(".md-show .md-content .spotsleft span").html()!="0"){
									$(".md-show .md-content .buy a").each(function(index, element) {
                                        if($(this).hasClass("deactive"))
											$(this).removeClass("deactive")
                                    });
								}
							}	
						});
					}
		} );
		
		
		
    });
	
				
	$(document).on('click', '.md-modal .quantityBtns a', function(e) {
		
		var newQuantity;
		var $topLevel= $(this).parent().parent()
		if($(this).hasClass("up"))
			newQuantity=parseInt($topLevel.find('.quantityBtns span').html(),10)+1;
		else
			newQuantity=parseInt($topLevel.find('.quantityBtns span').html(),10)-1;
		
		if(newQuantity<1)
			return;
			
		

		if(newQuantity>$topLevel.parent().parent().find('.spotsleft span').html())
			return;
			
		var newTotal=newQuantity*parseFloat($topLevel.find('.single strong').text(),10);
		newTotal=newTotal.toFixed(2).replace(/\.?0+$/, "");
		$topLevel.find('.quantityBtns span').html(newQuantity)
		$topLevel.parent().parent().find('input[name="quantity"]').val(newQuantity);
		
		$topLevel.find('.total strong').html(newTotal)
		 
		 
    });
	
	
	//checking coupon btn
	
	$(document).on('click', '.md-content .coupon.checking', function(e) {
		e.preventDefault();
		var $topLevel= $(this).parent().parent()
		$topLevel.find('span.couponResult').html("checking...");
		var coupon =$topLevel.find('input[name="coupon-code"]').val()
		var id =$topLevel.find('input[name="event-id"]').val()
		
		$.ajax({
					type:'POST', 
					url: $("input[name='ajaxlink']").val()+'/wp-admin/admin-ajax.php', 
					data:'action=check_coupon&code='+coupon+'&event='+id, 
					success: function(response) {
						if(response==="false"){
							$topLevel.find('span.couponResult').attr("data-name","");
							$topLevel.find('span.couponResult').html("Coupon not found or has expired.");
						}
						else{
							$topLevel.find('span.couponResult').html(response);
							$topLevel.find('span.couponResult').attr("data-name",coupon);
							calcTotal($topLevel);
							
						}
						
					}
				});
				
	 });

	
	
	//get images
	$(".eventDisplayCnt").not(".isCalendar").find(".eventImage").each(function(index, element) {
		if($(this).attr("data-image")!="")
		  getImg($(this),$(this).attr("data-image"),$(this).attr("data-image-crop"),$(this).attr("data-image-height"),$(this).attr("data-image-width"),false)
	});


	//get info
	$(".eventDisplayCnt").not(".isCalendar").find(".info").not(".deactive").each(function(index, element) {
	
		if(parseInt($(this).find(".cnt").height())>parseInt($(this).attr("data-height"))){
			
			$(this).css("height",$(this).attr("data-height"))
			$(this).append('<a href="" class="expand">'+$(this).attr("data-expandTxt")+'</a>');
			$(this).find("a.expand").css("width",'100%');
			$(this).find("a.expand").css("color",$(this).css("color"));
		}
		$(this).find("a.expand").click(function(e) {
			e.preventDefault();
			toggleTxtBox($(this).parent());
		});
	
	});




	function doBuyBtn($this){
		
	
		$modal =$( '#' +  $this.attr( 'data-modal' ))
		
		if($modal.height()>($(window).height()-40)){
			if(!$modal.hasClass("mCustomScrollbar") ){
				$modal.mCustomScrollbar({set_height:($(window).height()-40)});
				
			}
			else{
				$modal.height($(window).height()-40);
				$modal.mCustomScrollbar("update");
				
				
			}	
		}
		
		
		$modal.addClass('md-show' );
		if(parseInt($(".md-show .md-content .spotsleft span").html(),10)==0){
			$(".md-show .md-content .buy a").each(function(index, element) {
                    if(!$(this).hasClass("deactive"))
							$(this).addClass("deactive")
		  });	
		}
		setTimeout( function() {
		$('.md-content .offlineloader').hide();
				$(document).addClass( 'md-perspective' );
					}, 25 );	
		
		$(document).on('click', '.md-overlay, .closeBtn a', function(e) {
				e.preventDefault();
				$(".md-show .md-content .offlineloader").html($(".md-show .md-content .offlineloader").attr("data-text"));
				$modal.removeClass('md-show' );
				
				$(document).removeClass( 'md-perspective' );
				
		 });	
	}
	
	function calcTotal($topLevel){
		var quantity=parseInt($topLevel.parent().find('.quantityBtns span').html(),10);
		var initPrice=parseFloat($topLevel.find('input[name="initialCost"]').val(),10);
		var newPrice=$topLevel.find('span.couponResult strong').text()
		if(newPrice.indexOf("%")>-1)
			newPrice=initPrice-parseFloat(newPrice,10)*initPrice/100;
		else
			newPrice=initPrice-newPrice;
			
			newPrice=newPrice.toFixed(2).replace(/\.?0+$/, "");
			
		var newTotal=quantity*newPrice;
		
			newTotal=newTotal.toFixed(2).replace(/\.?0+$/, "");
		
		$topLevel.parent().find('.single strong').html(newPrice)
		$topLevel.parent().find('.total strong').html(newTotal)
		$topLevel.parent().parent().find('input[name="amount"]').val(newPrice);
                if ($topLevel.find('span.couponResult strong').length>0) {
                    var newName=$topLevel.find('input[name="eventName"]').val()+" - coupon: "+$topLevel.find('.col.double span').text();
		    $topLevel.parent().parent().find('input[name="item_name"]').val(newName);	            //code              
                }
		
	}

function checkCalendarScroller(){
	
	$('#eventContent').mCustomScrollbar("update");
}

	function toggleTxtBox($which){
		if($which.hasClass("opened")){
			$which.removeClass("opened")
			
			$which.find("a.expand").html($which.attr("data-expandTxt"))
			TweenMax.to($which, 0.5, {css:{height:$which.attr("data-height")}, ease:Expo.easeOut,onComplete:checkCalendarScroller}); 
		}else{
			$which.addClass("opened")
			$which.find("a.expand").html($which.attr("data-closeTxt"))
			TweenMax.to($which, 0.5, {css:{height:($which.find('.cnt').height()+$which.find("a.expand").height()+5)}, ease:Expo.easeOut,onComplete:checkCalendarScroller}); 
		}
	}
	
	function getImg($where,img,imgCropping,imgSetHeight,imgWidth,anim){
		
							$where.append('<div class="imgHolder"></div>')
							$where.find('.imgHolder').append('<img src="'+img+'" />');
							$where.find('.imgHolder img').css("display","none");
							$where.find('.imgHolder img').load(function(e){
						
						
							if(imgCropping){
								// $where.find('.imgHolder img').width("100%");
								  var imgH=parseInt($where.find(".imgHolder img").height())-imgSetHeight;
								  if(imgH>0){
									
									 $where.find('.imgHolder img').css("display","block");
									 if(anim)
										 TweenMax.fromTo($where.find('.imgHolder'), 0.5, {css:{height:0}}, {css:{height:imgSetHeight}, ease:Expo.easeOut});
									 else
										 $where.find('.imgHolder').height(imgSetHeight);
									 
									 $where.find(".imgHolder img").css("margin-top",-parseInt(imgH/2,10));
									 $where.find('.imgHolder').addClass("expandImg");
									  
									  var imageH=$where.find('.imgHolder').find('img').height()-imgSetHeight;
									 if(anim){
										 TweenMax.to($where.find('.imgHolder').find(' img'), 0.5, {css:{marginTop:-parseInt(imageH/2,10)}, ease:Expo.easeOut});
										 TweenMax.to($where.find('.imgHolder'), 0.5, {css:{height:imgSetHeight}, ease:Expo.easeOut});   
									 }else{
										 $where.find('.imgHolder').find(' img').css("margin-top",-parseInt(imageH/2,10));
										 $where.find('.imgHolder').height(imgSetHeight);
									 }
											  
									 $where.find('.imgHolder.expandImg').click(function(e) {
										 if(parseInt($(this).find('img').css("margin-top"),10)<0){
											TweenMax.to($(this).find('img'), 0.5, {css:{marginTop:0}, ease:Expo.easeOut});
											TweenMax.to($(this), 0.5, {css:{height:$(this).find('img').height()}, ease:Expo.easeOut}); 
										 }else{
											 var imageH=$(this).find('img').height()-imgSetHeight;
											  TweenMax.to($(this).find(' img'), 0.5, {css:{marginTop:-parseInt(imageH/2,10)}, ease:Expo.easeOut});
											  TweenMax.to($(this), 0.5, {css:{height:imgSetHeight}, ease:Expo.easeOut});   
											  
										 }	
										 
									 })	
								  }else{
									 $where.find('.imgHolder img').css("display","block"); 
								}
					  }
	
				  });
		}
		

		

		
				
			  $(document).on('focus',".md-content input,.md-content textarea",function() {
				  if ($(this).val() == $(this)[0].title)
				  {
					  $(this).removeClass("incorrect");
					  $(this).val("");
				  }
			  });
	  
	  
			   $(document).on('blur',".md-content input,.md-content textarea",function() {
				 
				  if ($(this).val() == "")
				  {
					  $(this).removeClass("incorrect");
					  $(this).val($(this)[0].title);
					 
				  }
			  });
	  
	  
	  
		
	 
	$(document).on('click', '.md-content .book', function(e) {

		e.preventDefault();
		  
		if($(this).hasClass("deactive"))
		  	return;
		 
		$(".md-show .md-content .incorrect").each(function(index, element) {
            $(this).removeClass("incorrect");
        }); 
		 
		var isOkay=true;
		var $this=$(this);	
		
		 
		 
		  $(".md-show .md-content .bookInput.isRequired").each(function(index, element) {
			 if ($(this).val() === "" || $(this).val() === $(this)[0].title){				
				isOkay=false
				$(this).addClass("incorrect");
			 }
			 
			  if($(this).hasClass("email") && !validateEmail($(this).val())){
				isOkay=false
				$(this).addClass("incorrect"); 
			  }
			  
			 
			  
   		 });
		 
		
		 if(!isOkay)
		 	return false
		else{
			$(".md-show .md-content .bookInput").not(".isRequired").each(function(index, element) {
				 if ($(this)[0].title==$(this).val())
					 	$(this).val("");
			 });
			 
				$(".md-show .md-content a.book").each(function(index, element) {
                    $(this).addClass("deactive")
                });
				
				var eventID=$(".md-show .md-content input[name='eventID'] ").val()
				var ticket=$('.md-show .md-content .tickets input[name="ticketType'+eventID+'"]').val();
				
				var dateid=$('.md-show .md-content .tickets input[name="ticketDate'+eventID+'"]').val()
				
				var coupon=$(".md-show .md-content .couponResult").attr("data-name")
				if(coupon == null)
					coupon='';
				var amount=	$(".md-show .md-content .col.total span strong").text()
		
				var eventName = $(".md-show .md-content .title").text()
		 		checkScroller()
				$(".md-show .md-content .offlineloader").html($(".md-show .md-content .offlineloader").attr("data-text"));
				if($('.md-show.mCustomScrollbar').length>0){
					$('.md-show').mCustomScrollbar("update");
					$('.md-show').mCustomScrollbar("scrollTo","bottom");
					$('.md-show .md-content .offlineloader').show();
				}else{
					$('.md-show .md-content .offlineloader').show(200);	
				}
				
				var bookingType="offlineBooking";
				var extra="";
				if($(this).hasClass("paypal"))
					bookingType="offlineBookingPayPal";
				
				
				var formInputes=""
				$('.md-show .md-content form input[type="text"]').each(function(index, element) {
					if($(this).attr("name") !="bookName"  && $(this).attr("name") !="bookEmail")
						formInputes+=$(this).attr("name").replace(/:/g , "")+": "+$(this).val()+"%";
				});
				
					
				$(".md-show .md-content form textarea").each(function(index, element) {
					formInputes+=$(this).attr("name").replace(/:/g , "")+": "+$(this).val()+"%";
				});
				$('.md-show .md-content form .cd-dropdown').each(function(index, element) {
					formInputes+=$(this).find("input").attr("name").replace(/:/g , "")+": "+$(this).find("input").val()+"%";
				});
				$('.md-show .md-content form input[type="radio"]').each(function(index, element) {
					if($(this).is(':checked'))
					formInputes+=$(this).attr("name").replace(/:/g , "")+": "+$(this).val()+"%";
				});
				
				$('.md-show .md-content form .hasCheckBoxes').each(function(index, element) {
					formInputes+=$(this).attr("data-name").replace(/:/g , "")+": ";
					$(this).find('input[type="checkbox"]').each(function(index, element) {
						if($(this).is(':checked'))
							formInputes+=$(this).val()+", ";
					});
				});
			
				
				formInputes='&formStuff='+encodeURIComponent(formInputes);
				
				var currentPage='$currentPage='+document.URL;
				$.ajax({
					type:'POST', 
					url: $("input[name='ajaxlink']").val()+'/wp-admin/admin-ajax.php', 
					data:'action='+bookingType+'&coupon='+coupon+'&dateid='+ dateid+'&ticket='+ ticket+'&eventid='+ eventID+'&quantity='+$(".md-show .md-content .quantityBtns span").html()+'&amount='+amount+"&eventName="+eventName+extra+formInputes+'&bookName='+ $(".md-show .md-content #bookName").val()+'&bookEmail='+$(".md-show .md-content #bookEmail").val()+currentPage, 
					success: function(response) {
						
						if(bookingType=="offlineBookingPayPal"){
							 $(response).appendTo('body').submit();
						
						}else if(bookingType=="offlineBooking"){
							$(".md-show .md-content a.book").each(function(index, element) {
								$(this).removeClass("deactive")
							});
							
							$(".md-show .md-content input").each(function(index, element) {
                                $(this).val($(this).attr("title"));
                            });
							
							$(".md-show .md-content .offlineloader").html($(".md-show .md-content .offlineloader").attr("data-text2"));
						}
					}
				});
			}
   	 });
	  
	  
	  function validateEmail(email) { 
	   var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
		return re.test(email);
			} 
	
	
	
	
	
	var
					$wrapper = $( '#custom-inner' ),
					$calendar = $( '.fc-calendar-container' ),
					id
					EB_Events = {};
					
					$calendar.find(".eventlist li").each(function(index, element) {
						id=$(this).attr("data-date");
						if(EB_Events[id]==undefined)
							EB_Events[id]=""
                        EB_Events[id]+=$(this).html();
                    });
					$calendar.find(".eventlist").remove();
					
					cal = $calendar.calendario( {
						onDayClick : function( $el, $element_content, dateProperties ) {

							if( $element_content.length > 0 ) {
								showEvents( $element_content, dateProperties );
							}

						},
						caldata : EB_Events,
						displayWeekAbbr : $calendar.attr("data-displayWeekAbbr"),
						displayMonthAbbr : ($calendar.attr("data-displayMonthAbbr")==="true"),
						startIn : parseInt($calendar.attr("data-startIn")),
					} );
					
				if(cal){
					$month = $( '#custom-month' ).html( cal.getMonthName() ),
					$year = $( '#custom-year' ).html( cal.getYear() );
				}

				$( '#custom-next' ).on( 'click', function() {
					cal.gotoNextMonth( updateMonthYear );
					updateTitles()
				} );
				$( '#custom-prev' ).on( 'click', function() {
					cal.gotoPreviousMonth( updateMonthYear );
					updateTitles()
				} );

				function updateMonthYear() {				
					$month.html( cal.getMonthName() );
					$year.html( cal.getYear() );
				}
				
				function updateTitles(){
					$(".fc-content").each(function(index, element) {
						$(this).attr("title", $(this).find(".eb_frontend .name").html());
					});
				}
				updateTitles()

				function showEvents( $element_content, dateProperties ) {
					$opt=$('<div class="opt" style="display:none">'+$element_content.html()+'</div>')
					var $eventHolder = $( '<div id="eventContent" class="eventContent"></div>' ),
						$events = $( '<div class="calanderCnt"></div>' ),
						$close = $( '<span class="eventClose"></span>' );
					
					$events.append( $element_content.html() , $close )
					$eventHolder.append($events).insertAfter( $wrapper );

					$('#eventContent h3.title').each(function(index, element) {
						$(this).before('<h4 style="margin-bottom:0px;">'+$(this).text()+'</h4>');
						$(this).remove();
					});
					
                      if(!$('#eventContent').hasClass("mCustomScrollbar"))
							$('#eventContent').mCustomScrollbar();
					  else
                    	$('#eventContent').mCustomScrollbar("update");
					
					$("#eventContent .info").each(function(index, element) {
	
						if(parseInt($(this).find(".cnt").height())>parseInt($(this).attr("data-height"))){
							
							$(this).css("height",$(this).attr("data-height"))
							$(this).append('<a href="" class="expand">'+$(this).attr("data-expandTxt")+'</a>');
							$(this).find("a.expand").css("width",$(this).width());
							$(this).find("a.expand").css("color",$(this).css("color"));
						}
					})

					$('#eventContent .info').find("a.expand").click(function(e) {
						e.preventDefault();
						toggleTxtBox($(this).parent());
					});
				
					
						
					if($("#eventContent .eventImage").attr("data-image")!=""){
						 $("#eventContent .eventImage .imgHolder").remove();
						  getImg($("#eventContent .eventImage"),$("#eventContent .eventImage").attr("data-image"),$("#eventContent .eventImage").attr("data-image-crop"),$("#eventContent .eventImage").attr("data-image-height"),$("#eventContent .eventImage").attr("data-image-width"),false)
					 
					}

					TweenMax.fromTo($( '#eventContent' ), 0.5, {css:{top:"100%"}}, {css:{top:0,opacity:1}, ease:"Expo.easeOut",onComplete:calElemOpened,delay:0.2});
					
					$('.eventClose').click(function(e) {
                    
					    TweenMax.to($('.eventContent'), 0.5, {css:{top:"100%",opacity:0}, ease:"Expo.easeOut",onComplete:removeElem});
					
                    });

				}

				function calElemOpened(){
					
					  $('#eventContent .map_canvas').each(function(index, element) {
			  
						var mapType = getMapType($(this).attr("data-maptype"));
					  
						doMap(this,$(this).attr("data-address"),mapType, parseInt($(this).attr("data-zoom"),10),  $(this).attr("data-addressType"), true)
						$('#eventContent').mCustomScrollbar("update");
					});
				}
				
				function removeElem(){
					$('.eventContent').remove();
				}
				
				
				
		
	})
})(jQuery)

// JavaScript Document