$(document).ready(function(){
	
	$('.featLeft a').hover(function(e){ $(this).hoverFlow(e.type, {opacity: "0.3"}, 200); }, function(e){ $(this).hoverFlow(e.type, {opacity: "1.0"}, 350); });
	// add the bump to the sub thumbnails
	$('.polThumbFeat').addClass('poltpush');
	$('.polThumbFeat:nth-child(4n)').removeClass('poltpush');
	// spritely
	$('.cloud1').pan({fps: 30, speed: 0.2, dir: 'left'});
	// hoverflow
	$(".cartadd, .shopTopLink, .polt, .poltf").hover(function(e){ $(this).hoverFlow(e.type, {opacity: "0.7"}, 200); }, function(e){ $(this).hoverFlow(e.type, {opacity: "1.0"}, 350); });
	$(".collageItem a").hover(function(e){ $(this).hoverFlow(e.type, {opacity: "0.5"}, 200); }, function(e){ $(this).hoverFlow(e.type, {opacity: "1.0"}, 350); });
	
//	$('.sbBio img, .sbTeaser img').animate({opacity: 0.6},0);
	$('.sbBio img, .sbTeaser img').hover(function(e){ $(this).hoverFlow(e.type, {opacity: "0.6"}, 200); }, function(e){ $(this).hoverFlow(e.type, {opacity: "1.0"}, 350); });

	$('.shopL:last').removeClass().addClass('shopR');
	
	$('.featPix').animate({opacity: 0.3}, 0);
	$('.featLink').hover(function(e){ 
		$(this).nextAll(':last').hoverFlow(e.type, {opacity: "1.0"}, 200);
	}, function(e){ 
		$(this).nextAll(':last').hoverFlow(e.type, {opacity: "0.3"}, 350);
	}); 
	
	$('.soonish').click(function(){
		alert('coming soon!');
		return false
	});
	
	
	//JQUERY UI INTENSITY

	$('.collageAdd h2 span').animate({ opacity: "0.0" }, 0);
	
	// TWITTER FEED
//	$.getJSON('http://twitter.com/status/user_timeline/shehitpause.json?count=1&callback=?', function(data){$.each(data, function(index, item){$('.twFeed').append('<div class="tweet"><p>' + item.text.linkify() + '</p><p><em>' + relative_time(item.created_at) + '</em></p></div>');});});

//	function relative_time(time_value) { var values = time_value.split(" "); time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3]; var parsed_date = Date.parse(time_value); var relative_to = (arguments.length > 1) ? arguments[1] : new Date(); var delta = parseInt((relative_to.getTime() - parsed_date) / 1000); delta = delta + (relative_to.getTimezoneOffset() * 60); var r = ''; if (delta < 60) { r = 'a minute ago';} else if(delta < 120) { r = 'couple of minutes ago'; } else if(delta < (45*60)) { r = (parseInt(delta / 60)).toString() + ' minutes ago'; } else if(delta < (90*60)) { r = 'an hour ago'; } else if(delta < (24*60*60)) { r = '' + (parseInt(delta / 3600)).toString() + ' hours ago'; } else if(delta < (48*60*60)) { r = '1 day ago'; } else { r = (parseInt(delta / 86400)).toString() + ' days ago'; } return r;}

//	String.prototype.linkify = function() { return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) { return m.link(m); }); };






	// HOMEPAGE SLIDESHOW STUFFS
	$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { $(pager).find('li').removeClass('activeLI')  .filter('li:eq('+currSlideIndex+')').addClass('activeLI'); };

	$('.singleSlides').cycle({ 
		before:  onBefore, 
		speed:  650, 
		timeout: 4000, 
/*		pager:  '#nav', 
		pagerAnchorBuilder: function(idx, slide) {  
			var img = $(slide).children().eq(0).attr("src"); return '<li><a href="#"><img src="' + img + '" width="120" height="92" /></a></li>'; 
			} */
		}); 

	$('.featLeft a').lightBox();
	$('.closer').click(function(){ $('.featLeft a').lightBox(); });
	
	$('.subLinks').easyPaginate({ step:8, nextprev: 0 });
	$('.thumbs').easyPaginate({ step:12, nextprev: 0 });
	
	// ATTEMPT AT SOME AJAX SHIZZ....OH GOD PLEASE WORK
	
	$('.collager li a').click(function(){
		$(this).parent().parent().find('.wicked').each(function(){
			$(this).removeClass('wicked');
		});
		$(this).addClass('wicked');
		var toLoad = $(this).attr('href')+' #content';
		$('#content').hide(0,loadContent);
		function loadContent() { $('.collageDrags').load(toLoad,'',showNewContent()) }
		function showNewContent() { $('#content').show(0) }
		$('.collageDrags').ajaxStop(function() {
			
			$('.collageParty').easyPaginate({ step:12, nextprev: 0});
			var pagernate = $('.collageDrags ol').length;			
			if( pagernate > 1 ) { $('.collageDrags ol').last().remove(); }

			// this sets 
			$('.collageParty img').draggable({ cursor: 'move', appendTo: "body", helper: "clone" }).touch({
			    animate: false,
			    sticky: false,
			    dragx: true,
			    dragy: true,
			    rotate: false,
			    resort: true
			});;
			
		});
	
		return false;
	});
	
	$('.collager li a:first').addClass('wicked');
	
	$('.page-template-collage-page-php').ready(function(){
		var topLoad = $('.collager li a:first').attr('href')+' #content';
		$('#content').hide(0,loadContent);
		function loadContent() { $('.collageDrags').load(topLoad,'',showNewContent()) }
		function showNewContent() { $('#content').show(0) }
		
		$('.collageDrags').ajaxStop(function() {
			
			$('.collageParty').easyPaginate({ step:12, nextprev: 0});
			var pagernate = $('.collageDrags ol').length;			
			if( pagernate > 1 ) { $('.collageDrags ol').last().remove(); }

			// this sets 
			$('.collageParty img').draggable({ cursor: 'move', appendTo: "body", helper: "clone" }).touch({
			    animate: false,
			    sticky: false,
			    dragx: true,
			    dragy: true,
			    rotate: false,
			    resort: true
			});;
			
		});
		
		return false
	});
	
	/**** here is a ui *****//**ADD STUFF TO COLLLAGE**/
	/**** here is a ui *****//**ADD STUFF TO COLLLAGE**/
		var limit = 4;
	    var counter = 0;
	
		$('.collageAdd form').hide();
	
		$( ".collageArea" ).droppable({
			addClasses: false,
			accept: '.collageParty img',
			activeClass: 'dragactive',
			drop: function( event, ui ) {			
				counter++;
	            if (counter == limit) {
					ui.draggable.clone().appendTo(this).addClass('canvassed').animate({opacity: 0.0}, 0, function(){ $(this).delay(100).animate({opacity: 1.0}, 400); });
	                $(this).droppable("disable");

					var title = ui.draggable.clone().attr("title");
					var cluster = "<li>" + title + "</li>";
					$('.collageAdd ul').append(cluster);
					var shoes = $('.collageAdd ul li:nth-child(1)').text();
					var shoes2 = $('.collageAdd ul li:nth-child(2)').text();
					var shoes3 = $('.collageAdd ul li:nth-child(3)').text();
					var shoes4 = $('.collageAdd ul li:nth-child(4)').text();
					var shoesies =  '1) ' + shoes + ' 2) ' + shoes2 + ' 3) '  + shoes3 + ' 4) '  + shoes4;

					$('.collageAdd form .onetwenty').attr('value', shoesies);

					$('.collageAdd form').fadeIn();
	
	            } else {
					ui.draggable.clone().appendTo(this).addClass('canvassed').animate({opacity: 0.0}, 0, function(){ $(this).delay(100).animate({opacity: 1.0}, 400); });
					
					var title = ui.draggable.clone().attr("title");
					var cluster = "<li>" + title + "</li>";
					$('.collageAdd ul').append(cluster);
				}
				
				if(counter > 0) { $(".deletered, .deletered2").animate({opacity: "1.0"}, 300); }
			}
		});

	
	$(".collageArea").sortable({
		opacity: 0.7,
		tolerance: 'pointer',
		update: function() {
			$('.collageAdd ul li').remove();
			$('.collageArea img').each(function() { 
				var colImg = $(this).attr('title');
				var colClus = "<li>" + colImg + "<span>*</span></li>";
				$('.collageAdd ul').append(colClus);

				$('.collageAdd h2 span').animate({opacity: "1.0"}, 0);
				$('.collageAdd ul li span').delay(500).animate({opacity: "0.0"}, 400, function(){
					$(this).remove();
				});
				
				var shoes = $('.collageAdd ul li:nth-child(1)').text().slice(0,-1)
				;
				var shoes2 = $('.collageAdd ul li:nth-child(2)').text().slice(0,-1)
				;
				var shoes3 = $('.collageAdd ul li:nth-child(3)').text().slice(0,-1)
				;
				var shoes4 = $('.collageAdd ul li:nth-child(4)').text().slice(0,-1)
				;
				var shoesies =  '1) ' + shoes + ' 2) ' + shoes2 + ' 3) '  + shoes3 + ' 4) '  + shoes4;

				$('.collageAdd form .onetwenty').attr('value', shoesies);
				
			});
		}
	});

	$(".deletered, .deletered2").animate({opacity: "0.0"}, 0);

	$(".deletered").droppable({
		connectWith: '.collageArea',
		tolerance: 'pointer',
		drop: function(event, ui) {
			$(ui.draggable).remove();
			counter--;
			$( ".collageArea" ).droppable("enable");
			if(counter == 0) { $(".deletered, .deletered2").animate({opacity: "0.0"}, 500); }
			if(counter < 4) { $('.collageAdd form').fadeOut(); }
		}	
	});
	
	$('.page-template-polaroids2-page-php .collageParty').remove();

	$('.informer .addthis_toolbox, .sbBio .addthis_toolbox, .sbTeaser .addthis_toolbox, .contactR .addthis_toolbox, .contactL .addthis_toolbox, .shopR .addthis_toolbox, .shopL .addthis_toolbox, .aboutContent .addthis_toolbox, .featRight .contee .addthis_toolbox, .sbMailing .addthis_toolbox, .page-template-news-page-php .addthis_toolbox').remove();
//	$('.informer script').remove();
	$('.wpcf7-text').attr('onblur', 'myBlur(this);');
	$('.wpcf7-text').attr('onfocus', 'myFocus(this);');

/*	$("#userandquery").tweet({
	          count: 1,
	          query: "from:seaofclouds http",
	          loading_text: "searching twitter..."
	 }); */

});//CLOSE THIS JQUERY SHIZZ

// Javascript
function onBefore() { var title = $(this).find('img').attr("title"); $('.mainSlideText p').text(title); }

function myFocus(element) { if (element.value == element.defaultValue) { element.value = ''; } }

function myBlur(element) { if (element.value == '') { element.value = element.defaultValue; } }
