/* MAINLINE MEDIA */
/* Javascript Functions
--------------------------------------------------------------------------- */


	$(document).ready(function() {
	
		markup();
		billboard();
		twitter();

	});
	
	$(window).load(function() {
	
		clients();
		
	});
	
	
/* JQUERY EXTENSIONS
--------------------------------------------------------------------------- */

	
	$.expr[':'].icontains = function(obj, index, meta, stack){
	return (obj.textContent || obj.innerText || jQuery(obj).text() || '').toLowerCase().indexOf(meta[3].toLowerCase()) >= 0;
	};


/* FUNCTION: MARKUP CHANGES
--------------------------------------------------------------------------- */


	function markup() {
	
	
/* Navigation Item Classes */	
	
	
		$('#navigationBottom ul.content-navigation').each(function() {
		
			$(this).find('a:icontains("lowdown")').closest('li').addClass('lowdown');
			$(this).find('a:icontains("services")').closest('li').addClass('services');
			$(this).find('a:icontains("portfolio")').closest('li').addClass('portfolio');
			$(this).find('a:icontains("case studies")').closest('li').addClass('casestudies');
			$(this).find('a:icontains("blog")').closest('li').addClass('blog');
			$(this).find('a:icontains("behind the scenes")').closest('li').addClass('scenes');
			$(this).find('a:icontains("faq")').closest('li').addClass('faqs');
			$(this).find('a:icontains("contact")').closest('li').addClass('contact');

			$(this).find('a:icontains("home")').closest('li').addClass('hide');
			$(this).find('a:icontains("log in")').closest('li').addClass('hide');
			$(this).find('a:icontains("hidden")').closest('li').addClass('hide');

		});
		
		
/* Alternate Layouts */


		if ($('div.fullwidth').length > 0) {
		
			$('body').addClass('full');
		
		}
		
		
/* Make Logo Clickable in IE7 */


		$('#bannerAreaWrapper').insertAfter('#pageHeader > #navigationBottom');

	
	}

	
/* FUNCTION: BILLBOARD
--------------------------------------------------------------------------- */


	function billboard() {
	
		$('#billboard').each(function() {
		
			// Move billboard outside content column
			$(this).prependTo('#pageBody');
			$(this).children().wrapAll('<div></div>');
			$(this).show();
				
			if ($(this).children('div').children().length > 1) {
			
				// Add paging buttons
				$(this).append('<a href="#" class="paging prev">Prev</a><a href="#" class="paging next">Next</a>');
				
				// Slideshow
				$(this).children('div').cycle({
				
					fx: 'scrollHorz',
					speed: 400, 
					timeout: 5000,
					pause: 1,
					prev: '.paging.prev',
					next: '.paging.next'
				
				});
				
			}
			
		});
	
	}
	
	
/* FUNCTION: TWITTER
---------------------------------------------------------------------------- */

	
	function twitter() {
	
		if ($('#twitter').length > 0) {
		
			$('#twitter').tweet({
			
				username: 'mainlineonline',
				count: 1,
				avatar_size: 28,
				loading_text: 'loading tweets...'
				
			});
			
		}
		
	}
	
	function twitterCallback() {
	
		// Add Follow Link
		var image = $('.tweet_avatar img').attr('src');
		$('#twitter').append('<a class="follow" href="http://twitter.com/mainlineonline" target="_blank"><img src="' + image + '" />Follow Mainline Media on Twitter</a>');
		
	}
	
	
/* FUNCTION: CLIENTS
---------------------------------------------------------------------------- */


	function clients() {

		var width = 0;
		$('#clients img').each(function() { width += $(this).width(); });
		$('#clients > div').css('width', width + 'px');
		$('#clients').css('visibility', 'visible');
		
		$jScroller.config.refresh = 50;
		$jScroller.add('#clients', '#clients > div', 'left', 2);
		$jScroller.start();
	
	}
