//////available functions:////////

		//* inputPlaceholder(elementSelector) - enables placeholder text on specified input fields for non-html5
		
		//* flickrFeed_user_all(user_id, section_id) - adds a flickr feed to specified section, with lightbox effects added
		
		//* validateForm(formSelector) - enables front-end validation for selected form
		
		//* dynamicCufon(elementSelector, hover_on, font_family) - cufon replacement for elements generated dynamically. font_family variable is optional.
		
		//* makeSlider(parentElement, slide_effect, speed, pause, control) - creates slideshow using nivo slider plugin. 
		
		//* menuIntent(sens, int, slideSpeed, mouseOutTimeOut) - uses hover intent plugin to control navigation drop down menus. all arguments are optional. int, slideSpeed and mouseOutTimeOut are in milliseconds (1000 = 1 second);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	

////////enables placeholder text on specified input fields for non-html5.////////
//	jQuery.support.placeholder = false;
//	test = document.createElement('input');
//	if('placeholder' in test) jQuery.support.placeholder = true;
function inputPlacehoder(elementSelector){	
	if(!$.support.placeholder) { 
		var active = document.activeElement;
		$(elementSelector+':text').focus(function () {
			if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
				$(this).val('').removeClass('hasPlaceholder');
			}
		}).blur(function () {
			if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
				$(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
			}
		});
		$(elementSelector+':text').blur();
		$(active).focus();
		$('form').submit(function () {
			$(this).find('.hasPlaceholder').each(function() { $(this).val(''); });
		});
	}
}

////////create flickr feed, with lightbox effects/////////
function flickrFeed_user_all(user_id, section_id){
	$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id="+user_id+"&lang=en-us&format=json&jsoncallback=?", function(data){
	  $.each(data.items, function(i,item){
		var thumbImage = item.media.m;
		var largeImage = thumbImage.replace('_m.jpg', '.jpg');
		$("<img/>").attr("src", thumbImage).appendTo(section_id)
		  .wrap("<a href='" + largeImage + "' title='" + item.title + "'></a>").parent('a').lightBox();
		$("a[rel*=lightbox]").lightBox();
	  });
	});
}

////////add lightbox ability to images///////
function makeLightbox(selector){
		$(selector+" a").attr('rel', 'lightbox');
}

///////form validation////////
jQuery.fn.exists = function(){return jQuery(this).length>0;}
function validateForm(formSelector){
	if($(formSelector).exists())
	{
		$(formSelector).validate();
	}
}

////////dynamic element cufon replacement////////
function cufonReplace(elementSelector, hover_on, font_family){
	if(font_family) {
		Cufon.replace(elementSelector, {fontFamily: font_family, hover: hover_on});
	} else {
		Cufon.replace(elementSelector, {hover: hover_on});
	} 
}


////////creates slideshow using nivo slider plugin///////
function makeSlider(parentElement, slide_effect, speed, pause, control, start){
	$(parentElement+' img').hide();
	$(window).load(function(){
	// feature box
		var total = $(parentElement+' img').length;
		var rand = Math.floor(Math.random()*total);
		$(parentElement).nivoSlider({
			effect: slide_effect, //sliceDown, sliceDownLeft, sliceUp, sliceUpLeft, sliceUpDown, sliceUpDownLeft, fold, fade, random, slideInRight, slideInLeft, boxRandom, boxRain, boxRainReverse, boxRainGrow, boxRainGrowReverse
			slices:15,
			animSpeed:speed, //slide transition speed, in milliseconds
			pauseTime:pause, //how long each slide will show, in milliseconds
			startSlide:start, //Set starting Slide (0 index)
			directionNav:false, //Next & Prev
			directionNavHide:true, //Only show on hover
			controlNav: (control == "num" || control == "thumbs" || control == "rel") ? true : false, //1,2,3...
			controlNavThumbs: (control == "thumbs") ? true : false, //Use thumbnails for Control Nav
			controlNavThumbsFromRel: (control == "rel") ? true : false, //Use image rel for thumbs
			controlNavThumbsSearch: '.jpg', //Replace this with...
			controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
			keyboardNav:true, //Use left & right arrows
			pauseOnHover:true, //Stop animation while hovering
			manualAdvance:false, //Force manual transitions
			captionOpacity:1, //Universal caption opacity
			beforeChange: function(){},
			afterChange: function(){},
			slideshowEnd: function(){} //Triggers after all slides have been shown
		});
	});
}

////////uses hover intent plugin to control navigation drop down menus////////
function menuIntent(sens, int, slideSpeed, mouseOutTimeOut) {
	if(!sens) {
		var sens = 5;
	}
	if(!int) {
		var int = 0;
	}
	if(!slideSpeed) {
		var slideSpeed = 100;
	}
	if(!mouseOutTimeOut) {
		var mouseOutTimeOut = 0;
	}
	var menuConfig = {    
		sensitivity: sens, // number = sensitivity threshold (must be 1 or higher)    
		interval: int, // number = milliseconds for onMouseOver polling interval    
		over: function()
		{
			$(this).children('ul').slideDown();
			$(this).addClass('active');
			$(this).children('a').css({
				'color' : '#bab03e',
				'background' : '#37362c',
				'border' : 'solid #b3b08b',
				'borderWidth' : '1px 1px 0', 
				'margin' : '0',
				'-mozBorderRadius' : '5px 5px 0 0',
				'-webkitBorderRadius' : '5px 5px 0 0',
				'borderRadius' : '5px 5px 0 0'
			});
			
		}, // function = onMouseOver callback (REQUIRED)    
		timeout: mouseOutTimeOut, // number = milliseconds delay before onMouseOut    
		out: function()
		{
			$(this).children('ul').hide();
			$(this).removeClass('active');
			$(this).children('a').css({
				'color' : '#ffffff',
				'background' : 'transparent',
				'border' : 'none',
				'borderWidth' : '0', 
				'margin' : '0 1px',
				'-mozBorderRadius' : '0',
				'-webkitBorderRadius' : '0',
				'borderRadius' : '0'
			});
	} // function = onMouseOut callback (REQUIRED)    
	};				
	$('.dropMenu ul').hide();
	$('.dropMenu').hoverIntent(menuConfig);
}

