(function($) {

jQuery(document).ready(function(){
	
	/*if ($('#cboxLoadedContent .images').length > 0) {
	    $('.cycle_btn').show();
		$('#cboxLoadedContent .images').cycle({ 
			fx:      'growY', // transition type
			timeout: 5000,
			speed: 1200,
			pause: 0,
			pauseOnPagerHover: 1,
			pager: ".pager",
			backwards: false,
			next: '.cycle_next',
			prev: '.cycle_prev'
		});
	}*/
	
	
	$('#read_more_about').click(function(){
		$('#navigation .about').trigger('click');									 
	});
	
	 $('.portfolio-thumbs .thumb').hover(
		function(){
			$('.portfolio-thumbs .thumb').addClass('trans');
			$(this).removeClass('trans').addClass('hover');
			$('.trans').animate({opacity:'0.3'},{queue:false,duration:300});
		},
		function(){
			$('.hover').removeClass('hover');
			$('.portfolio-thumbs .trans').animate({opacity:'1'},{queue:false,duration:300}).removeClass('trans');
		}								  
	);
	
	$('.featured .colorbox, .portfolio-thumbs a.thumb').colorbox({
			//width: "95%",
			height: "451px",
			width: "980px",
			speed: 200,
			fastIframe: false,
			initialWidth: "350",
			initialHeight: "250",
			onComplete: runProjectCycle,
			onLoad: stopProjectCycle,
			onClosed: stopProjectCycle
		});
	
	$('#cboxPrevious, #cboxNext, #cboxClose, #cboxOverlay').click(function(){
		$('#cboxLoadedContent .images').cycle('destroy');						  
	});
	
	/*if ($('.Projects .projects').length > 0) {
		$('#work .cycle_btn').show();
		$('.Projects .projects').css({overflow:'hidden', height: '282px'});
		$('div.projects div.item').css({marginBottom: '125px'});
		$('.Projects .projects').cycle({ 
			fx: 'scrollHorz', 
			timeout: 0,
			speed: 500,
			pause: 1,
			pauseOnPagerHover: 1,
			allowPagerClickBubble: false,
			pager: ".pager",
			backwards: false,
			next: '.cycle_next',
			prev: '.cycle_prev'
		});
	}*/
	
	runProjectCycle();
	activateProjectColorbox();
	
	var ajax_load = '<div class="loading"></div>';
	$(".Project .cycle_prev, .Project .cycle_next").live('click',function(e){
		e.preventDefault();
		if($('.loading').length == 0){
			var url = $(this).attr('rel');	
			var projectID = $(this).attr('id').replace('project', '');
			$("#content").append(ajax_load);
			$(".thumbs").fadeOut(1000);
			$(".cycle_btn").remove();
			$(".loading").animate({ opacity: 1}, 1000, function(){
				$.get(
					url,
					function(responseText){
						$('.Project .images').cycle('destroy');
						$(".col1,.col2").remove();
						$("#content").append(responseText);
						runProjectCycle();
						$(".loading").css({ background: 'black' });
						$(".loading").animate({ opacity: 0}, 500, function(){
							$(this).remove();
							activateProjectColorbox();
							/*$.get(
								  'work/getSiblingData/'+projectID,
								  function(data){
									if(data.next['id']){
										$('.cycle_next').attr({
											id: 'project'+data.next['id'],
											href: data.next['link'],
											rel: data.next['rel'],
											title: data.next['title']
										});
									}
									//console.log(data.next['id']);	  
								  },
								  "json"
							);*/
							
						});
						
					},
					"html"
				);
			});
		}
	});

	
	/*$('h1').click(function(){
						   console.log('yeah');
			$('body').animate({
				backgroundColor: '#ffffff'
			  }, 600, function() {
				$('#main-nav').animate({
				backgroundColor: '#f1f1f1'
			  }, 600, function() {
				$(this).css({borderColor: '#cccccc'});
				$('p.company').animate({
					color: '#000000'
				  }, 600, function() {
					// Animation complete.
				  });
				//$('h1').css({color: '#cccccc'});
			  });
				$('#footer').animate({
				backgroundColor: '#f1f1f1'
			  }, 600, function() {
				// Animation complete.
			  });
		  });
		

	});
	*/
	
	
});

function runProjectCycle(){
	if ($('.images').length > 0) {
		$('.images').cycle({ 
			activePagerClass: 'active',						
			fx:      'growX', // transition type
			timeout: 5000,
			speed: 300,
			pause: 1,
			pauseOnPagerHover: 1,
			pager: ".thumbs",
			backwards: false,
			pagerAnchorBuilder: function(idx, slide) { 
				//console.log($(slide).find('img'));
				return '<a href="#"><img src="' + $(slide).find('img').attr("src") + '" width="60" height="47" /></a>'; 
			} 
		});
	}
}

function activateProjectColorbox(){
	if($('.Project .img').length > 0){
		$('.Project .img').colorbox({
			//width: "95%",
			height: "95%",
			transition: 'none',
			speed: 200
		});	
	}
}

function stopProjectCycle(){
	if($('#cboxLoadedContent .images').length > 0){
		$('#cboxLoadedContent .images').cycle('destroy');
		$('#cboxLoadedContent .images').remove();
	}
}


})(jQuery);

function resetField(field){
	if (field.value=="Search..." || field.value=="DD" || field.value=="MM" || field.value=="YYYY"){
		field.value="";	
		return false;
	}
}




