(function($) {
	$(document).ready(function() {
		// Detect Submenu and Adds the hasMenu class to its parent <li>				
		$('.submenu').parent().addClass(' hasMenu');
		
		// Sets the width of the submenu
		$('.submenu').each(function() {
			var totalWidth = 0;
			$(this).children('ul').each(function() {
				totalWidth += $(this).outerWidth();
			});
			$(this).width(totalWidth + ( 20 * $(this).children('ul').size()) ).hide();
		});
		
		// Submenu drop down effect
		$('.hasMenu').hover(function() {
			$(this).children('a').addClass(' active');
			$(this).children('.submenu').slideDown('fast');
		}, function() {
			$(this).children('a').removeClass(' active');
			$(this).children('.submenu').slideUp('fast');
		});
		
		// Initialize Carousels
		if ( $('#mainCarousel').length ) { 
			$('#mainCarousel').cycle({
				fx:			'scrollLeft',
				timeout:	5000,
				start:      1,
				pause:      1,
				next: 		'#mainCarouselNext',
				prev:		'#mainCarouselPrev'
			});
		}
		
		if ( $('.carousel ul').length ) { 
			$('.carousel ul').jcarousel({
				wrap: 'circular',
				scroll: 1,
				animation: 'normal'
			});
		}
		
		// Initialize Carousels
		if ( $('#innerCarousel').length ) { 
			 $('#innerCarousel').cycle({
				fx:			'scrollLeft',
				timeout:	5000,
				start:      1,
				next: 		'#innerCarouselNext',
				prev:		'#innerCarouselPrev'
			});
		}
		
		// Initialize Carousels
		if ( $('#eventCarousel').length ) { 
			var startSlide = window.location.search.substring(1)-1;
			 $('#eventCarousel').cycle({
				fx:			'scrollLeft',
				timeout:	0,
				startingSlide: startSlide,
				next: 		'#eventCarouselNext',
				prev:		'#eventCarouselPrev',
				after:		function(currSlideElement, nextSlideElement, options, forwardFlag) {
					var newHeight = $(nextSlideElement).children('.eventCarouselBg').first('div').outerHeight(true) + 10;
					$(nextSlideElement).css('height', newHeight + 'px').parent().css('height', newHeight + 'px');
				}
			});
			
			/*var newHeight = $('#eventCarousel .slide').children('.eventCarouselBg').first('div').outerHeight(true) + 30;
			$('#eventCarousel').css('height', newHeight + 'px').first('slide').css('height', newHeight + 'px');*/
		}

		// Initialize Home Page Slider
		if ( $('#mcs_container').length ) { 
			$("#mcs_container").mCustomScrollbar("horizontal",500,"easeOutCirc",1,"fixed","no","yes",20);
			resizeElements();
			
			$(window).resize(function() {
				resizeElements();
			});
			
			$('#mcs_container .textOverlay').each(function() {
				if ( $(this).children('p').size() > 0 ) { 
					var newHeight = $(this).children('p').outerHeight('true') * $(this).children('p').size() + 5;
					$(this).css('bottom', '-' + newHeight + 'px');
				}
			}).hover(function() {
				$(this).animate({ 'bottom': -5 });
			}, function() {
				if ( $(this).children('p').size() > 0 ) { 
					var newHeight = $(this).children('p').outerHeight('true') * $(this).children('p').size() + 5;
					$(this).animate({ 'bottom': -newHeight }); 
				}
			});
		}

		// Initialize gallery
		if ( $('.ad-gallery').length ) { 
			 var galleries = $('.ad-gallery').adGallery();
		}
		
		// align center
		var element = $('.redPointer');
		$(".ad-thumb-list li").width();
		element.css('margin','0px auto');
		element.css('width', $(".ad-thumb-list li").width() );
        
        // Red Pointer
        $('.redPointer').eq(0).css('display','block');
        $('.ad-thumb-list a').click(function(){
            $('.redPointer').css('display','none');
            var id = $(this).attr('rel');
            $('.redPointer').eq(id).css('display','block');
        });

		
		// Hide and show overlay div
		$('.videoHover').hover(function(){
			$(this).children('.overlayVideo').hide();
		}, function() {
			$(this).children('.overlayVideo').show();
		});
		
		// Initialize Page Overlay and Video Box
		$('.pageOverlay').hide().height( $(document).height() );
		var xPos = ( $(window).width() - $('.videoBox').width() ) / 2;
		var yPos = ( $(window).height() - $('.videoBox').height() ) / 2;
		$('.videoBox').hide().css({ 'left':xPos + 'px', 'top':yPos + 'px' });

		// Initialize Video Links and Link them with the Video Box 
		/*$('.videoHover, .videoHover a').click(function() {
			var currentSlide = $(this).children('a').attr('rel');*/
		
		$('.videoHover a').click(function() {
			var currentSlide = $(this).attr('rel');
			$('#videosCarousel').cycle({
				fx:			'scrollLeft',
				timeout:	0,
				next: 		'#videoBoxNext',
				prev:		'#videoBoxPrev',
				startingSlide:	currentSlide
			});
			
			$('.pageOverlay').show();
			$('.videoBox').show();
			return false;
		});
		
		// Functionality for Video Box Close Button 
		$('.videoBoxContent a#closeButton').click(function() {
			$('.videoBox').hide();
			$('.pageOverlay').hide();
			$('#videosCarousel').cycle('destroy');
			return false;
		});
		
		// Hide and show overlay div
		$('.imageDisplay').hover(function() {
			$(this).children('.overlayImage').show();
		}, function() {
			$(this).children('.overlayImage').hide();
		});
		
		// Hide and show help filter
		$('.helpIcon').hover(function(){
			$('a.helpFilter').show();
		});
		
		$('.helpIcon').hover(function() {}, function() {
			$('a.helpFilter').hide();
		});

		$("div.textOverlay").click(function() {	
			window.location = $(this).attr("url");
		});
		
		$("div.overlayImage").click(function() {	
			window.location = $(this).attr("url");
		});
		
		$("div.disable").click(function() {	
			window.location = $(this).attr("url");
		});
		
		/*$("div.rollOver").click(function() {	
			window.location = $(this).attr("url");
		});*/
		
		// google map expand and collapse 
		$('.collapse').hide();
		$('.expand').click(function() {
			
			lat = $('#lat').html();
			lang = $('#lang').html();
			heading = $('#heading').html();  
			address = $('#address').html();    
			
			$('#map').animate({width:'970px'}, function() { initializemarker(lat,lang,heading,address); });
			$('.expand').hide();
			$('.collapse').show();
		});
		
		$('.collapse').click(function() {
			lat = $('#lat').html();
			lang = $('#lang').html();  
			
			$('#map').animate({width:'180px'}, function() { initialize(lat,lang); });
			$('.collapse').hide();
			$('.expand').each(function() {
				if ( $(this).attr('id') != 'overlayMap' ) { 
					$(this).show();
				}
			});
		});
		
		$('#map').hover(function() {
			if ( $('.collapse').css('display') == 'none' ) { 
				$('#overlayMap').show();
			}
		});
		
		$('#overlayMap').hover(function() {}, function() {
			$(this).hide();
		});
		
		if( $('#datepicker').length ){
            var dates = $( "#datepicker, #datepickerTo" ).datepicker({
			    defaultDate: "+1w",
			    showOn: "both",
			    buttonImage: "assets/images/calender-icon.jpg",
			    buttonImageOnly: true,
			    changeMonth: false,
                dateFormat: 'yy-mm-dd',
			    numberOfMonths: 2,                
			    onSelect: function( selectedDate ) {
				    var option = this.id == "datepicker" ? "minDate" : "maxDate",
					    instance = $( this ).data( "datepicker" ),
					    date = $.datepicker.parseDate(
						    instance.settings.dateFormat ||
						    $.datepicker._defaults.dateFormat,
						    selectedDate, instance.settings );
				    dates.not( this ).datepicker( "option", option, date );
			    }                
		    });
        }
		
		// Disable all # links 
        $('a[href="#"]').click(function() { return false; });
		
	});
})(jQuery);

function resizeElements() {
	(function($) {
		var screenCenterX = ( $(document).width() - $('.dragger_container').outerWidth() ) / 2;
		$('.dragger_container').css('left', screenCenterX + 'px');
		
		if ( $('.horWrapper').outerWidth() < $(document).width() ) { 
			var screenCenterX = ( $(document).width() - $('.horWrapper').outerWidth() ) / 2;
		}
		else { 
			var screenCenterX = 0;
		}

		$('.horWrapper').css('left', screenCenterX + 'px');
	})(jQuery);
}

	// google map initialize 
	function initialize(lat,lang) {
			
			var myLatlng = new google.maps.LatLng(lat,lang);
			
			//var myLatlng = new google.maps.LatLng(39.993726,-83.005925);

			var myOptions = {
			  zoom: 15,
			  center: myLatlng,
			  mapTypeId: google.maps.MapTypeId.ROADMAP
			}
			var map = new google.maps.Map(document.getElementById("map"), myOptions);
			var image = 'assets/images/map-icon.png';
			var marker = new google.maps.Marker({
				position: myLatlng,
				map: map,
				icon: image
			});
			//google.maps.event.addListener(marker, 'load', function() {
			  //infowindow.open(map,marker);
			//});	
	  }
  
	// google map initialize 
	function initializemarker(lat,lang,heading,address) {
		var myLatlng = new google.maps.LatLng(lat,lang);
		var myOptions = {
		  zoom: 15,
		  center: myLatlng,
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		}
		var map = new google.maps.Map(document.getElementById("map"), myOptions);

		var image = 'assets/images/map-icon.png';
		var marker = new google.maps.Marker({
		 map: map,
		 icon: image,
		 title:"Uluru (Ayers Rock)",
		 position: new google.maps.LatLng(lat,lang),
		});
	
		var boxText = document.createElement("div");
		boxText.style.cssText = " margin-top: 8px; background:url(assets/images/map-window.png) no-repeat 0px 0px scroll; padding: 15px 95px 15px 15px; width:300px; height:259px;";
		boxText.innerHTML = '<div id="content">'+
				'<div id="siteNotice">'+
				'</div>'+
				'<h1 id="firstHeading" class="firstHeading">'+heading+'</h1>'+
				'<div id="bodyContent">'+address+
				'</div>'+
				'</div>';
				
		var myOptions = {
				 content: boxText
				,disableAutoPan: false
				,maxWidth: 0
				,pixelOffset: new google.maps.Size(-168 , -300)
				,zIndex: null
				,boxStyle: { 
				  
				  width: "325px"
				 }
				,closeBoxMargin: "20px 20px 0px 0px"
				,closeBoxURL: "assets/images/Bubble-Close.gif"
				,infoBoxClearance: new google.maps.Size(1, 1)
				,isHidden: false
				,pane: "floatPane"
				,enableEventPropagation: false
		};
		
		google.maps.event.addListener(marker, "click", function (e) {
				ib.open(map, this);
			});
	
		var ib = new InfoBox(myOptions);
		ib.open(map, marker);
	}

