if($("#menu-item-31").hasClass("current_page_item") || 
$("#menu-item-32").hasClass("current_page_item") || 
$("#menu-item-156").hasClass("current_page_item") ||
$("#menu-item-33").hasClass("current_page_item") || 
$("#menu-item-156").hasClass("current-page-ancestor")) 
{
	$("#menu-item-26").addClass("current_page_item");
};

// cache all gallery images 
if ($("#menu-item-26").hasClass("current_page_item")) {
	$('.title').hide();
	$(".mag-jquery").each(function() {
		var img_path = $(this).attr("id");
		new Image().src = img_path;
	});
};

$(".mag-jquery").click(function() {
	var path = $(this).attr("id"); //getting path of large picture from thumbnail
	var temp_dimensions = $(this).children("img").attr("name");
	var dimensions = temp_dimensions.split('-');
	var width = dimensions[0];
	var height = dimensions[1];
	var desc = $(this).attr("title"); //getting description of picture
	var pid = $(this).children("img").attr("alt");
	
	$('#mag-image').css('display', "none");
	$('#mag-image').fadeIn(700);
	$('#mag-image').css('background-image', "url("+path+")");
	$('#mag-image').css('width', width);
	$('#mag-image').css('height', height);

	$("#desc").css('width', width);
	$('#mag-image').attr("alt", pid);

   
	//$("#mag-image").attr('src', path); //swaping large image
	$("#desc").html(desc); //swaping image description
	
	var img_h = $("#mag-image").height(); //getting image height
	$("#mag-picture-inner").css("height", img_h); //setting div height equal to image height
});

$("#prev").click(function() {
	var temp_pid = $("#mag-image").attr("alt");
	if(temp_pid != '1') {
		temp_pid--;
		var pid_ok = temp_pid;
		var path = $(".mag-jquery img[alt="+pid_ok+"]").parent("a").attr("id"); //getting path of large picture from thumbnail
		var desc = $(".mag-jquery img[alt="+pid_ok+"]").parent("a").attr("title"); //getting description of picture
		var pid = pid_ok;
		var temp_dimensions = $(".mag-jquery img[alt="+pid_ok+"]").attr("name");
		var dimensions = temp_dimensions.split('-');
		var width = dimensions[0];
		var height = dimensions[1];
 		
 		$('#mag-image').css('display', "none");
		$('#mag-image').fadeIn(700);
		$('#mag-image').css('background-image', "url("+path+")");
  	 	$('#mag-image').css('width', width);
   		$('#mag-image').css('height', height);

   		$("#desc").css('width', width);
		$('#mag-image').attr("alt", pid);
 		
		$("#desc").html(desc); //swaping image description
		
		var img_h = $("#mag-image").height(); //getting image height
		$("#mag-picture-inner").css("height", img_h); //setting div height equal to image height
			
	}
});

$("#next").click(function() {
	var temp_pid = $("#mag-image").attr("alt");
	var n = $(".mag-jquery").size();

	if(temp_pid != n) {
		temp_pid++;
		var pid_ok = temp_pid;
		var path = $(".mag-jquery img[alt="+pid_ok+"]").parent("a").attr("id"); //getting path of large picture from thumbnail
		var desc = $(".mag-jquery img[alt="+pid_ok+"]").parent("a").attr("title"); //getting description of picture
		var pid = pid_ok;
		var temp_dimensions = $(".mag-jquery img[alt="+pid_ok+"]").attr("name");
		var dimensions = temp_dimensions.split('-');
		var width = dimensions[0];
		var height = dimensions[1];
 		
 		$('#mag-image').css('display', "none");
		$('#mag-image').fadeIn(700);
		$('#mag-image').css('background-image', "url("+path+")");
  	 	$('#mag-image').css('width', width);
   		$('#mag-image').css('height', height);

   		$("#desc").css('width', width);
		$('#mag-image').attr("alt", pid);
		
		$("#desc").html(desc); //swaping image description
		
		var img_h = $("#mag-image").height(); //getting image height
		$("#mag-picture-inner").css("height", img_h); //setting div height equal to image height
			
	} 
});

