var port = {
	current_image: 0,
	current_total_images: 0,
	// SITE PAGES
	sitepages: $.sammy(function() { with(this) {
	// INITIAL STATE
		route('get','#/', function() { with(this) {
			port.next_back(false);
			port.highlight_nav('about-me');
			port.intro_transition('intro');
			
		}});
		route('get','#/about-me', function() { with(this) {}});
		route('get','#/contact', function() { with(this) {}});
		route('get','#/print', function() { with(this) {
			port.gallery_transition("print");
			port.highlight_nav('print');
			port.current_image = 0;
			port.current_total_images = port_copy['print'].length - Math.round($(window).width() / 588);
		}});
		route('get','#/identity', function() { with(this) {
			port.gallery_transition("identity");
			port.highlight_nav('identity');
			port.current_image = 0;
			port.current_total_images = port_copy['identity'].length - Math.round($(window).width() / 588);			
		}});
		route('get','#/web-design', function() { with(this) {
			port.gallery_transition("web-design");
			port.highlight_nav('web-design');
			port.current_image = 0;
			port.current_total_images = port_copy['web-design'].length - Math.round($(window).width() / 588);			
		}});
		route('get','#/product-design', function() { with(this) {
			port.gallery_transition("product-design");
			port.highlight_nav('product-design');
			port.current_image = 0;
			port.current_total_images = port_copy['product-design'].length - Math.round($(window).width() / 588);			
		}});
		route('get','#/music', function() { with(this) {
			port.gallery_transition("music");
			port.highlight_nav('music');
			port.current_image = 0;
			port.current_total_images = port_copy['music'].length - Math.round($(window).width() / 588);			
		}});
	}}),

next_back: function(on){
	if(on){
		$('div#port-navigation').css('display','block')
	}else{
		$('div#port-navigation').css('display','none')
	}
},

highlight_nav:function(pagename){
	$('div#nav a').removeClass();
	$('div#nav a#nav-link-'+pagename).addClass('selected');
},

gallery_transition: function(pagename){
	port.next_back(true);
	var $copy = $('div#copy');
	var $images = $('div#images');
	var imageHTML = "";
	var copyHTML = "";
	$copy.fadeTo('fast', 0, function(){
		$images.slideUp({ duration: 1000, easing: "easeInOutExpo", complete: function(){
			$('div#content-area').removeClass().addClass(pagename);
			$images.html(imageHTML);
			$copy.html(copyHTML);
			var wrapper_size = 0;
			for(i in port_copy[pagename]){
				imageHTML += '<a href="portfolio/'+pagename+'/large/image'+i+'.jpg" id="image-'+i+'" class="port-image" style="background:url(portfolio/'+pagename+'/small/image'+i+'.jpg);"></a>';
				copyHTML += '<div class="port-copy"><h2>'+port_copy[pagename][i]['title']+'</h2><p>'+port_copy[pagename][i]['copy']+'</p></div>';
				wrapper_size += 588;
			}
			imageHTML+='<div style="clear:both;"></div>';
			copyHTML +='<div style="clear:both;"></div>';
			
			$("div#wrapper").css({"marginLeft":0,"width":wrapper_size});
			$images.html(imageHTML);
			$images.children().nyroModal();
			$copy.html(copyHTML);
			$images.slideDown({ duration: 1000, easing: "easeInOutExpo", complete: function(){
				$copy.css('display','block').fadeTo('fast',1);
			}});
		}});
	});
},
intro_transition: function(pagename){
	port.next_back(false);
	var $copy = $('div#copy');
	var $images = $('div#images');
	var imageHTML = "";
	var copyHTML = "";
	$copy.fadeTo('fast', 0, function(){
		$images.slideUp({ duration: 1000, easing: "easeInOutExpo", complete: function(){
			$("div#wrapper").css("marginLeft",0);
			$('div#content-area').removeClass().addClass(pagename);
			$copy.html(port_copy.intro);
			$copy.css('display','block').fadeTo('fast',1);
		}});
	});
}

};
$(function() {
  port.sitepages.run('#/');
	$('a').live('click',function(){
		$(this).blur();
	});
	$('a#next').click(function(){
		if(port.current_image != port.current_total_images){
			port.current_image += 1;
			$('div#wrapper').animate({'marginLeft':"-"+(588 * port.current_image)},150,"easeInOutExpo");
		}else{
			port.current_image = 0;
			$('div#wrapper').animate({'marginLeft':0},350,"easeInOutExpo");			
		}
		$(this).blur();
		return false;
	});
	$('a#prev').click(function(){
		if(port.current_image != 0){
			port.current_image -= 1;
			$('div#wrapper').animate({'marginLeft':"-"+(588 * port.current_image)},150,"easeInOutExpo");
		}	else{
				port.current_image = port.current_total_images;
				$('div#wrapper').animate({'marginLeft':"-"+(588 * port.current_total_images)},350,"easeInOutExpo");
			}
		$(this).blur();
		return false;
	});
});


