//projectID = getHashValue('id');
$(document).ready(function(){
  iZindex = 500;
	$('div#header_nav ul li').each(function(){
	  $(this).css('z-index',iZindex);
	  iZindex--;
	});
	/* -- dynamic thumbnail clicks -- now disabled
  $('#thumbnail-panels a').click(function(){
  	strID = $(this).attr('rel');
  	strHREF = $(this).attr('href');
  	if (strID) {
  		iCurrentProject = strID;
	  	changeProject();
  	}
  	//self.document.location.hash = strHREF;
    return false;
  });
  */
  // Portfolios Toggle
  $('.showPortfolioGrid').click(function(){
    //$(this).toggleClass('highlight');
    $('.categories').toggle();
    return false;
  });
  
  // Read Description
  $('.read-more').click(function(){
    strBlurbID = $(this).attr('href');
    if ($(strBlurbID).is(':visible')) {
    	$(this).html('Read More');
    	$(strBlurbID).slideUp('fast');
    } else {
    	$(this).html('Read Less');
    	$(strBlurbID).slideDown('fast');
    }
    return false;
  });
  
  $('.display .nav a:not(.images .nav a)').click(function(){
    $('.blurb .blurb-more').hide();
  });
  
	// Image nav
	$('.large-image div[rel]').hide();
	$('.large-image div[rel=1]').show();
	
	$('.images .nav a').click(function(){
		//get the newly selected slide
	  var selectedProjectID = $(this).attr('href');
	  var selectedImage = $(this).attr('rel');
	  
	  //Hide all slides
	  $(selectedProjectID+' div').hide();
	  
	  stopMovies();
	  
		//Show selected slide
	  $(selectedProjectID+' div[rel='+selectedImage+']').show();
	  
	  //currentSlideID = selectedProjectID + '-' + selectedImage;
	  return false;
	});
	
	// Next project
	/*
	$('.project_next').click(function(){
	  iCurrentProject++;
	  if (iCurrentProject > iTotalProjects) iCurrentProject = 1;
	  changeProject();
	  return false;
	});
	*/
	// Prev project
	/*
	$('.project_prev').click(function(){
	  iCurrentProject--;
	  if (iCurrentProject < 1) iCurrentProject = iTotalProjects;
	  changeProject();
	  return false;
	});
	*/
	
	//Project Thumbnail nav
	$('#thumbnail-panels').cycle({
		fx:		'scrollHorz',
		speed:300,
		next: '#panel_next',
		prev: '#panel_prev',
		pager:'#panel_pager',
		timeout: 0,
		nowrap: 1,
		containerResize: 1
	});
	
	$('#thumbnail-panels table').show();
});

/*
function changeProject() {
	//Reset Read More links
	$('.blurb-more').hide();
	$('.read-more').html('Read More');
	
	$('#display-cycle .project').hide();
  $('#display-cycle .project[rel='+iCurrentProject+']').show();
  
  $('#thumbnail-panels a').removeClass('active');
  $('#portfolio-thumb-'+iCurrentProject).addClass('active');
  
  thisPanel = Math.ceil(iCurrentProject/iProjectsPerPage);
  
  $('#panel_pager a:nth-child('+thisPanel+')').click();
  
  stopMovies();
}
*/
function fnprevNextClick(isNext, slideIndex, slideElement) {
  //console.log('change project: '+slideIndex);
  slideIndex = slideIndex + 1;
	$('#thumbnail-panels a').removeClass('active');
  $('#portfolio-thumb-'+slideIndex).addClass('active');
}

function getHashValue(key, default_) {
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\#&]"+key+"=([^&#]*)");
  var qs = regex.exec(self.document.location.hash);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

function stopMovies() {
	$('.qtmovie').each(function(){
		try {
			this.Stop();
		} catch(e) {}
	});
}