hs.graphicsDir = '/highslide/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.outlineType = 'glossy-dark';
hs.wrapperClassName = 'dark';
hs.fadeInOut = true;
hs.dimmingOpacity = 0.85;
hs.showCredits = false;
 
// Add the controlbar
if (hs.addSlideshow) hs.addSlideshow({
	//slideshowGroup: 'group1',
	interval: 5000,
	repeat: false,
	useControls: true,
	fixedControls: 'fit',
	overlayOptions: {
		opacity: .6,
		position: 'bottom center',
		hideOnMouseOut: true
	}
});



// Options for the vimeo gallery
	var vimeoOptions = {
		//thumbnailId: 'vimeo',
		slideshowGroup: 'vimeo',
		objectType: 'swf', 
		width: 780, 
		objectWidth: 780,
		height: 449, 
		objectHeight: 439, 
		useControls: false,
		allowSizeReduction: false, 
		preserveContent: false,
		wrapperClassName: 'vimeo-class dark',
		maincontentText: 'You need to upgrade your Flash player'
	}


$(function() {

	$.each("ul.css-tabs li a",function(i){
		if($("ul.css-tabs>li>a:eq("+i+")").attr("href")!=null){
			var patt=new RegExp("accordion=[A-z_\\-]+ ");
			var hash = location.hash;
			var found = patt.exec(hash);
			//if(found!=null)alert(found[0]);
			if(patt.test(hash)!=false){
				href_parts = $("ul.css-tabs>li>a:eq("+i+")").attr("href").split(" ");
				new_href = href_parts[0] + "/" + found[0] + href_parts[1];
				$("ul.css-tabs>li>a:eq("+i+")").attr("href", new_href);
			}
		}
	});

	var tab_accordion_click_counter = 0;

	$.tools.tabs.addEffect("slide_with_nav", function(tabIndex, done) {
		
		var patt=new RegExp("accordion=([A-z_\\-]+) ");
		var hash = location.hash;
		var found = patt.exec(hash);

		if(patt.test(hash)!=false && tab_accordion_click_counter==0){
			var accordion_name = found[1];
			var accordion_position = "0";

			$.each(this.getTabs(),function(i,v){
				if($(v).find("a").attr("name")==accordion_name){
					accordion_position = i;
				}
			});
			//this.click(accordion_position);
			this.getConf().initialIndex = accordion_position;
			tabIndex = accordion_position;
			//alert(accordion_position);
		}
		tab_accordion_click_counter++;

		this.getPanes().slideUp('fast');

		this.getPanes().eq(tabIndex).slideDown(function()  {
			
			// the supplied callback must be called after the effect has finished its job
			done.call();
		});
	});

	$.tools.tabs.addEffect("mx10_ajax", function(tabIndex, done) {
		
		//load tab as ajax
		var url = this.getTabs().eq(tabIndex).attr("href");

		var pane = $(".css-panes > div");
		
		//load tab content from sitemap. format the response to match required html.
		$.ajax({
  		url: url,
		beforeSend: function(xhr){$(".default_accordion").slideDown();},
		dataFilter: function(data, dataType){
			selector = "";
			list = url.split(" ");
			if(list.length>0){ 
//if css selector used to point to data - extract css selector part of url
			$.each(list,function(i,v){
			  if(i>0){
			    selector+=v+" ";
			  }
			})

// pick out data (accorions) from whole page..
			 clean_data = $(data).find(selector);

			//find all the accordions in the ol>li's
			 items = $(clean_data).children(".accordions").children();

			if(items.length>0){
			 accordion_text = "<div class=\"accordion accordion_"+items.length+"\">";
			
			 $.each(items,function(i,v){
			   accordion_text += "<h2><a href=\""+$(items[i]).children("h5").children("a").attr("href")+"\" name=\""+$(items[i]).children("h5").children("a").attr("name")+"\">"+$(items[i]).children("h5").children("a").text()+"</a></h2>";
			   accordion_text += "<div class=\"pane\"><h3>"+$(items[i]).children("h5").children("a").text()+"</h3>"+$(items[i]).children(".content").html();


// if popups exist show them within the accordion...

				if($(items[i]).children(".popups").length>0){
					accordion_text += "<div class=\"button_holder\">";
					$.each($(items[i]).children(".popups"),function(i2,v2){
						css_selector = $(items[i]).children(".popups").eq(i2).children("li").children("h6").children("a").attr("href");
						css_selector_parts = css_selector.split("/");
						new_css_selector = "";
						$.each(css_selector_parts,function(i3,v3){
							if(i3>0) new_css_selector += " #"+v3;
						})
						
						accordion_text +="<a href=\"/link"+new_css_selector+"\" rel=\"#overlay\" class=\"button\">"+$(items[i]).children(".popups").eq(i2).children("li").children("h6").text()+"</a>";
						accordion_text +="<div id=\"overlay\" class=\"apple_overlay black\">";
						accordion_text +="<div class=\"contentWrap\"></div>";
						//accordion_text += $(items[i]).children(".popups").eq(i2).children("li").children(".content").html();
						accordion_text += "</div>";
					});
					//accordion_text +=' <div class="button_holder"><a href="#" class="button">Programme</a><a href="#" class="button">Fitness/attitude</a><a href="#" class="button">Equipment/kit list</a></div>';
					//accordion_text +=' <div class="button_holder"><a href="#" class="button">Gallery</a><a href="#" class="button_blue">Clients and testimonials</a></div>';
					accordion_text += "</div>";
				}

			   accordion_text += "</div>";
			 });

			 accordion_text += "</div>";
			}else{
			  accordion_text = "<div class=\"inner-pad\">";
			  accordion_text += $(clean_data).children(".content").html();
			  accordion_text += "</div>";
			}
			  return accordion_text;

			}else{
//if no accordions present ... use tab text.
			  return "<h1>need to output  from skiweekend_tabs</h1>";
			}
			
		},
		context: pane,
  		success: function(data, textStatus, jqXHR){
   			pane.html(data);
   			$(".accordion").each(function(i,v) { 

     		 	$(this).tabs(".accordion:eq(" +i+ ") div.pane", {
       				tabs: 'h2',  
        			effect: 'slide',
					initialIndex: null
				});
				
				var api = $(this).data("tabs");
				
				var patt=new RegExp("accordion=([A-z_\\-]+) ");
				var hash = location.hash;
				var found = patt.exec(hash);
				var accordion_position = 0;
				if(patt.test(hash)!=false){
					var accordion_name = found[1];
					$.each(api.getTabs(),function(i,v){
						if($(v).find("a").attr("name")==accordion_name){
							accordion_position = i;
						}
					});				
				}
			
				api.click(accordion_position);
				

				$(".button[rel]",pane).each(function(i) {
					$("a[rel]:eq("+i+")",pane).overlay({
						mask: '#000000',
						effect: 'apple',

						onBeforeLoad: function() {
							// grab wrapper element inside content
							var wrap = this.getOverlay().find(".contentWrap");

							// load the page specified in the trigger
							wrap.load(this.getTrigger().attr("href"));
						}
					}); 
				});
    			});
			//calendar overlays once loaded via ajax
			$(".list a[rel]").overlay({
				mask: '#000000',
				effect: 'apple'
			});

 		}, // EOF ajax success
		error: function(a,b,c){
			//console.log("a= "+a);
			//console.log("error b = "+b);
			//console.log("c= "+c);
		}
		});// EOF ajax function

		// the supplied callback must be called after the effect has finished its job
		done.call();
	});

	//console.log("before first tab ajax");
	$("ul.css-tabs:not(.no_default)").tabs("div.css-panes > div", {
		effect: 'mx10_ajax',
		history: true
	});

/*

	var api = $("ul.css-tabs").data("tabs");

	//When the slideshow transitions
	api.onClick(function() {
	
		//Now you can look at which slide you're on by using this.getIndex()
		if((this.getIndex()) == 0){

			//console.info("Yes, this is the first slide ");

			//console.info(api);

		}
	
	});

*/


/* ACCORDION SCRIPT WAS HERE... moved to the "2011/tabs" template */

    $('#ajaxLoader')
    .ajaxStart(function() {$(this).show();})
    .ajaxStop(function() {$(this).fadeOut();});

	var pause_icon = "100% 0";
	var play_icon = "0 0";
	var speed = 500;
	var between_slides = 7000; // milliseconds

	
	if($(".scrollable").length>0){
		$(".scrollable")
		.scrollable({
			"circular": true,
			"speed":speed
		})
		.autoscroll({
			"autoplay": true,
			"interval":between_slides
		})
		.navigator()

		var scrollable_api = $(".scrollable").data("scrollable");
		scrollable_api.status = 'playing';
		$("span#num").text(scrollable_api.getIndex()+1);

		//console.log(scrollable_api.status);

		scrollable_api.onBeforeSeek(function() {
		
			//console.log(scrollable_api.status);
			if(scrollable_api.status == 'stopped'){
				scrollable_api.stop();

				//change the pause button background
				$("a#pause").css("background-position",play_icon);
				return false;
			}else{
				//change the pause button background
				$("a#pause").css("background-position",pause_icon);

				//if ok to carry on ...
				return true;
			}
		});

		scrollable_api.onSeek(function() {
			// inside callbacks the "this" variable is a reference to the API
			//console.info("current position is: " + this.getIndex())
			$("span#num").text(this.getIndex()+1);

			$(".slider-more-link[rel]").overlay({
				mask: '#000000',
				effect: 'apple'
			});
		});

		$("a#pause").click(function(){
			if(scrollable_api.status == 'playing'){
				//change status to 'stopped'
		 		scrollable_api.status = 'stopped'
				scrollable_api.stop();
				$(this).css("background-position",play_icon);
			}else{
				//change status to 'playing'
				scrollable_api.status = 'playing';
				scrollable_api.play();
				scrollable_api.next(speed);
				//$(this).css("background-position",pause_icon);
			}
			//console.log(scrollable_api.status);
			return false;
		});

		$("a#next").click(function(){
			scrollable_api.next(speed);
			return false;
		});

		$("a#prev").click(function(){
			scrollable_api.prev(speed);
			return false;
		});

	}

	$(".homepage_popup_text").overlay({
		mask: '#000000',
		effect: 'apple'
	});  
	$("#callback").overlay({
		mask: '#000000'
	});   
	$("#full_news_content").overlay({
		mask: '#000000',
		effect: 'apple'
	});

	$(".news_overlay_link").overlay({
		mask: '#000000',
		effect: 'apple'
	});


	$(".news .news_pagination a").live("click",function(e){
		var clicked_link = $(this);
		var container = $(".news_ajax");
		var ajax_link = $(clicked_link).attr("href");
		var ajax_link_base = "/tab-templates/latest_news/";
		var ajax_link_parts = ajax_link.split("/");

		ajax_link = ajax_link_base + ajax_link_parts[ajax_link_parts.length-1];
		
		//$(".news h2").clone().prependTo(container.parent()).css().addClass("news_heading_ajax");
		container.fadeOut('fast',function(){ // once box faded out load new content
				container.load(ajax_link,function(){ 
					container.fadeIn();//on successful ajax load fade back in.
					$(".news_overlay_link").overlay({
						mask: '#000000',
						effect: 'apple'
					});
				})
		})
		return false;
	});

	$(".thumbs img[title]").tooltip({
		tip: '#skitip',
		effect: 'slide',
		offset: [25, 0],
		tipClass:".tooltip"
	});


}); // EOF jquery document ready..

