$(document).ready(function(){$(".single").colorbox();$("a[rel='graphic-gallery']").colorbox();$("a[rel='illus-gallery']").colorbox();$("a[rel='brand-gallery']").colorbox();$("a[rel='web-gallery']").colorbox();$("a[rel='photo-gallery']").colorbox();$("a[rel='motion-gallery']").colorbox();$(".video-gal").colorbox({iframe:true,innerWidth:"75%",innerHeight:"75%"});$('small#view-resume a').click(function(){$('section#cv').fadeTo("slow",0.85);$('body').addClass('fixed');$('#wrapper-content').addClass('all-fixed');$('#nav-first-child').css("visibility","hidden")});$('.close-btn').click(function(){$('section#cv').fadeOut("slow");$('body').removeClass('fixed');$('#wrapper-content').removeClass('all-fixed');$('#nav-first-child').css("visibility","visible")});$('li.work-item').hover(function(){$(this).find('div.work-caption').stop(false,true).css("visibility", "visible").fadeIn("fast")},function(){$(this).find('div.work-caption').stop(false,true).fadeOut("slow")});$("nav").hover(function(){$(this).find("li.fade-option").stop().animate({left:"25",opacity:1},"fast").css("visibility","visible")},function(){$(this).find("li.fade-option").stop().animate({left:"0",opacity:0},"meddium").css("display","inline")})
	
		var wrapper = $(".work-caption");
		var theItem =$(".work-caption h3");
		var contHeight=$(wrapper).height();
		var contMiddle=contHeight/2;
		var titleMiddle=$(".work-caption h3").height()/2;
		var theMiddle=contMiddle-titleMiddle;

		$('.work-caption').each(function(i) {
			var wh = $(this).height();
			var ih = $('h3', this).height();
			
			if (wh > ih) {
			$('h3', this).css('margin-top', (wh-ih)/2 + 'px');
			} else {
			$('h3', this).css('margin-top',0);
			}
		});
		
		var $paneTarget = $('#list-works');
		$('.works-filters li a').click(function(){
		var categoria = $(this).attr('href').substr(1);
		var $target = $paneTarget.find('li:eq(0)');
		$paneTarget.stop().scrollTo( $target , 800 );
		addBreakClass(categoria);
		});
		
		function addBreakClass(target) {
			var visibles = 0;	
			$('#list-works li').each(function() {	
			$(this).removeClass('break');	
			if (target=='all' || $(this).hasClass(target)) {
			visibles++;
			if (visibles==1 || visibles%20 == 0 ) $(this).addClass('break');
			}	
			});
		}
		addBreakClass('all');
		
//FADE PRELOADING IMAGES FUNCTION


// Run it!
targetImages = $('#list-works a img');
targetImages.imgFolioloader();


	//DETECT iPad/iPhone devices for manage fixed position elements
	var deviceAgent = navigator.userAgent.toLowerCase();
	var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
	if (agentID) {
        $('#theme-wrapper').delay('200').remove();
 		$('section#cv{').css('width','120%');
		$('#cboxOverlay').css({'width': '110%', 'height': '250%'});
	}
//$( window ).scroll( function ( ) { $( "#theme-wrapper" ).css( "top", ( $( window ).height() + $( document ).scrollTop() - 90 ) +"px" );  } );

	//	//stick the footer at the bottom of the page if we're on an iPad/iPhone due to viewport/page bugs in mobile webkit
//if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
//{
//     $("#theme-wrapper").css("position", "static");
//};

});
