
// remap jQuery to $
(function($){



// get news feature news content size
var featureCount = $('.content-item').size();
var contentscrollerWidth = featureCount * 260;
var showSlider = false;
if (contentscrollerWidth > 840){
		showSlider = true;
}
$('#content-holder').width(contentscrollerWidth);




$(".scrollable").scrollable();	


var pageclass = $('html').attr('id');
if(pageclass == 'home'){

//$.backstretch("http://www.kew.co.nz/assets/Homepage/background3.jpg");


}
	
	
	$('#slider-handle').live('click', function(e) {
		// first stop background animation to prevent flicker
		//$(document).bgStretcher.pause()
		e.preventDefault();
		if($('#back-slider-panel').hasClass('open')){
			$('#content-slider').fadeOut('slow');
			$('#back-slider-panel').animate({ bottom: -140}, 600).removeClass('open').addClass('closed');
					
				
		} else {
			
			$('#back-slider-panel').animate({ bottom: 0}, 600).removeClass('closed').addClass('open');
			if(showSlider){$('#content-slider').fadeIn('slow');}
			
			
		}
	});
	
	
	
	$("#content-slider").slider({
    animate: true,
    change: handleSliderChange,
    slide: handleSliderSlide
  });

/*
if($('body').hasClass('class-HomePage')){
	setTimeout(function() {		
	   $('#slider-handle').trigger('click');
	},600);
	}
	
*/

	
	//footer ipad hack
if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
{
     $("#pageFooter").css("position", "static");
};




	defaultValue = $('#searchtext').val();  
	$('#searchtext').click(function() {
	if( this.value == defaultValue ) {
	$(this).val("");
	}
	});
	
	
	
	$("#mainNav .navItem").hoverIntent({
		interval: 90, 
		over: drops_show, 
		timeout: 500, 
		out: drops_hide
	});
	$("#mainNav .navItem").addClass('with-js');
 
 
 })(window.jQuery); 	
		






function drops_show(){ $(this).addClass('show'); $(this).removeClass('with-js'); }
function drops_hide(){ $(this).removeClass('show'); $(this).addClass('with-js'); }



	
// usage: log('inside coolFunc',this,arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if(this.console){
    console.log( Array.prototype.slice.call(arguments) );
  }
};







// catch all document.write() calls
(function(doc){
  var write = doc.write;
  doc.write = function(q){ 
    log('document.write(): ',arguments); 
    if (/docwriteregexwhitelist/.test(q)) write.apply(doc,arguments);  
  };
})(document);


function handleSliderChange(e, ui)
{
  var maxScroll = $("#content-scroll").attr("scrollWidth") - $("#content-scroll").width();
  $("#content-scroll").animate({scrollLeft: ui.value * (maxScroll / 100) }, 1000);
}

function handleSliderSlide(e, ui)
{
  var maxScroll = $("#content-scroll").attr("scrollWidth") - $("#content-scroll").width();
  $("#content-scroll").attr({scrollLeft: ui.value * (maxScroll / 100) });
}

