$(document).ready(function() {

	//photography portfolio	
	$.getJSON("/includes/imageGalleryJson.php?category=photography", function(json){
	 	
	 	$.preload(json, {
    		base:'images/photography/thumbnails/',
		});
	 	 	
  		//console.log(json);
  	
  		i = 1;
  		j = json.length-1;
  		
  		$("div.portfolio.photography a").attr({
  			href: "/images/photography/"+json[0],
  			title: json[0]
  		});
  		$("div.portfolio.photography a img").attr({
			src: "/images/photography/thumbnails/"+json[0],
			title: json[0],
			alt: json[0]
		});
  		
  		//console.log(json[i]);
			
			$('div.portfolio.photography .portfolionext').click(function(e) {
				e.preventDefault();
				$("div.portfolio.photography a").attr({
					href: "/images/photography/"+json[i],
					title: json[i]
				});
				$("div.portfolio.photography a img").attr({
					src: "/images/photography/thumbnails/"+json[i],
					title: json[i],
					alt: json[i]
				});
				i++;
				j = i-2;
				if(i>json.length-1)
				i = 0;
				if (j<0)
				j = json.length-1;
				//console.log(i);
				}
			);
		
			$('div.portfolio.photography .portfolioprevious').click(function(e) {
				e.preventDefault();
				$("div.portfolio.photography a").attr({
					href: "/images/photography/"+json[j],
					title: json[j]
				});
				$("div.portfolio.photography a img").attr({
					src: "/images/photography/thumbnails/"+json[j],
					title: json[j],
					alt: json[j]
				});
				j--;
				i = j+2;
				if(i>json.length-1)
				i = 0;
				if (j<0)
				j = json.length-1;				
				//console.log(j);
				}			
			);
 	
	});
	
	//web-design portfolio
	$.getJSON("/includes/imageGalleryJson.php?category=web-design", function(json){
	
		$.preload(json, {
    		base:'images/web-design/thumbnails/',
		});
  	
  		//console.log(json);
  	
  		k = 1;
  		l = json.length-1;
  		
  		$("div.portfolio.web-design a").attr({
			href: "/images/web-design/"+json[0],
			title: json[0]
		});
  		$("div.portfolio.web-design a img").attr({
			src: "/images/web-design/thumbnails/"+json[0],
			title: json[0],
			alt: json[0]
		});
			
			$('div.portfolio.web-design .portfolionext').click(function(e) {
				e.preventDefault();
				$("div.portfolio.web-design a").attr({
					href: "/images/web-design/"+json[k],
					title: json[k]
				});
				$("div.portfolio.web-design a img").attr({
					src: "/images/web-design/thumbnails/"+json[k],
					title: json[k],
					alt: json[k]
				});
				k++;
				l = i-2;
				if(k>json.length-1)
				k = 0;
				if (l<0)
				l = json.length-1;
				//console.log(k);
				}
			);
		
			$('div.portfolio.web-design .portfolioprevious').click(function(e) {
				e.preventDefault();
				$("div.portfolio.web-design a").attr({
					href: "/images/web-design/"+json[l],
					title: json[l]
				});
				$("div.portfolio.web-design a img").attr({
					src: "/images/web-design/thumbnails/"+json[l],
					title: json[l],
					alt: json[n]
				});
				l--;
				k = j+2;
				if(k>json.length-1)
				k = 0;
				if (l<0)
				l = json.length-1;				
				//console.log(l);
				}			
			);
 	
	});
	
	//print-design portfolio
	$.getJSON("/includes/imageGalleryJson.php?category=print-design", function(json){
  		
  		$.preload(json, {
    		base:'images/print-design/thumbnails/',
		});
  		
  		//console.log(json);
  		
  		m = 1;
  		n = json.length-1;
  		
  		$("div.portfolio.print-design a").attr({
  			href: "/images/print-design/"+json[0],
  			title: json[0]
  		});
  		$("div.portfolio.print-design a img").attr({
  			src: "/images/print-design/thumbnails/"+json[0],
  			title: json[0],
  			alt: json[0]
  		});
			
			$('div.portfolio.print-design .portfolionext').click(function(e) {
				e.preventDefault();
				$("div.portfolio.print-design a").attr({
					href: "/images/print-design/"+json[m],
					title: json[m]
				});
				$("div.portfolio.print-design a img").attr({
					src: "/images/print-design/thumbnails/"+json[m],
					title: json[m],
					alt: json[n]
				});
				m++;
				n = i-2;
				if(m>json.length-1)
				m = 0;
				if (j<0)
				n = json.length-1;
				//console.log(i, j);
				}
			);
		
			$('div.portfolio.print-design .portfolioprevious').click(function(e) {
				e.preventDefault();
				$("div.portfolio.print-design a").attr({
					href: "/images/print-design/"+json[n],
					title: json[n]
				});
				$("div.portfolio.print-design a img").attr({
					src: "/images/print-design/thumbnails/"+json[n],
					title: json[n],
					alt: json[n]
				});
				n--;
				m = j+2;
				if(m>json.length-1)
				m = 0;
				if (n<0)
				n = json.length-1;				
				//console.log(i, j);
				}			
			);
 	
	});

	
	$('.portfolionext, .portfolioprevious').addClass('minustext');
	$('.portfolionext, .portfolioprevious').hide();
	
	$('.portfolio').bind('mouseover mouseout', 
		function(){
			var portfolioActive = $.makeArray(this.className.split(" "));
			$(	'.'+portfolioActive[0]+'.'+portfolioActive[1]+'> .portfolionext, '+
				'.'+portfolioActive[0]+'.'+portfolioActive[1]+'> .portfolioprevious'
			).toggle();
		}
	);
	
	$("a.fancybox").fancybox({
		'overlayOpacity': 0.6,
		'hideOnContentClick': false
	});
	
});