$(function(){
	  
	  $(window).hashchange( function(e){
		  e.preventDefault()  
		  
		var hash = window.location.hash;
		  
	    if(hash=="#hash")
	    	return false
	    	
	 	if(hash.match("collection")){
	 		_class= hash.toString().getURI()
     		$("li").removeClass("selected")
     		$('#nav li p').removeClass('selected');
    		$("." + _class).parent().addClass("selected")
		try{
	    		_parent=$("." + _class).parent().parent().parent().attr('class').split(" ")
	    		$("." + _parent[0] + " p").addClass("selected")
		}catch(err){
			//could be this season so lets just highlight that instead
			$("#thisseason").addClass("selected")
		}		
    		getCollection(_class);
    	}
	  })
	  
	  $(window).hashchange();

	  return false;
	  
	});


$(document).ready(function() {
	if($("#content").attr("class")=="thisseason")
		getThisSeason()
	_nav=$("#content").attr("class")
	if(_nav!="gallery"){
		$('#nav li p').removeClass('selected');
		$("#" + _nav).addClass("selected");
	}else
		$('#home').removeClass('selected');
	  
});

function getCollection(get){
	$.ajax({
		url: '/collection/' + get + "/json",
		type: "GET",
		dataType: "json",
		success: function(data) {
			collectionIndex = 0;
			collectionArray = new Array();
			sortCollection(data);
			renderCollection(get);		
		}
	});
}

function getThisSeason(){
	$.get("/thisseason/json", function(data){
		$('#content').html();
		collectionIndex = 0;
		collectionArray = new Array();
		sortCollection(data);
		renderCollection();			
		return true;
	});
}


