//SET NOCONFLICT TO WORK WITH OTHER LIBRARIES
jQuery.noConflict();

//CUSTOM JQUERY FUNCTIONS
jQuery(document).ready(function(){


	//Enable the snow
	jQuery('#status').snowfall({flakeCount : 5, maxSpeed : 0.2});

	//Enabled dropdowns
	jQuery('ul#nav').superfish({ 
		delay:       500,                            // one second delay on mouseout 
		animation:   {opacity:'show', height:'show'},  // fade-in and slide-down animation 
		speed:       300,                          // faster animation speed 
		autoArrows:  false,                           // disable generation of arrow mark-up 
		dropShadows: false                            // disable drop shadows 
	});	


	//Check if element exists
	if (jQuery('#homepageSlideshow').length != 0){

		jQuery('#homepageSlideshow').anythingSlider({
			
			// Appearance
			width               : '962',      // Override the default CSS width
			height              : '344',      // Override the default CSS height
			resizeContents      : true,      // If true, solitary images/objects in the panel will expand to fit the viewport
			tooltipClass        : 'tooltip', // Class added to navigation & start/stop button (text copied to title if it is hidden by a negative text indent)
			
			// Navigation
			startPanel          : 1,         // This sets the initial panel
			hashTags            : false,      // Should links change the hashtag in the URL?
			enableKeyboard      : false,      // if false, keyboard arrow keys will not work for the current panel.
			buildArrows         : true,      // If true, builds the forwards and backwards buttons
			toggleArrows        : false,     // if true, side navigation arrows will slide out on hovering & hide @ other times
			buildNavigation     : true,      // If true, builds a list of anchor links to link to each panel
			enableNavigation    : true,      // if false, navigation links will still be visible, but not clickable.
			toggleControls      : false,     // if true, slide in controls (navigation + play/stop button) on hover and slide change, hide @ other times
			appendControlsTo    : null,      // A HTML element (jQuery Object, selector or HTMLNode) to which the controls will be appended if not null
			navigationFormatter : null,      // Details at the top of the file on this use (advanced use)
			forwardText         : "&raquo;", // Link text used to move the slider forward (hidden by CSS, replaced with arrow image)
			backText            : "&laquo;", // Link text used to move the slider back (hidden by CSS, replace with arrow image)
			
			// Slideshow options
			enablePlay          : true,      // if false, the play/stop button will still be visible, but not clickable.
			autoPlay            : true,      // This turns off the entire slideshow FUNCTIONALY, not just if it starts running or not
			startStopped        : false,     // If autoPlay is on, this can force it to start stopped
			pauseOnHover        : true,      // If true & the slideshow is active, the slideshow will pause on hover
			resumeOnVideoEnd    : true,      // If true & the slideshow is active & a youtube video is playing, the autoplay will pause until the video completes
			stopAtEnd           : false,     // If true & the slideshow is active, the slideshow will stop on the last page
			playRtl             : false,     // If true, the slideshow will move right-to-left
			startText           : "Start",   // Start button text
			stopText            : "Stop",    // Stop button text
			delay               : 3000,      // How long between slideshow transitions in AutoPlay mode (in milliseconds)
			animationTime       : 1000,       // How long the slideshow transition takes (in milliseconds)
			easing              : "swing",   // Anything other than "linear" or "swing" requires the easing plugin
			
			// Interactivity
			clickArrows         : "click",         // Event used to activate arrow functionality (e.g. "click" or "mouseenter")
			clickControls       : "click focusin", // Events used to activate navigation control functionality
			clickSlideshow      : "click",         // Event used to activate slideshow play/stop button
			
			// Misc options
			addWmodeToObject    : "opaque", // If there is an embedded object & swfobject.js is active, the script will automatically add this wmode parameter
			maxOverallWidth     : 32766     // Max width (in pixels) of combined sliders (side-to-side); set to 32766 to prevent problems with Opera
			
		});
	
	}
	
	//Check if element exists
	if (jQuery('#homepageEvents').length != 0){
		
		//Enable the tabs
		jQuery('#homepageEvents').tabs();

	}
	
	//Check if element exists
	if (jQuery('#tweet').length != 0){	

		jQuery('#tweet').tweet({	
			username: 'CrabbeMountain',
			join_text: "auto",
			avatar_size: 32,
			count: 1,
			auto_join_text_default: "we said,",
			auto_join_text_ed: "we",
			auto_join_text_ing: "we were",
			auto_join_text_reply: "we replied to",
			auto_join_text_url: "we were checking out",
			loading_text: "loading tweet..."
		});
	
	}
	
});

//clearInput function
jQuery.fn.clearInput = function(){
	return this.focus(function(){
		if(this.value == this.defaultValue){
			this.value = "";
		}
	}).blur(function(){
		if(!this.value.length){
			this.value = this.defaultValue;
		}
	});
};

//clearForm function
jQuery.fn.clearForm = function() {
	return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
			return jQuery(':input',this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
			this.value = '';
		else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		else if (tag == 'select')
			this.selectedIndex = -1;
	});
};
