var myhandle=null;

var getRandomCourse = function() {
	var imagePrefix = "http://www.waccamawgolftrail.com/media/coursemini/";
	var linkPrefix = "http://www.waccamawgolftrail.com/courses/"
	var courses = "{ 'names' : [ 'Blackmoor' , 'Caledonia' , 'Founders Club', 'Heritage Club', 'Litchfield Country Club', 'Pawleys Plantation', 'River Club', 'Wachesaw Plantation East', 'Willbrook Plantation' ], 'images' : [ 'blackmoor.jpg', 'caledonia.jpg', 'founders-club.jpg', 'heritage-club.jpg', 'litchfield.jpg', 'pawleys.jpg', 'river-club.jpg', 'wachesaw-east.jpg', 'willbrook.jpg' ], 'description' : [ 'Few golfers are as passionate for the game as Gary Player, one of only four golfers to win all four majors.', 'Built upon the site of a southern rice plantation, Caledonia has been widely recognized for its superb design...', 'Construction of the new Founders Club is well underway with a target completion date of 2007.', 'A day at The Heritage Club is a trip back in time. Built on two historic South Carolina plantations...', 'The gracious charms of this country club are enjoyed by a private membership and a limited number of visiting golfers.', 'This Jack Nicklaus signature design is a player&#39;s course that demands strategy, ingenuity and concentration.', 'The semi-private River Club at Litchfield is one of the highest rated courses on the Grand Strand', 'Carved from the gently rolling terrain of a former rice plantation, this Clyde Johnston design possesses...', 'Celebrated course designer Dan Maples has called Willbrook Plantation &quot;One of my best!&quot;' ], 'link' : [ 'blackmoor/', 'caledonia/' , 'founders-club/', 'heritage-club/', 'litchfield-country-club/', 'pawleys-plantation/', 'river-club/', 'wachesaw-plantation-east/', 'willbook-plantation/'] }";

	var ran_number = Math.floor(Math.random()*9);
	var courseJson = eval('(' + courses + ')');
	$('rotatingCourse').innerHTML = "<a href=\"" + linkPrefix + courseJson['link'][ran_number] + "\"><img src=\"" + imagePrefix + courseJson['images'][ran_number] + "\" alt=\"" + courseJson['names'][ran_number] + "\" width=\"198\" height=\"150\" /></a><h2>" + courseJson['names'][ran_number] + "</h2><p>" + courseJson['description'][ran_number] + " <a href=\"" + linkPrefix + courseJson['link'][ran_number] + "\">more...</a></p>";
}

var checkWindow = function(UID,SiteID,PID,RedLine) {
	// This function is used to close any open tee time windows, then open a new window for the tee time app to prevent application var problems
	if(myhandle && !(myhandle.closed)) {
		myhandle.close();
		openWindow(UID,SiteID,PID,RedLine);
	} 
	else {
		openWindow(UID,SiteID,PID,RedLine);
	}
}

var openWindow = function(UID,SiteID,PID,RedLine) {
	myhandle=window.open('https://secure.guestdesk.com/teetimes/?UID='+UID+'&SiteID='+SiteID+'&PID='+PID+'&ShowRedLine='+RedLine,'windowName','toolbar=no,scrollbars=no,location=no,resizable=no,directories=no,status=yes,menubar=no,width=800,height=505,titlebar=TeeTimes,left=2,top=2');
}