// GENERAL BEHAVIOUR //

jQuery(function() {		
	
	jQuery.each(jQuery('.wp-caption img'), function() {
		jQuery(this).one("load",function(){
			var imgWidth = jQuery(this) .width();
			jQuery(this) .parent() .css('width', imgWidth);
		})
		.each(function(){
		if(this.complete) jQuery(this).trigger("load");
		});
	});
	
	jQuery.each(jQuery('a.load-img img'), function() {
		jQuery(this) .after('<span class="img-load-wrap"></span>');
	});
	
	jQuery('a.load-img img').one("load",function(){
		jQuery(this) .parent() .find('span.img-load-wrap') .css('display', 'none');
		jQuery(this) .hide() .fadeIn();
	})
	.each(function(){
	if(this.complete) jQuery(this).trigger("load");
	});
	
	jQuery.each(jQuery('a.zoom-img img'), function() {
		jQuery(this) .after('<span class="zoom-wrap"></span>');
		jQuery(this) .parent() .find('span.zoom-wrap') .css('display', 'none');
	});
	
	jQuery.each(jQuery('a.play-img img'), function() {
		jQuery(this) .after('<span class="play-wrap"></span>');
		jQuery(this) .parent() .find('span.play-wrap') .css('display', 'none');
	});
	
	jQuery.each(jQuery('a.read-img img'), function() {
		jQuery(this) .after('<span class="read-wrap"></span>');
		jQuery(this) .parent() .find('span.read-wrap') .css('display', 'none');
	});
	
	jQuery.each(jQuery('.pull-right, .pull-left'), function() {
		jQuery(this) .next('p') .replaceWith('<span class="wrap-around">' + jQuery(this).next('p').text() + '</span>');
	});
	
	jQuery('.featured-item:last, div.latest-news-item:last') .css({'border' : 'none', 'marginBottom' : '0px'});
	jQuery.each(jQuery('.popular-posts-list, .recent-tweets, .widget-list, .sidebar-widget ul, #sidebar-menu, #sidebar-menu li ul, #sidebar-menu li ul li ul, ul.menu, ul.menu li ul, #big-footer #recentcomments, #big-footer .widget_recent_entries ul, #big-footer .widget_recent_entries ul, #big-footer .widget_alt_style .widget_archive ul, #big-footer .widget_alt_style .widget_categories ul, #big-footer .widget_alt_style .widget_links ul, #big-footer .widget_alt_style .widget_meta ul, #big-footer .widget_alt_style .widget_pages ul'), function() {
		jQuery(this) .find('li:last') .css({'border' : 'none', 'marginBottom' : '0px'});
	});
	
	jQuery.each(jQuery('dl:last'), function() {
		jQuery(this) .after('<br class="clear">');
	});
	
});


// MBIZ SLIDER //

(function(jQuery){
jQuery.fn.mbizslider = function(options) {
	var defaults = {
		autoRotate: true,
		interval: 6000
	  },
	  settings = jQuery.extend({}, defaults, options);
	
	slidesCount = jQuery('#mbiz-slides .mbiz-slide-bg') .length;
	i = 1;
	
	var mbizSlide = '#mbiz-slides .mbiz-slide-bg';
	
	jQuery(mbizSlide + ':first') .addClass('first');
	jQuery(mbizSlide + ':last') .addClass('last');
	jQuery('#mbiz-slides .mbiz-slide-img') .hide();
	jQuery(mbizSlide + ':not(:first)') .css('display', 'none');
	jQuery('#mbiz-slides .mbiz-slide-info') .css('top', '-370px');
	
	while (i <= slidesCount) {
        jQuery('#mbiz-slider-nav') .append('<span class="mbiz-slider-butt"><img src="wp-content/themes/thedawn/images/mbiz-slider-butt.png" alt="button" /></span>');
		i++;
	}
	
	jQuery(mbizSlide + ':first img.mbiz-slide-bg-img') .one("load",function(){
		if (jQuery(mbizSlide + ':first .mbiz-slide-img img') .length != 0) {
			jQuery(mbizSlide + ':first .mbiz-slide-img img') .one("load",function(){
				showSlides();
			}) .each(function(){
				if(this.complete) jQuery(this).trigger("load");
			});
		} else {
			showSlides();
		}
		
		if(settings.autoRotate) {
			MbizPause = 0;
			jQuery('#mbiz-pause') .click(function() {
				if (MbizPause == 0) {
					MbizPause = 1;
					jQuery(this) .css('backgroundPosition', 'center bottom');
				} else if (MbizPause == 1) {
					MbizPause = 0;
					jQuery(this) .css('backgroundPosition', 'center top');
				};
			});
		}
		
		function showSlides() {
			jQuery.each(jQuery(mbizSlide), function() {
				var mbizSlideBG = jQuery(this) .find('img.mbiz-slide-bg-img') .attr('src');
				jQuery(this) .css("background-image", "url("+mbizSlideBG+")");
			});
			jQuery(mbizSlide + ':first .mbiz-slide-info') .animate({'top' : '10px'}, 600);
			jQuery(mbizSlide + ':first .mbiz-slide-img') .fadeIn(); //.animate({'top' : '0px'}, 600);
			jQuery('.slide-img-has-border .slide-img-border') .css('border', '7px solid #000');
			
			jQuery('#mbiz-slider-nav span:first') .css('backgroundPosition', 'center bottom');
			
			jQuery('#mbiz-slides') .css('backgroundImage', 'none');
			
			// Auto Rotator //
			if(settings.autoRotate) { autoRotate = 1; } else { autoRotate = 0; }
			var $autoR;
			var rotatorInterval = setInterval(function() {
				if (autoRotate) {
					$autoR = jQuery(mbizSlide + ':visible');
					$currNavIndex = $autoR .index();
					$currNav = jQuery('#mbiz-slider-nav span:eq('+$currNavIndex+')');
					
					if ($autoR .hasClass('last')) {
						$autoR = jQuery(mbizSlide + ':first');
						$currNav .css('backgroundPosition', 'center top');
						$currNav = jQuery('#mbiz-slider-nav span:first');
					} else {
						$autoR = $autoR.next();
						$currNav .css('backgroundPosition', 'center top');
						$currNav = $currNav.next();
					}
							
					jQuery(mbizSlide + ':visible .mbiz-slide-info') .animate({'top' : '-370px'}, 100);
					jQuery(mbizSlide + ':visible .mbiz-slide-img') .hide();
					jQuery(mbizSlide + ':visible') .hide();
					
					$autoR .fadeIn();
					$autoR .find('.mbiz-slide-info') .animate({'top' : '10px'}, 300);
					$autoR .find('.mbiz-slide-img') .fadeIn();
					
					$currNav .css('backgroundPosition', 'center bottom');
				}
				
				if(settings.autoRotate) {
					jQuery('#pre-body-area') .hover(function() {
						autoRotate = 0;
						jQuery('#mbiz-pause') .show();
					}, function() { 
							if (MbizPause == 0) {autoRotate = 1};
							jQuery('#mbiz-pause') .hide();
						});
				}
			
			}, settings.interval);
		} // end function showSlides
		// ------------ //
		
	}) .each(function(){
			if(this.complete) jQuery(this).trigger("load");
		});
	
	jQuery('#mbiz-slider-nav span') .click(function() {
		
		if(settings.autoRotate) {
			jQuery('#pre-body-area') .hover(function() {
				autoRotate = 0;
			}, function() { 
					if (MbizPause == 0) {autoRotate = 1};
				});
		}
		
		slideIndex = jQuery(this) .index();
		jQuery('#mbiz-slider-nav span') .css('backgroundPosition', 'center top');
		jQuery(this) .css('backgroundPosition', 'center bottom');
		
		jQuery(mbizSlide + ':visible .mbiz-slide-info') .animate({'top' : '-370px'}, 100);
		jQuery(mbizSlide + ':visible .mbiz-slide-img') .hide();
		jQuery(mbizSlide + ':visible') .hide();
			
		jQuery(mbizSlide + ":eq("+slideIndex+")") .fadeIn();
			jQuery(mbizSlide + ":eq("+slideIndex+") .mbiz-slide-info") .animate({'top' : '10px'}, 300);
			jQuery(mbizSlide + ":eq("+slideIndex+") .mbiz-slide-img") .fadeIn();
	});
	
}
})(jQuery);


// Slider fixed image

jQuery(function() {
	
	jQuery('.fixed-slider-loader') .css('display', 'block');
	jQuery('img.fixed-slide-bg-img').one("load",function() {
		jQuery('.fixed-slider-loader') .fadeOut();
		jQuery('img.fixed-slide-bg-img') .remove();
	})
	.each(function(){
	if(this.complete) jQuery(this).trigger("load");
	});
	
});


// LOGIN FROM //

jQuery(function() {
	
	jQuery('#login-button') .click(function() {
		jQuery('#login-box') .slideDown(100);
	});
	
	jQuery('#close-login') .click(function() {
		jQuery('#login-box') .slideUp(100);
	});

});


// LOGO DESCRIPTION //

jQuery(function() {

	jQuery('#logo') .mouseover(function() {
		jQuery('#logo-desc') .stop() .animate({'opacity' : '1', 'marginLeft' : '5px'}, 100);
		jQuery('#logo-desc') .css('display', 'block');
	});
	jQuery('#logo') .mouseout(function() {
		jQuery('#logo-desc') .stop() .animate({'opacity' : '0', 'marginLeft' : '0px'}, 300);
		jQuery('#logo-desc') .css('display', 'none');
	});
});


// MAIN MENU //

jQuery(function() {
	jQuery('#main-menu li ul') .parent() .children('a') .addClass('has-submenu');
	
	jQuery('#main-menu li').hoverIntent(function() {
		jQuery(this) .children('ul') .stop(true, true) .slideDown(100);
	}, function() {
		jQuery(this) .children('ul') .stop(true,true) .slideUp(80);
	});
	
	jQuery('#main-menu li') .find('li.current-menu-item') .parents('li') .addClass('current-parent');
	
	jQuery('#main-menu li ul li ul') .parent() .addClass('sub-has-sub');

});


// SIDEBAR MENU //

jQuery(function() {

	jQuery('#sidebar-menu li ul') .parent() .children('a') .addClass('has-submenu');
	jQuery('#sidebar-menu li').hoverIntent(function() {
		jQuery(this) .children('ul') .stop(true, true) .slideDown(100);
	}, function() {
		jQuery(this) .children('ul') .stop(true,true) .slideUp(80);
	});
	
	jQuery('#sidebar-menu li.current-menu-item') .children('a') .addClass('current-a');
	jQuery('#sidebar-menu li.current-menu-item') .parents('li') .children('a') .addClass('current-parent');
	
	//-----------------//
	
	jQuery('ul.menu li ul') .parent() .children('a') .addClass('has-submenu');
	jQuery('ul.menu li').hoverIntent(function() {
		jQuery(this) .children('ul') .stop(true, true) .slideDown(100);
	}, function() {
		jQuery(this) .children('ul') .stop(true,true) .slideUp(80);
	});
	
	jQuery('ul.menu li.current-menu-item') .children('a') .addClass('current-a');
	jQuery('ul.menu li.current-menu-item') .parents('li') .children('a') .addClass('current-parent');

});


// SHARE THIS //

jQuery(function() {

	jQuery('.share-this-wrap') .mouseover(function() {
		jQuery('#share-social-icons') .stop() .animate({'opacity' : '1', 'marginLeft' : '10px'}, 100);
		jQuery('#share-social-icons') .css('visibility', 'visible');
	});
	jQuery('.share-this-wrap') .mouseout(function() {
		jQuery('#share-social-icons') .stop() .animate({'opacity' : '0', 'marginLeft' : '5px'}, 300);
		jQuery('#share-social-icons') .css('visibility', 'hidden');
	});
});


// PORTFOLIOS //

jQuery(function() {
	
	jQuery('.portfolio-post-wrap .portfolio-post-info') .css('display', 'none');
	
	jQuery('.scrollable') .css('overflow', 'hidden');
	jQuery('#portfolio-nav') .css('display', 'block');
	var portfolioLength = jQuery('.portfolio-page') .length;
	i = 1;
	jQuery('span.portfolio-length').replaceWith("<span class=\"portfolio-length\">OF "+portfolioLength+"</span>");
	
	jQuery('.next-portfolio') .click(function() {
		i++;
		jQuery('.portfolio-count') .contents() .remove();
		jQuery('.portfolio-count') .append(i);
	});
	
	jQuery('.prev-portfolio') .click(function() {
		i--;
		jQuery('.portfolio-count') .contents() .remove();
		jQuery('.portfolio-count') .append(i);
	});
	
	jQuery('.portfolio-post-2columns') .css({'minHeight' : 'none', 'maxHeight' : 'none'});
	jQuery('.text-out-2col') .css({'minHeight' : 'none', 'maxHeight' : 'none'});
	
	jQuery('.portfolio-post-3columns') .css({'minHeight' : 'none', 'maxHeight' : 'none'});
	jQuery('.text-out-3col') .css({'minHeight' : 'none', 'maxHeight' : 'none'});
	
	var portfolio2Length = jQuery('.portfolio-post-2columns') .length;
	i2 = 1;
	if (portfolio2Length > 1) {
		
		while (i2 < portfolio2Length) {
			jQuery(".portfolio-post-2columns:eq("+i2+")") .after('<br class="clear" />');
			i2 = i2 + 2;
		};
		
	};
	
	var portfolio3Length = jQuery('.portfolio-post-3columns') .length;
	i3 = 2;
	if (portfolio3Length > 2) {
		
		while (i3 < portfolio3Length) {
			jQuery(".portfolio-post-3columns:eq("+i3+")") .after('<br class="clear" />');
			i3 = i3 + 3;
		};
		
	};

	jQuery('.portfolio-post-2columns') .hover(function() {
		jQuery(this) .find('div.portfolio-post-info') .show();
	}, function() {
		jQuery('.portfolio-post-info') .stop(true, true) .fadeOut(200);
	});
	
	jQuery('.portfolio-post-3columns') .hover(function() {
		jQuery(this) .find('div.portfolio-post-info') .show();
	}, function() {
		jQuery('.portfolio-post-info') .stop(true, true) .fadeOut(200);
	});
	
});


// TABS //

jQuery(function() {
	
	jQuery.each(jQuery('.tabs-style1 .tabs-navigation'), function() {
		jQuery(this) .find('li:first') .addClass('current-tab');
	});
	
	jQuery.each(jQuery('.tabs-style1 .tabs-content, .tabs-style1 .tabs-content-nostyle'), function() {
		jQuery(this) .children('br') .remove();
		jQuery(this) .children('div:not(:first)') .hide();
	});
	
	jQuery('.tabs-style1 .tabs-nav li') .click(function() {
		
		var clickedTab = jQuery(this) .find('a') .attr('title');
		
		jQuery(this) .parent() .children('.tabs-nav li') .removeClass('current-tab');
		jQuery(this) .addClass('current-tab');
		
		jQuery(this) .parent() .parent() .parent() .find('.tabs-content, .tabs-content-nostyle') .children('div') .slideUp(50);
		jQuery(this) .parent() .parent() .parent() .find('.tabs-content .'+clickedTab) .slideDown(100);
		jQuery(this) .parent() .parent() .parent() .find('.tabs-content-nostyle .'+clickedTab) .slideDown(100);
		
		return false;
		
	});
	
});


// H5 TABS //

jQuery(function() {
	
	jQuery('.tabs-posts .fancy-header a:first') .addClass('current-title');
	
	jQuery('.tabs-posts .tabs-content') .children('div:not(:first)') .hide();
	
	jQuery('.tabs-posts .fancy-header a') .click(function() {
		
		var clickedTab = jQuery(this) .attr('title');
		
		jQuery(this) .parent() .children('a') .removeClass('current-title');
		jQuery(this) .addClass('current-title');
		
		jQuery(this) .parent() .parent() .parent() .find('.tabs-content') .children('div') .hide();
		jQuery(this) .parent() .parent() .parent() .find('.tabs-content .'+clickedTab) .slideDown();
		
		return false;
		
	});
	
});


// Toggles //

jQuery(function() {
	
	jQuery('.faq-block') .children('p, br') .remove();
	jQuery('.faq-answer, .toggle-content') .css('display', 'none');
	
	jQuery.each(jQuery('.toggle-block'), function() {
		jQuery(this) .children('br') .remove();
	});
	
	jQuery('.faq-q, .toggle-t') .click(function() {
		jQuery(this) .toggleClass('toggle-open');
		jQuery(this) .next('.faq-answer, .toggle-content') .slideToggle(100);
	});
	
	jQuery('.toggle-block .box-title-style-1, .toggle-block .box-title-style-2') .click(function() {
		jQuery(this) .next('.toggle-block .box-text') .slideToggle(100);
	});
	
	jQuery('.toggle-block .box-title-style-1, .toggle-block .box-title-style-2') .hover(function() {
		jQuery(this) .prev('span.handle') .css('display', 'block');
	}, function() {
		jQuery(this) .prev('span.handle') .css('display', 'none');
	});
	
});


// Zoom, paly, read, flickr icons //

jQuery(function() {
	
	jQuery('a.zoom-img') .hover(function() {
		jQuery(this) .find('span.zoom-wrap') .css('display', 'block');
		jQuery(this) .find('span.zoom-wrap') .hide() .slideDown(250);
	}, function() {
		jQuery(this) .find('span.zoom-wrap') .slideUp(200);
	});
	jQuery('a.play-img') .hover(function() {
		jQuery(this) .find('span.play-wrap') .css('display', 'block');
		jQuery(this) .find('span.play-wrap') .hide() .slideDown(250);
	}, function() {
		jQuery(this) .find('span.play-wrap') .slideUp(200);
	});
	jQuery('a.read-img') .hover(function() {
		jQuery(this) .find('span.read-wrap') .css('display', 'block');
		jQuery(this) .find('span.read-wrap') .hide() .slideDown(250);
	}, function() {
		jQuery(this) .find('span.read-wrap') .slideUp(200);
	});
	
	jQuery('.video-lightbox') .hover(function() {
		jQuery(this) .find('span.play-lightbox-wrap') .css('opacity', '0.8');
	}, function() {
		jQuery(this) .find('span.play-lightbox-wrap') .css('opacity', '0.6');
	});
	
});


// FOOTER //

jQuery(function() {
	
	var footer1Length = jQuery('.col-option1 .footer-column') .length;
	var footer2Length = jQuery('.col-option2 .footer-column') .length;
	var footer3Length = jQuery('.col-option3 .footer-column') .length;
	var footer4Length = jQuery('.col-option4 .footer-column') .length;
	var footer5Length = jQuery('.col-option5 .footer-column') .length;
	
	i1footer = 0;
	i2footer = 1;
	i3footer = 2;
	i4footer = 3;
	i5footer = 4;
	
	if (footer1Length > 1) {
		while (i1footer < footer1Length) {
			jQuery(".col-option1 .footer-column:eq("+i1footer+")") .after('<br class="clear" />');
			i1footer = i1footer + 1;
		};
	};
	
	if (footer2Length > 2) {
		while (i2footer < footer2Length) {
			jQuery(".col-option2 .footer-column:eq("+i2footer+")") .after('<br class="clear" />');
			i2footer = i2footer + 2;
		};
	};
	
	if (footer3Length > 3) {
		while (i3footer < footer3Length) {
			jQuery(".col-option3 .footer-column:eq("+i3footer+")") .after('<br class="clear" />');
			i3footer = i3footer + 3;
		};
	};
	
	if (footer4Length > 4) {
		while (i4footer < footer4Length) {
			jQuery(".col-option4 .footer-column:eq("+i4footer+")") .after('<br class="clear" />');
			i4footer = i4footer + 4;
		};
	};
	
	if (footer5Length > 5) {
		while (i5footer < footer5Length) {
			jQuery(".col-option5 .footer-column:eq("+i5footer+")") .after('<br class="clear" />');
			i5footer = i5footer + 5;
		};
	};
	
	jQuery('.col-option5-4 .footer-column:eq(3)') .css('width', '354');
	jQuery('.col-option54- .footer-column:eq(0)') .css('width', '354');
	jQuery('.col-option4-3 .footer-column:eq(2)') .css('width', '440');
	jQuery('.col-option43- .footer-column:eq(0)') .css('width', '440');
	
});


// Contact Form //

jQuery(function() {
	
	var templatePath = jQuery('.contact-form') .attr('title');
	jQuery.each(jQuery('.contact-form'), function() {
		jQuery(this) .attr('title', '');
	});
	
	jQuery('.submitemail') .click(function(visitoremail) {
		
		var $this = jQuery(this) .parent() .parent();
		
		var visitorname = $this .find('input.visitorname') .val();
		var visitoremail = $this .find('input.visitoremail') .val();
		var visitormessage = $this .find('textarea.visitormessage') .val();
		var thedawnfield = $this .find('input.theDawnfield') .val();                                                                                  
		
		var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
		var validEmail = emailPattern.test(visitoremail);
		
		if (visitorname.length < 2 || visitorname == 'Name') {
			$this .find('input.visitorname') .effect('shake', { times:2, distance:10 }, 100);
			$this .find('input.visitorname') .animate({'borderColor' : '#cc0f16'}, 500, function() {
				$this .find('input.visitorname') .delay(1000) .animate({'borderColor' : '#e1e4e9'}, 500);
			});
			var nameValid = 'NO';
		} else if (visitoremail == '' || validEmail == false) {
			$this .find('input.visitoremail') .effect('shake', { times:2, distance:10 }, 100);
			$this .find('input.visitoremail') .animate({'borderColor' : '#cc0f16'}, 500, function() {
				$this .find('input.visitoremail') .delay(1000) .animate({'borderColor' : '#e1e4e9'}, 500);
			});
			var emailValid = 'NO';
		} else if (visitormessage.length < 2) {
			$this .find('textarea.visitormessage') .effect('shake', { times:2, distance:10 }, 100);
			$this .find('textarea.visitormessage') .animate({'borderColor' : '#cc0f16'}, 500, function() {
				$this .find('textarea.visitormessage') .delay(1000) .animate({'borderColor' : '#e1e4e9'}, 500);
			});
			var messageValid = 'NO';
		}
		
		if ( nameValid != 'NO' && emailValid != 'NO' && messageValid != 'NO' && thedawnfield == '' ) {
			
			$this .find('.contact-form-loader') .show();
			
			jQuery.ajax({
				type: 'POST',
				url: templatePath+'/lib/scripts/sendEmail.php',
				data: 'visitorname=' + visitorname + '&visitoremail=' + visitoremail + '&visitormessage=' + visitormessage,
				
				success: function(contactResults) {
					$this .find('div.response') .html(contactResults) .slideDown();
					$this .find('.contact-form-loader') .hide();
				}
			
			});
		}
	});
});


// Twitter Widget //

(function(jQuery){
	
	jQuery.fn.twitterwidget = function(options) {
		var defaults = {
			twitterUser: 'mohdbiz',
			tweetsCount: 3
		},
		settings = jQuery.extend({}, defaults, options);
		
		if (jQuery('.recent-tweets') .length != 0) {
			triggerTwitter();
		}

		function triggerTwitter() {
			jQuery('.recent-tweets') .empty();
			jQuery('.recent-tweets') .parent() .find('h4') .css('position', 'relative');
			jQuery('.recent-tweets') .parent() .find('h4') .append('<span class="tweets-load"></span>');
			
			var numofTweets = settings.tweetsCount;
			numofTweets = numofTweets -1;

			jQuery(window).load(function () {
			jQuery.getJSON( 'http://twitter.com/statuses/user_timeline/'+settings.twitterUser+'.json?callback=?&count=10',
				function(data) {
					jQuery.each(data, function(i) {
						var tweet = data[i].text;
						tweet = tweet.replace(/(http:\/\/\S+)/g, '<a href="$1">$1</a>');
						tweet = tweet.replace(/(@\S+)/g, '<a href="http://twitter.com/$1">$1</a>');
						tweet = tweet.replace('@', '');
						
						var tweetDate = data[i].created_at;
						tweetDate = tweetDate.split(' ');
						var tweetFullDate = tweetDate[3] +' - '+tweetDate[0] +' '+ tweetDate[1] +' '+ tweetDate[2] +', '+ tweetDate[5];
						tweetDate = tweetDate[1] +' '+ tweetDate[2];
						
						var tweetID = data[i].id_str;
						var tweetStatus = 'http://twitter.com/'+settings.twitterUser+'/status/'+tweetID;
						
						jQuery('#sidebar-content .recent-tweets, #big-footer .recent-tweets') .append('<li>'+tweet+'<span class="recent-tweets-date"><a href="'+tweetStatus+'" title="'+tweetFullDate+'">'+tweetDate+'</a></span></li>');
						
						if ( i == numofTweets ) return false;
					})
					jQuery('.recent-tweets') .hide() .slideDown();
					jQuery('.recent-tweets') .parent() .find('.tweets-load') .hide();
					jQuery('.recent-tweets') .find('li:last') .css({'border' : 'none', 'marginBottom' : '0px'});
				}
			);
			});
		}
	}
	
})(jQuery);


// Flickr Widget //

jQuery(function() {

	if(jQuery('.flickr-photos') .length != 0) {
		
		jQuery('.flickr-photos') .parent() .find('h4') .css('position', 'relative');
		jQuery('.flickr-photos') .parent() .find('h4') .append('<span class="flickr-load"></span>');
		
		triggerFlickr();
	}
	
	function triggerFlickr() {
	
	if (jQuery('.flickr-photos') .attr('title')) {
		var flickrUserInput = jQuery('.flickr-photos') .attr('title');
		var flickrId = flickrUserInput.split('/')[0];
		var numofFlickrPhotos = flickrUserInput.split('/')[1];
		numofFlickrPhotos = numofFlickrPhotos -1;
		var groupPhotos = flickrUserInput.split('/')[2];
		var pool_public;
		if (groupPhotos == 'group') { pool_public = 'groups_pool'; } else { pool_public = 'photos_public'; }
	}

	if (flickrId == '') {
		jQuery('.flickr-photos') .parent() .find('.flickr-load') .hide();
		jQuery('#sidebar-content .flickr-photos, #big-footer .flickr-photos') .html('<p>Please set a flickr user!</p>');
	}
	else { jQuery(window).load(function () {
		jQuery.getJSON( 'http://api.flickr.com/services/feeds/'+pool_public+'.gne?id='+flickrId+'&lang=en-us&format=json&jsoncallback=?', function(data) {
			
			jQuery.each(data.items, function(i, item) {
				var photoTitle = item.title;
				var photoSrc = (item.media.m).replace("_m.jpg", "_s.jpg");
				var photoURL = item.link;
				jQuery('#sidebar-content .flickr-photos, #big-footer .flickr-photos') .append('<li><a class="flickr-img load-img" target="_blank" href="'+photoURL+'" title="View on flickr: '+photoTitle+'"><img src="'+photoSrc+'" width="75" height="75" /><span class="flickr-wrap"></span><span class="img-load-wrap"></span></a></li>');
				
				if ( i == numofFlickrPhotos ) return false;
			})
			
			jQuery('.flickr-photos') .hide() .slideDown();
			jQuery('span.flickr-wrap') .css('display', 'none');
			jQuery('.flickr-photos') .parent() .find('.flickr-load') .hide();
			
			jQuery('.flickr-photos a.load-img img').one("load",function(){
				jQuery(this) .parent() .find('span.img-load-wrap') .css('display', 'none');
				jQuery(this) .hide() .fadeIn();
			})
			.each(function(){
			if(this.complete) jQuery(this).trigger("load");
			});
			
			jQuery('a.flickr-img') .hover(function() {
				jQuery(this) .find('span.flickr-wrap') .css('display', 'block');
			}, function() {
				jQuery(this) .find('span.flickr-wrap') .css('display', 'none');
			});
			
			jQuery('.flickr-photos') .find('li:last') .css({'border' : 'none', 'marginBottom' : '0px'});
		
		});
	});
	}
	}
	
});


jQuery(function() {
	// when header-intro is disabled - ie bug fix
	$headerIntro = jQuery('#pre-body-area') .html();
	if ( $headerIntro == '' ) {
		jQuery('#pre-body-area') .css('display', 'none');
	}
});
