jQuery.noConflict();
jQuery(document).ready(function($){
		   
	jQuery(".date-picker").datepicker({ 
					duration: "", 
					showOn: "both",
					//beforeShow: setDatePicker,
					hideIfNoPrevNext: true,
					buttonImage: "images/icon-cal.gif", 
					buttonImageOnly: true 
	});

	var openFn=function(hash){
		hash.w.show();
		var difference = $(window).width() - $('#webcam-viewer').width();
		difference = difference / 2;
		$('#webcam-viewer').css({left:difference+275,top:$(window).scrollTop()+10});
	};
	var hideFn=function(hash){
		hash.w.hide()
		hash.o.remove();
	};
	
	$('#webcam-viewer').jqm({trigger:'.webcam-viewer-click'});
	
	
	
		$('.share-link').initializeSharing();
	
		// Wifi sifr
		/*$('body.wifi #current-temp').sifr(
			{ strSWF: 'flash/arial.swf', strColor: '#4b461e', strLinkColor: '#cccc00', strHoverColor: '#cc00cc', strWmode: 'transparent', intPadding: [0, 26, 54, 0] },
			{ expressInstall: true }
		);
		$('body.wifi #weather-box #weather-image p').sifr(
			{ strSWF: 'flash/arial.swf', strColor: '#4b461e', strLinkColor: '#cccc00', strHoverColor: '#cc00cc', strWmode: 'transparent', strFlashVars: 'textalign=center&' },
			{ expressInstall: true }
		);*/

	
	
		// Wifi tabs
	$("#mcc-nav").each(function(){
		var mccNav = $(this);
		$("li#mcc-events a",mccNav).click(function(e){
			e.preventDefault();
			$("#wifi-mcc-content #events-wrapper").html('').html('<p id="loading"><img src="images/ajax-loader.gif" alt="loading..." border="0" width="16" height="16" /></p>');
			$.get('wifi-events.php', function(data){
				if ( $('#events-wrapper').length == 0 ) {
					$('#wifi-mcc-content').empty()
					$('#wifi-mcc-content').append( $('<div id="events-wrapper"></div>') )
				}
				$("#wifi-mcc-content #events-wrapper").html(data);
				$('.share-link').initializeSharing();
			});
			$("#mcc-nav li a").removeClass("current");
			$(this).addClass("current");
		});

		$("li#mcc-offers a",mccNav).click(function(e){
			e.preventDefault();
			$("#wifi-mcc-content").html('').html('<p id="loading"><img src="images/ajax-loader.gif" alt="loading..." border="0" width="16" height="16" /></p>');
			$.get('wifi-offers.php', function(data){
				$("#wifi-mcc-content").html(data);
				$('.package').packagePreview();
				$('.share-link').initializeSharing();
			});
			$("#mcc-nav li a").removeClass("current");
			$(this).addClass("current");		
		});

		// Google search on wifi page
		$("#google-search #q").click(function(){
			$(this).attr('value','');
		});

	});
	
	
	$('li.event a.event-details').bind("click", function() {
		var el = $(this);
		if ( !($(el).hasClass('active')) ) {
			$.get('/includes/events-calendar-details.php', { event_id:$(this).attr('id') },function(data) { 
				$(el).html('Hide Details').addClass('active').parent().children('.event-description').hide().html(data).slideDown('slow');
			});
			return false;								   
		} else {
			var el = this;
			$(el).html('View Details').removeClass('active').parent().children('.event-description').slideUp('slow', function() { 
				$(this).html(''); 
			});
			return false;								   
		}
		return false;		
	 });


	
	
	
});

function validate( frm ) {
	var returnValue = false;
	if(frm.id=="tournament-request"){
		if ( BlankField( frm.first_name.value ) ) {
			alert ( "Please enter your first name." );
			frm.first_name.focus();
		
		} else if ( BlankField( frm.last_name.value ) ) {
			alert ( "Please enter your last name." );
			frm.last_name.focus();
	
		}else if ( BlankField( frm.zip.value ) ) {
			alert ( "Please enter your zip code." );
			frm.phone.focus();
	
		} else if ( !ValidEmail( frm.email.value ) ) {
			alert ( "Please enter a valid email address." );
			frm.email.focus();
	
		} else if ( document.getElementById('amenities-other').checked==true && BlankField(frm.amenities_other.value)) {
			alert ( "Please enter a value for other amenities." );
			frm.email.focus();
	
		}else if ( BlankField( frm.the_word.value ) ) {
			alert ( "Please enter the word you see in the picture." );
			frm.email.focus();
	
		}  else {
			returnValue = true;
			document.getElementById( "submit" ).disabled = "true";
		}
	}else{
		if ( BlankField( frm.first_name.value ) ) {
			alert ( "Please enter your first name." );
			frm.first_name.focus();
		
		} else if ( BlankField( frm.last_name.value ) ) {
			alert ( "Please enter your last name." );
			frm.last_name.focus();
	
		} else if ( !ValidEmail( frm.email.value ) ) {
			alert ( "Please enter a valid email address." );
			frm.email.focus();
	
		} else if ( BlankField( frm.phone.value ) ) {
			alert ( "Please enter your telephone number." );
			frm.phone.focus();
	
		} else if ( BlankField( frm.number_in_group.value  ) ) {
			alert ( "Please enter the number in your group." );
			frm.number_in_group.focus();
	
		} else if ( BlankField( frm.tee_time_after.value  ) ) {
			alert ( "Please select an after tee time." );
			frm.tee_time_after.focus();
	
		} else if ( BlankField( frm.tee_time_before.value  ) ) {
			alert ( "Please select a before tee time." );
			frm.tee_time_before.focus();
	
		} else if ( BlankField( frm.date.value  ) ) {
			alert ( "Please enter a date." );
			frm.date.focus();
	
		} else {
			returnValue = true;
			document.getElementById( "submit" ).disabled = "true";
		}
	}
	return returnValue;

}


(function($) {


$.fn.packagePreview = function(options) {
	var defaults = {
		hideDetails : '',
		viewDetails : ''
	},
	opts = $.extend(defaults, options);
	return this.each(function() {
		$('.package-details a', this).toggle(function(event) {
			event.preventDefault();
			$('.share-panel').hide();
			var el = $(this);
			$.get('/includes/package-details.php', { package_id: this.id.substr(3), channel: this.rel, lang: 'en' },function(data) { 
				el.html(opts.hideDetails).parent().addClass('active').parent().find('.package-long').hide().html(data).slideDown('slow');
			});
		},function(event) { 
			event.preventDefault();
			$('.share-panel').hide();
			$(this).html(opts.viewDetails).parent().removeClass('active').parent().find('.package-long').slideUp('slow', function() { 
				$(this).html(''); 
			});
		});
	});
};

$.fn.initializeSharing = function() {
		return this.each(function() {
			$('.share-link').click(function(event) {
				event.preventDefault();
				$('.share-panel').hide();
				$(this).parents('.rss-item').find('.share-panel').css('display','inline');
			});
			$('.share-close').click(function(event){
				event.preventDefault();
				$(this).parents('.rss-item').find('.share-panel').slideUp('fast');
			});
		});
	};

})(jQuery);

