(function($){ 
    $.fn.extend({
		
		tabbedContent: function() {
			
			//vars
			var mainCont = this;
			var tabs = mainCont.children('.tabs');
			var tabbed = mainCont.children('.tabbed');
			
			//adds classes to all tabs
			var i = 1;
			tabs.children('li').each(function() {
				
				jQuery(this).addClass('tab-'+i);
				i++;
				
			});
			
			
			var i = 1;
			tabbed.children('li').each(function() {
				
				jQuery(this).addClass('tabbed-'+i);
				i++;
				
			});
			
			//sets up the first current content
			tabs.children('li:first').addClass('current');
			tabbed.children('li:first').addClass('current').css({ display: 'block' });
			
			//when the user interacts change the tab
			tabs.children('li').click(function() {
				
				//gets the number of the clicked tab
				var tabNo = jQuery(this).attr('class').split(' ');
				
				//if its nit current
				if(!tabNo[1]) {
				
					var tabNo = tabNo[0].split('-');
					var tabNo = tabNo[1];
					
					//removes the current from the tab and puts on the clicked one
					tabs.children('li.current').removeClass('current');
					tabs.children('li.tab-'+tabNo).addClass('current');
					
					//animates our tabbed content
					tabbed.children('li.current').fadeOut(200, function() {
						
						jQuery(this).removeClass('current');
						tabbed.children('li.tabbed-'+tabNo).addClass('current').fadeIn(200);
						
					});
				
				}
				
			});
			
		},
		
		ddPortfolioGrid: function(col) {
			
			//main vars
			var mainCont = this;
			
			//if our col is true we activate the color hover
			if(col === true) {
				
				//when user hovers the portfolio item
				mainCont.children('li').children('.portfolio-item').hover(function() {
					
					//let's get the colour
					var color = jQuery(this).children('.image').children('.color').text();
					
					//now we change the bg color
					jQuery(this).children('.image').css({ background: '#'+color });
					
				}, function() {
					
					//removes the color
					jQuery(this).children('.image').css({ background: 'none' });
					
				});
				
			}
			
			//when users hovers the image the image hover appears
			mainCont.children('li').children('.portfolio-item').children('.image').children('a').children('span').css({ display: 'block', opacity: 0 });
			mainCont.children('li').children('.portfolio-item').children('.image').children('a').children('span').children('span').css({ display: 'block', opacity: 0 });
			mainCont.children('li').children('.portfolio-item').children('.image').children('a').hover(function() {
				
				jQuery(this).children('span').stop().animate({ opacity: 1 }, 250);
				jQuery(this).children('span').children('span').stop().animate({ opacity: 1 }, 250);
				
			}, function() {
				
				jQuery(this).children('span').stop().animate({ opacity: 0 }, 250);
				jQuery(this).children('span').children('span').stop().animate({ opacity: 0 }, 250);
				
			});
			
		}
		
	})
	
})(jQuery);

function ddMenu(anim) {
	
	//in anim isnt set
	if(!anim) { anim = false; }
	
	//vars
	var mainCont = jQuery('#menu');
	var ulCont = jQuery('#menu ul');
	
	//when users hover the li
	ulCont.children('li').hover(function() {
		
		//finds the next UL
		var next = jQuery(this).find('ul:first');
		
		//if the user wants to animate
		if(anim === true) {
			
			next.css({ display: 'block', opacity: 0 }).stop().animate({ opacity: 1 }, 200);
			
		} else {
			
			next.show();
			
		}
		
	}, function() {
		
		//finds the next UL
		var next = jQuery(this).find('ul:first');
		
		//if the user wants to animate
		if(anim === true) {
			
			next.stop().animate({ opacity: 0 }, 200, function() { jQuery(this).css({ display: 'none' }); });
			
		} else {
			
			next.hide();
			
		}
		
	});
	
}

function ddSliderArrows() {
	
	//vars
	var next = jQuery('#slide-right');
	var prev = jQuery('#slide-left');
	var arrows = jQuery('#slide-right, #slide-left');
	
	//if the ddslider is there
	if(next.length > 0 && prev.length > 0) {
		
		//displays block and opacity 
		next.css({ display: 'block', opacity: 0 });
		prev.css({ display: 'block', opacity: 0 });
		
		jQuery('#slider-wrapper').hover(function() { arrows.stop().animate({ opacity: 1 }, 150); }, function() { arrows.stop().animate({ opacity: 0 }, 150); });
		
		//next.hover(function() { jQuery(this).stop().animate({ opacity: 1 }, 100); }, function() { jQuery(this).stop().animate({ opacity: 0 }, 100); });
		//prev.hover(function() { jQuery(this).stop().animate({ opacity: 1 }, 100); }, function() { jQuery(this).stop().animate({ opacity: 0 }, 100); });
		
	}
	
}

function ddShareTab() {
	
	//main vars
	var mainCont = jQuery('.share-this');
	var ulCont = mainCont.children('ul');
	
	jQuery('.share-this > .open, .share-this > .arrow').click(function() {
		
		//if its closed
		if(jQuery(this).parent().children('.arrow-close').length === 0) {
		
			mainCont.children('.arrow').addClass('arrow-close');
			ulCont.slideDown(200);
		
		} else {
		
			mainCont.children('.arrow').removeClass('arrow-close');
			ulCont.slideUp(200);
			
		}
		
	});
	
}
