/** The magic, what's of it **/


//Label replacement
jQuery.fn.labelOver = function(overClass) {
	return this.each(function(){
		var label = jQuery(this);
		var f = label.attr('for');
		if (f) {
			var input = jQuery('#' + f);
			
			this.hide = function() {
			  label.css({ textIndent: -10000 })
			}
			
			this.show = function() {
			  if (input.val() == '') label.css({ textIndent: 0 })
			}
	
			// handlers
			input.focus(this.hide);
			input.blur(this.show);
		  label.addClass(overClass).click(function(){ input.focus() });
			
			if (input.val() != '') this.hide(); 
		}
	})
}
	
$(document).ready(function() {

	//Random bg image
	//var randomBg = ['1','2','3','4','5','6','7'];
  	//var rndNum = Math.floor(Math.random() * randomBg.length);
  	//alert(rndNum);
  	//$('#background').css('background-image', 'url(/wp-content/themes/positiveimpact/images/background'+ randomBg[rndNum] +'.jpg)');

	

	//Add intro class to first paragraph for styling
	$('article p:first-child').addClass('intro');
	
	//Main nav dropdown
	$('#primaryNav li').hover(function() {
		$('ul', this).animate({
			opacity: 1
		},100).slideDown(100);
	}, function() {
		$('ul', this).animate({
			opacity: 0
		},200).slideUp(100);
	});
	
	//Scroll to top
	$('.scrollTop').click(function () {
    	$('html, body').animate({ scrollTop: '0px' }, 1500);
        return false;
    });

	//Label replacement
	$('label').labelOver('overApply');
	
	//Features scroller
	//$('.scrollPrev').addClass('disabled');
	$('#test').scrollable({
		next: '.scrollNext',
		prev: '.scrollPrev',
		speed: 300,
		items: 'ul',
		circular: true
	});//.autoscroll({ autoplay: true, interval: 10000 })
	
	//Clients scroller
	$("#clientsScroller li").hover(function(){
		$(this).stop().fadeTo(300, 1);
		}, function(){
		$(this).stop().fadeTo(300, 0.6); // animate to opaque
	});
	$('#clientsScroller')
		.scrollable({ speed: 1500, circular: true, prev: '#scrollLeft', next: '#scrollRight' })
		.autoscroll({ autoplay: true, interval: 8000 })
		.scrollableAddClones();
	
	//Homepage intor box fading
	$('#bannerBoxes').innerfade({
		animationtype: 'fade',
		speed: 1000,
		timeout: 8000,
		type: 'sequence'
	});
	
	//jQuery Masonry on box lists
	$('ul.boxes').masonry();
	
	//Remove funny character from shop prices
	//$('.pricedisplay').html($('.pricedisplay').html().replace(/&[^;]+;/g, ''))
	
		
//End
});
