//////available functions:////////

		//* inputPlaceholder(elementSelector) - enables placeholder text on specified input fields for non-html5
		
		//* flickrFeed_user_all(user_id, section_id, count) - adds a flickr feed to specified section, with lightbox effects added
		
		//* flickrFeed_set(user_id, set_id, section_id, count) - 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, count){
	var itemNum = 0;
	$.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');
		var description = item.description;
		var desc = $("<div />").append(description);
		if ($(desc).children().size() == 3) {
        	description = $(desc).children("p:last").html();
        } else {
        	description = "";
        }
		$("<img/>").attr("src", thumbImage).appendTo(section_id)
		  .wrap("<a href='" + largeImage + "' title='" + description + "'></a>").parent('a').lightBox();
		itemNum++;
		if(itemNum == count) {
			return false;
		}
	  });
	});
}

function flickrFeedAPI_set(api_key, setID, section_id, count) {
	var itemNum = 0;
	var apiKey = api_key;
	
	var photosetID = setID;
	//alert('http://api.flickr.com/services/rest/?&method=flickr.photosets.getPhotos&api_key=' + apiKey + '&photoset_id=' + photosetID + '&format=json&jsoncallback=?');
	$.getJSON('http://api.flickr.com/services/rest/?&method=flickr.photosets.getPhotos&api_key=' + apiKey + '&photoset_id=' + photosetID + '&format=json&jsoncallback=?', 
	function(data){
		  $.each(data.photoset.photo, function(i,item){
			var photoID = item.id;
			var photoSecret = item.secret;
			var photoURL = 'http://farm'+item.farm+'.static.flickr.com/'+item.server+'/'+item.id+'_'+item.secret+'_m.jpg';
			var largeImage = photoURL.replace('_m.jpg', '.jpg');
			var desc;
			$.getJSON('http://api.flickr.com/services/rest/?&method=flickr.photos.getInfo&api_key=' + apiKey + '&photo_id=' + photoID + '&secret=' + photoSecret + '&format=json&jsoncallback=?', function(d) {
				desc = d.photo.description._content;
				$("<img/>").attr("src", largeImage).attr("title", desc).appendTo(section_id)
					 .wrap("<a href='" + largeImage + "' title='" + desc + "'></a>").parent('a').lightBox();
					itemNum++;
				if(itemNum == count) {
					return false;
				}
			});
		  });	
	});
}

////////create flickr feed from individual set, with lightbox effects/////////
function flickrFeed_set(user_id, set_id, section_id, count){
	var itemNum = 0;
	$.getJSON("http://api.flickr.com/services/feeds/photoset.gne?set="+set_id+"&nsid="+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');
		var description = item.description;
		var desc = $("<div />").append(description);
		if ($(desc).children().size() == 3) {
        	description = $(desc).children("p:last").html();
        } else {
        	description = "";
        }
		$("<img/>").attr("src", thumbImage).appendTo(section_id)
			 .wrap("<a href='" + largeImage + "' title='" + description + "'></a>").parent('a').lightBox();
			itemNum++;
			if(itemNum == count) {
				return false;
			}
	  });
	});
}

////////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: '_m.jpg', //...this in thumb Image src
			keyboardNav:true, //Use left & right arrows
			pauseOnHover:true, //Stop animation while hovering
			manualAdvance:false, //Force manual transitions
			captionOpacity:0.8, //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 = 200;
	}
	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').show();
			$(this).addClass('active');
			$(this).children('a').css('color', '#ed068f');
			$(this).children('a').css('borderTop', '1px solid #2a2b27');
			$(this).children('a').css('borderLeft', '1px solid #2a2b27');
			$(this).children('a').css('borderRight', '1px solid #2a2b27');
			$(this).children('a').css('padding', '0 7px');
			
		}, // 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', '#fff');
			$(this).children('a').css('borderTop', '0');
			$(this).children('a').css('borderLeft', '0');
			$(this).children('a').css('borderRight', '0');
			$(this).children('a').css('padding', '0 8px');
	} // function = onMouseOut callback (REQUIRED)    
	};				
	$('.dropMenu ul').hide();
	$('.dropMenu').hoverIntent(menuConfig);
}


