jQuery(document).ready(function() {	
	//packages slider
	if (jQuery('#slider').length > 0) {
		jQuery("#slider").easySlider({
			prevId: 'prevBtn',
			prevText: 'Previous',
			nextId: 'nextBtn',	
			nextText: 'Next',
			controlsShow: true,
			controlsBefore: '',
			controlsAfter: '',	
			controlsFade: true,
			firstId: 'firstBtn',
			firstText: 'First',
			firstShow: false,
			lastId: 'lastBtn',	
			lastText: 'Last',
			lastShow: false,				
			vertical: true,
			speed: 1200,
			auto: true,
			pause: 8000,
			continuous: true
		});
	}
	
	//open rel="external" in external window
	jQuery('a[rel="external"]').click( function() {
        window.open(jQuery(this).attr('href'));
        return false;
    });
    
    //create the slug if a slug and title field exist
    if (jQuery('#fldslug').length > 0 && jQuery('#fldtitle').length > 0) {
		jQuery('#fldtitle').bind('keyup', function() {
			var regexed = jQuery.trim(jQuery('#fldtitle').val()).replace(/[^A-Za-z0-9 ]/g, '').replace(/ /g, '-').toLowerCase();
	    	jQuery('#fldslug').val(regexed);
	    });
    }
    
    //open golfpackage things in the correct winder.
    jQuery('.golfPackageLink').click(function() {
    	var theHref = 'https://secure.guestdesk.com/golf/?id=399&siteID=barefootgolfvacations.com&SystemType=3&packageURLID=' + jQuery(this).attr('rel');
		window.open(theHref, 'GolfPackageReservations', 'toolbar=no, scrollbars=auto, location=no, resizable=no, directories=no, status=yes, menubar=no, width=790, height=450, screenX=1, screenY=1, top=1, left=1');
		return false;
    });
	//open top deal things in the correct winder
	jQuery('.topDealsLink').click(function() {
    	var theHref = 'https://secure.guestdesk.com/golf/?id=399&siteID=barefootgolfvacations.com&SystemType=3&packageURLID=' + jQuery(this).attr('rel');
		window.open(theHref, 'GolfPackageReservations', 'toolbar=no, scrollbars=auto, location=no, resizable=no, directories=no, status=yes, menubar=no, width=790, height=450, screenX=1, screenY=1, top=1, left=1');
		return false;
    });
    //open golf link system window
    jQuery('.golfLink').click(function() {
    	var theHref = 'https://secure.guestdesk.com/golf/?id=399&siteID=barefootgolfvacations.com&SystemType=3';
		window.open(theHref, 'GolfPackageReservations', 'toolbar=no, scrollbars=auto, location=no, resizable=no, directories=no, status=yes, menubar=no, width=790, height=450, screenX=1, screenY=1, top=1, left=1');
		return false;
    });
    //open tee times system
    jQuery('.teeTimeLink').click(function() {
    	var theHref = 'https://secure.guestdesk.com/teetimes/?UID=58&siteID=13&PID=460&ShowRedLine=0';
    	if (jQuery(this).attr('rel').length > 0)
    		theHref += '&urlCourseID=' + jQuery(this).attr('rel');
		window.open(theHref, 'GolfPackageReservations', 'toolbar=no, scrollbars=auto, location=no, resizable=no, directories=no, status=yes, menubar=no, width=790, height=450, screenX=1, screenY=1, top=1, left=1');
		return false;
	});
    
    //make the AED "table" rows light up
    if (jQuery('ul#item_list').length > 0) {
    	jQuery('ul#item_list li').hover(function() {
    		jQuery(this).addClass('hover');
    	}, function() {
    		jQuery(this).removeClass('hover');
    	});
    }
    
    //photogallery
    if ($('.galleryThumbs').length > 0 && $('.photoMain').length > 0) {
    	$('.galleryThumbs li a').click(function() {
    		var el = $(this);
    		var id = el.attr('rel');
    		var caption = el.children(':first').attr('alt');
    		$('.galleryThumbs li a').removeClass('selected');
    		el.attr('class', 'selected');
    		$('.photoMain img').removeClass('show');
    		$('#photo' + id).addClass('show');
    		$('#caption').html(caption);
    		return false;
    	});
    }
    
    //course photogallery
    if ($('.galleryThumbs').length > 0 && $('.photoCourseMain').length > 0) {
    	$('.galleryThumbs li a').click(function() {
    		var el = $(this);
    		var id = el.attr('rel');
    		var caption = el.children(':first').attr('alt');
    		$('.galleryThumbs li a').removeClass('selected');
    		el.attr('class', 'selected');
    		$('.photoCourseMain img').removeClass('show');
    		$('#photo' + id).addClass('show');
    		$('#caption').html(caption);
    		return false;
    	});
    }
    
    //show/hide the form stuff on the homepage
    if ($('#edealsEmail').length > 0) {
    	$('#edealsEmail').focus(function() {
    		if ($(this).val() == 'example@example.com') {
    			$(this).val('');
    		}
    	});
    	$('#edealsEmail').blur(function(){
    		if ($(this).val().length < 1) {
    			$(this).val('example@example.com');
    		}
    	});
    }
    if ($('#drawingEmail').length > 0) {
    	$('#drawingEmail').focus(function() {
    		if ($(this).val() == 'example@example.com') {
    			$(this).val('');
    		}
    	});
    	$('#drawingEmail').blur(function(){
    		if ($(this).val().length < 1) {
    			$(this).val('example@example.com');
    		}
    	});
    }
    if ($('#edealsZip').length > 0) {
    	$('#edealsZip').focus(function() {
    		if ($(this).val() == 'zip code') {
    			$(this).val('');
    		}
    	});
    	$('#edealsZip').blur(function(){
    		if ($(this).val().length < 1) {
    			$(this).val('zip code');
    		}
    	});
    }
    if ($('#drawingZip').length > 0) {
    	$('#drawingZip').focus(function() {
    		if ($(this).val() == 'zip code') {
    			$(this).val('');
    		}
    	});
    	$('#drawingZip').blur(function(){
    		if ($(this).val().length < 1) {
    			$(this).val('zip code');
    		}
    	});
    }
    
	//Omniture
	$('.topDealsLink').click(function() {
			s=s_gi(s_account);
			s.linkTrackVars="events,prop6";
			s.linkTrackEvents = "event2";
			s.events = "event2";
			s.prop6 = $(this).html();
			s.prop6 = s.prop6.toLowerCase();
			s.tl(this,'o','Top Deals Click');		 
		});
	
	$('.golfPackageLink').click(function() {
			s=s_gi(s_account);
			s.linkTrackVars="events,prop7,eVar3";
			s.linkTrackEvents = "event10";
			s.events = "event10";
			relID =  $(this).attr('rel');
			s.prop7 = $('#golfPack'+relID).children('h3').html();
			s.prop7 = s.prop7.toLowerCase();
			s.eVar3 = s.prop7;
			s.tl(this,'o','Book Now Packages');		 
		});
	
	$('.teeTimeLink').click(function() {
			s=s_gi(s_account);
			s.linkTrackVars="events,prop8,eVar5";
			s.linkTrackEvents = "event12";
			s.events = "event12";
			relID =  $(this).attr('rel');
			s.prop8 = $('#teeTime'+relID).children('h2').html();
			s.prop8 = s.prop8.toLowerCase();
			s.eVar5 = s.prop8;
			s.tl(this,'o','Book Now Tee Times');		 
		});
	
	$('.viewPackages').click(function() {
			s=s_gi(s_account);
			s.linkTrackVars="prop9,eVar4";
			relID =  $(this).attr('rel');
			s.prop9 = $('#viewPackages'+relID).children('h3').html();
			s.prop9 = s.prop9.toLowerCase();
			s.eVar4 = s.prop9;
			s.tl(this,'o','View Packages');		 
		});
	
	$('.realEstate').click(function() {
			s=s_gi(s_account);
			s.linkTrackVars="events,prop10,eVar6";
			s.linkTrackEvents = "event13";
			s.events = "event13";
			s.prop10 = $(this).attr('rel');
			s.prop10 = s.prop10.toLowerCase();
			s.eVar6 = s.prop10;
			s.tl(this,'o','View Packages');		 
		});
    /*load the swf for the image rotate in the header
    if (jQuery('mastheadImg').length > 0) {
	    var so = new SWFObject("/media/scalingSlideshow.swf", "scalingSlideshow", "960", "269", "8", "##000000");
	    so.addVariable("imagePath", "/media/layout/mastheads");
	    so.addVariable("imageList", "1.jpg,2.jpg,3.jpg,5.jpg,6.jpg,7.jpg,8.jpg,9.jpg,10.jpg,11.jpg,12.jpg");
	    so.addVariable("skipFirstPic", "false");
	    so.addParam("wmode", "transparent");
	    so.write("mastheadImg");
	}*/
});