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

})(window.jQuery);



// 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);


$(document).ready(function() {
	
	if($(".home-container").length > 0){
		$(".home-container").scrollable({circular: "true", activeClass: "active", disabledClass: "disabled"}).navigator().autoscroll({ autoplay: true, interval: 30000 });
	}
	
	if( $("span.tooltipTrigger").length > 0 ){
		$("span.tooltipTrigger[title]").tooltip();
	}
		
	if($(".menu-item-21")){
		$(".menu-item-21").hover(function(){
			//$("ul.sub-menu").fadeIn();
		},function(){
			//$("ul.sub-menu").fadeOut();
		})
	}
	
	$("#search").focus(function(){
		if($.trim($("#search").val()) == "Search"){
			$(this).val("");
		}
	});
	
	$("#search").blur(function(){
		if($.trim($("#search").val()) == ""){
			$(this).val("Search");
		}
	});
	
	
	

	if($("#contactForm").length > 0){

		$.tools.validator.localize("en", {
			'*'	: 'Please re-check this field.',
			':email': 'This is not a valid email address',
			':name': 'Please enter a valid first last name.',
			':number': 'Please enter a vail phone number',
			':url'	: 'Please enter a vail URL',
			'[required]'	: 'This is a required field.'
		});
		
		$("#contactForm").validator({
			inputEvent: 'blur',
			lang: 'en'
		
		});
		
	}

		
});

function jumpToSlideState(id){
	scrollableAPI.each(function(apiIndex) {
		var allItems = scrollableAPI.eq(apiIndex).data("scrollable").getItems();
			allItems.each(function(index){
				if( $(this).attr("id") == id) { scrollableAPI.eq(apiIndex).data("scrollable").seekTo(index);}
			});
	});
}


function jumpToPageLink(linkname){
	setTimeout(function() { $('html, body').animate({
	    scrollTop: $('a[name='+linkname+']').next('div').offset().top 
	}, 300); }, 200);
	
}


function initiateSlideshow(){
	if($('.slideshow-carousel').length > 0){
	
		window.scrollableAPI = $(".slideshow-carousel").scrollable({ circular: true, activeClass: "active", disabledClass: "disabled", onSeek: function(){ 
			this.getRoot().animate({ height : this.getItems().eq(this.getIndex()).height() });
		
		} }).navigator();
		
		scrollableAPI.each(function(index) {
			scrollableAPI.eq(index).data("scrollable").begin();
			scrollableAPI.eq(index).data("scrollable").getRoot().animate({ height : scrollableAPI.eq(index).data("scrollable").getItems().eq(scrollableAPI.eq(index).data("scrollable").getIndex()).height() },100);
		});
		if(window.jumpToSlide){ jumpToSlideState(window.jumpToSlide); }
		if(window.jumpToLink){ jumpToPageLink(window.jumpToLink); }
	};
}
