jQuery.noConflict();
try{
		jQuery(document).ready(function(){
		
			var courseDetailsRotateTimeout=20000;
					
			if(jQuery().fancybox){ //namespace check
				jQuery("#mod_pukkaPictures div.gallery div.pictures div.picture a, a[rel*=lightbox]").fancybox({ 
					'zoomSpeedIn': 500,
					'zoomSpeedOut': 500,
					'zoomOpacity':true
				});
			}
			
			/*
				Hole Viewer
			*/
			
			/* <p class="prev"><span>Previous</span></p>
			<p class="next"><span>Next</span></p> */
			
			//create previous and next buttons
			var prevBtn=jQuery('<p class="prev"><span>Previous</span></p>');
			var nextBtn=jQuery('<p class="next"><span>Next</span></p>');
			
			//append these to the relevant container
			jQuery("#main-visual-rotator").append(prevBtn);
			jQuery("#main-visual-rotator").append(nextBtn);
			
			//hide stuff that needs to be hidden because we are going to show only one item at a time
			jQuery("#page_details .hole:not(:first),#page_details #content .illustration,#page_details #content .image,#page_details #content .heading").hide();
			
			/*wrap all banner images inside the main-visual with a div so that other elements do not get effected with transitions*/
			jQuery("#main-visual img").wrapAll('<div id="image-wrapper"></div>');
			
			jQuery("#image-wrapper").css({
				"position":"relative",
				"width":972,
				"height":347,
				"overflow":"hidden"
			});
			
			/*assign styles to the main-visual images and the course-illustrations images*/
			jQuery("#main-visual img:not(:first),#course-illustrations img:not(:first)").css({
				"display":"none",
				"position":"absolute",
				"top":0,
				"left":0,
				"z-index":1
			})
			jQuery("#main-visual img:first,#course-illustrations img:first").css({
				"position":"absolute",
				"top":0,
				"left":0,
				"z-index":2
			})
			
			/*add the active css class to the initial slide*/
			jQuery("#course-numbers li:first a").addClass("active");
			
			//handle click event for the course numbers
			jQuery("#course-numbers li a").click(function(){
				a=jQuery(this);
				if(!a.hasClass("active")){ //if not active do the animation
				
					jQuery("#course-numbers li a").removeClass("active"); //remove the active class from any elements which has it
					
					jQuery("#main-visual img:visible,#course-illustrations img:visible").addClass("toanimate");// add identifier class to items that are to be animated
					
					jQuery("#main-visual img.mainVisual"+a.text()+",#course-illustrations img.illustration"+a.text()).show();// show the elements that correspond to the element clicked
					
					jQuery("#content .hole:visible, #main-visual img.toanimate, #course-illustrations img.toanimate").animate({ //hide the currently visible elements
						"opacity":"hide"
					},500,function(){
						/*
						callback function:
						update the text elements with the new details
						*/				
						jQuery("#content #hole-"+a.text()).fadeIn(100,function(){
							var id=this.id;
							jQuery("#content .hole:not(#"+id+")").hide();
						});
						
						title=jQuery("#content .hole:visible .hole-title").text();	//get the new hole title text to be shown
						dist=jQuery("#content .hole:visible .hole-distance").text(); //get the new hole distance text to be shown
						
						/*
							show new title and distance
						*/
						jQuery("#main-visual-rotator .hole-title").text(title);
						jQuery("div#hole-viewer #course-details .hole-title").text(title);
						jQuery("div#hole-viewer #course-details .hole-distance").text(dist);
						
						a.addClass("active"); //add active class to the newly activated anchor because by now, the new content and images are presumably visible
						
						/*
							do some cleaning up so that we are ready for the next transition
						*/
						jQuery("#main-visual img:hidden,#course-illustrations img:hidden").css({
							"z-index":1,
							"display":"none"
						});
						jQuery("#main-visual img,#course-illustrations img").removeClass("toanimate");
						jQuery("#main-visual img:visible,#course-illustrations img:visible").css("z-index",2);
					})
				}
				return false;
			});
			
			/*
				next >, previous < button click handlers.
				here we get the help of the above written click handler for the hole numbers to do the transition for us, so that we are not repeating code.
			*/
			
			jQuery("#main-visual-rotator .next").click(function(){
				active=jQuery("#course-numbers a.active"); // get the active hole anchor
				li=active.parent(); //refer the list element which houses this anchor
				jQuery("a",li.next()).click(); //fire click event on the anchor element that lies within the next list element
			});
			jQuery("#main-visual-rotator .prev").click(function(){
				active=jQuery("#course-numbers a.active");
				li=active.parent();
				jQuery("a",li.prev()).click();
			});
			
			setInterval(autoRotate,courseDetailsRotateTimeout); //auto rotate through the holes. the timeout can be changed by the "courseDetailsRotateTimeout" var at the top of this file.
			
			/*auto rotate function*/
			function autoRotate(){
				var ul=jQuery("#course-numbers");
				var active=jQuery("a.active",ul);
				var li=active.parent();
				var nextli=li.next();
				if(nextli.length==1){
					jQuery("a",nextli).click();
				}else{
					jQuery("li:first a",ul).click();
				}
			}
			
			/*
				END Hole Viewer
			*/
			
		});
}catch(error){

}