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

//CUSTOM JQUERY FUNCTIONS
jQuery(document).ready(function(){
	
	//Setup the dropdowns for the main nav
	jQuery('ul#nav').superfish(); 	
	
	//Clear any input fields
	jQuery('input').clearInput();

	//Check if element exists
	if (jQuery('select').length != 0){
	
		jQuery('select').ufd({listMaxVisible: 20});
		jQuery('select').ufd('enable');
	
	}

	//Check if element exists
	if (jQuery('#slideshow ul').length != 0){
	
		jQuery('#slideshow ul').anythingSlider({
			// Appearance
			width               : 402,      // Override the default CSS width
			height              : 238,      // Override the default CSS height
			resizeContents      : false,      // If true, solitary images/objects in the panel will expand to fit the viewport
			
			// Navigation
			startPanel          : 1,         // This sets the initial panel
			hashTags            : false,      // Should links change the hashtag in the URL?
			buildArrows         : false,      // If true, builds the forwards and backwards buttons
			buildNavigation     : true,      // If true, buildsa list of anchor links to link to each panel
			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
			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, it will pause the autoplay until the video has completed
			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       : 600,       // How long the slideshow transition takes (in milliseconds)
			easing              : "swing"    // Anything other than "linear" or "swing" requires the easing plugin
		});
		
	}
	
});

//Sort category via dropdown
function sortCategory(url){
			
	if (url == "#"){
		
		//Do nothing
		
	}
	else {
		
		window.location = url;
	
	}

};

//Show the map tooltip
function showTooltip(vendor){

	//Show the tooltip
	jQuery('#vendorMap a').poshytip('hide');
			
	if (vendor == "#"){
		
		//Do nothing
		
	}
	else {
		
		jQuery('#vendorMap a#vendor_'+vendor).poshytip('show');
		
		//Jump to the section
		window.location = '#vendor_'+vendor;
		
	}

};

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