var $ = jQuery.noConflict();
$(document).ready(function(){

//try{ console.log('global '); }catch(e){}

	//grid layout
	if ($('#blog-thumbs').length > 0){
		$('#blog-thumbs').masonry({
			singleMode: true, 
			itemSelector: '.item'//,
			//appendedContent: $('#blog-thumbs'),
			/*animate: false,
			animationOptions: {
			duration: 750,
			easing: 'linear',
			queue: false
			}*/
		});
	}
	
	if ($('#work-thumbs').length > 0){
		$('#work-thumbs').show().masonry({
			singleMode: true, 
			itemSelector: '.item:not(.invis)',
			animate: true,
			animationOptions: {
				duration: 500,
				queue: true
				}
		});
	}
	
	//hide tooltips
	$('img, a').attr('title','');
	
	//twitter reply links hover animation
	$('#twitter-feed').find('.feed-item').hover(
		function() {
			$(this).find('.reply-link').fadeIn(250);
		},
		function() {
			$(this).find('.reply-link').fadeOut(250);
		});
		
	//slideshow
	if ($('#container_show').length > 0){
		$('#container_show').slideshow();
	}
	
	
	//homepage message
	if ($('body').hasClass('home')){
		setTimeout(function(e){
			$('#hp-message').slideUp(1000, "easeInOutExpo");
			//var new_top = $('#hp-message').height();
			//$('#hp-message').animate({top:-new_top},1000, "easeInOutExpo");
		},5000);
	}
	$('#close-message').bind('click',function(e){
		
		e.preventDefault();
		$('#hp-message').slideUp(1000, "easeInOutExpo");
		return false;
	});
	//set visited cookie to hide homepage message
	$.cookie('visited', 'true', { expires: 3650});//, path: '/', domain: '*.cincodesign.com'
	
	//kick start engine
	//$('#container_show').controller();

	//work and studio menu hover fade
	var hover_state_work = $('<span />').addClass('hover-state');
	var hover_state_studio = $('<span />').addClass('hover-state');
	
	$('#menu-work').find('h3 a')
		.append(hover_state_work)
		.hover(
			function(){ $(this).find('.hover-state').fadeIn(250); },
			function(){ $(this).find('.hover-state').fadeOut(250);	});
		
	$('#menu-studio').find('h3 a')
		.append(hover_state_studio)
		.hover(
			function(){ $(this).find('.hover-state').fadeIn(250); },
			function(){ $(this).find('.hover-state').fadeOut(250);	});

	//filtering
/*	if ($('#work-thumbs').length > 0){
		$('#work-thumbs').filtering();
	}*/
	
	//studio grid items
	$('.studio-grid-item').hoverIntent({
			over: showPersonInfo, 
			timeout: 0, 
			out: hidePersonInfo
		});

	function showPersonInfo(){
		var $this = $(this);
		
		//hide all others
		$('.person-info').hide();
		
		$this.find('img').animate({'opacity':'.5'}, 100, function(){
			
			$this.find('.person-info')
				.delay(1000)
				.show();
			}
		);
	}
	
	function hidePersonInfo(){
		var $this = $(this);		
		$this.find('img').animate({'opacity':'1'},100);
		$('.person-info').hide();
	}

	
	//blog-thumbs infinitescroll
	
	/*$('#blog-thumbs').infinitescroll(
		{
			debug           : true,
			nextSelector    : "#nav-below a:first",
			loadingImg      : "http://cincodesign.com/blog2010/wp-content/themes/cinco/images/ajax-loader.gif",
			loadingText     : "",
			donetext        : "",
			navSelector     : "#nav-below",
			contentSelector : "#blog-thumbs",
			itemSelector    : "#blog-thumbs .item"
		},
		function(new_elements){
//try{ console.log( '!! new blog thumbs' ); }catch(e){}

			try {
				//setTimeout(function() {
					if ($('#blog-thumbs').length > 0){
						$(new_elements).hide();//css('visibility','hidden');//hide();
						$('#blog-thumbs').masonry({
								appendedContent: $(new_elements)
							},
							function(){
								$(new_elements).fadeIn('1000') 
							});//////
						//$(new_elements).css('visibility','visible').fadeIn('1000');
					}
				//}, 1000);
			} catch(e){}
		}
	);*/
	
	//inner links & highlight on studio menu
	if ( $('body').hasClass('page-id-3461') ){
		var $inner_links = $('a[href*=#]');
		
		$inner_links.bind('click',function(){
			
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			
//console.log('# '+$target.attr('id')+' '+$(this).attr('href'));
			
			var the_url = $(this).attr('href');
			
			//animate to inner link
			if ( $target.length && $target.attr('id') ) {
				var new_top = $target.offset().top - 40;
				$('html, body').animate({scrollTop:  new_top}, 'slow');
			}
			return false;
		});
		
		$('#menu-studio').find('h3 a').css({'background-position':'0 0'});
	}

	if ( $('body').hasClass('page-id-1110') ){

		$('#menu-work').find('h3 a').css({'background-position':'0 0'});
	}

});

