﻿/* greatapts functions */


// called when a page is loaded, put all initialize stuff here
function initPage() {
	div = $("#accordion_sub");
	
	/*
	$("#accordion_header").css('background-image', "url(" + t_p + "/images/down.gif)");
	
	$('#accordion_header').click(function(){
       if (div.is(':hidden')) { 
           showGalleryMenu();
       } else { 
		   hideGalleryMenu();
	 }	 
       return false;
   });
   */
}

// setup function for gallery pages
function displayGallery () {
	
	$("#accordion_sub").css('display','block').css('visibility','visible');
	//$("#accordion_header").css('background-image', "url(" + t_p + "/images/up.gif)");
	
	// resize all the images so they're nice and proportional
	resizeImg("#galleryImg,#galleryImg",[155,135]);  
}

function showGalleryMenu() {
	// show the gallery sidebar submenu
	
	$("#accordion_sub").slideDown(); //.css('display','block').css('visibility','visible');
	$("#accordion_header").css('background-image', "url(" + t_p + "/images/up.gif)");
}

function hideGalleryMenu () {
	
	$("#accordion_sub").slideUp(); //.css('display','none').css('visibility','hidden');
	$("#accordion_header").css('background-image', "url(" + t_p + "/images/down.gif)");

}

// resize images constrained to a certain size while maintaining
//  the images proportions
function resizeImg (id,max_size) {
	var max_w, max_h;
	if (max_size.length > 1) {
		max_w = max_size[0];
		max_h = max_size[1];
	} else {
		max_w = max_h = max_size;
	}

	$(id).each(function(i) {
	  var h,w;
	  var t = $(this);
	  if ($(this).height() > $(this).width()) {
	  	h = max_h;
	    w = Math.ceil($(this).width() / $(this).height() * max_h);
	  } else {
	    w = max_w;
	    h = Math.ceil($(this).height() / $(this).width() * max_w);
	  }
	 $(this).css({ 'height': h, 'width': w });
	});
}
