var currentFontSize = 60;
var newW;

function increaseFont() {
	if (currentFontSize < 64) {
		document.body.style.fontSize = (currentFontSize + 2) + '%';
		currentFontSize += 2; 
	}
}

function decreaseFont() {
	if (currentFontSize > 56) {
		document.body.style.fontSize = (currentFontSize - 2) + '%';
		currentFontSize -= 2;
	}
}

var imgData;
var boxxed;
//function ShowBigImage(imgName,caption,sort_order) {
function ShowBigImage(id) {
	boxxed = false;
	$.post(urlgetImage, {"album_id": album_id, "photo_id": id}, 
		function(res) {
			imgData = eval('(' +  res + ')');
			showImage();
		}
	);
}

function showImage() {
//	$("#dimmercontent").css('width','400px');
	
	if (imgData['prev'] > 0)
		prev = "<a href='#' class='button' onclick='javascript:getImage("+imgData['prev']+");'>" + prev_txt + "</a>";
	else
		prev = "";
	if (imgData['next'] > 0)
		next = "<a href='#' class='button' onclick='javascript:getImage("+imgData['next']+");'>" + next_txt + "</a>";
	else
		next = "";
		
	imgName = img_path + "/" + imgData['name'];

	$("#dimmercontent").html("<div id='imgbox'><div class='close'></div><img id='dimmerIMG' src=\"" + imgName + "\" alt\=\"\" height=\"600\" /></div><div class='caption'><div id='captionArea'>" + imgData['caption'] + "</div><div id='navArea'><div id='imgPrev'>" +  prev + "</div><div id='imgNext'>" + next + "</div></div></div><div class='clear'></div>");
	
	$("#dimmerIMG").one("load",function () {
		//alert($("#dimmerIMG").width());
		getW(imgName);    	
	})
	.each(function(){
		if(this.complete) $(this).trigger("load");
	});
}



function getW(imgsrc){ 
	//imgsrc = $("#dimmerIMG").src;
	var t = new Image();
	t.src =imgsrc;
	newW = t.width*600/t.height;
	//alert('getW'+t.width);
	$("#dimmerIMG").css('width',newW);
	$("#dimmercontent").css('width',newW);	
	$("#dimmercontent").css('margin-left',-(newW/2));
	$("#dimmerIMG, #imgbox, #imgPrev, #imgNext, #captionArea").hide().delay(500).fadeIn(1000);

	if (!boxxed)
		$("#dimmercontent").lightbox_me({centered: true,overlayCSS:{background:'#000000',opacity:.8}});
	boxxed = true;
}




function getImage(id) {
	//$("#dimmerIMG, #imgbox, #imgPrev, #imgNext, #captionArea, .close, .button").hide();	

	$.post(urlgetImage, {"album_id": album_id, "photo_id": id}, 
		function(res) {
			imgData = eval('(' +  res + ')');
			showAgain();
		}
	);
}

function showAgain() {
//	$("#dimmercontent").css('width','400px');
	
	if (imgData['prev'] > 0)
		prev = "<a href='#' class='button' onclick='javascript:getImage("+imgData['prev']+");'>" + prev_txt + "</a>";
	else
		prev = "";
	if (imgData['next'] > 0)
		next = "<a href='#' class='button' onclick='javascript:getImage("+imgData['next']+");'>" + next_txt + "</a>";
	else
		next = "";
		
	imgName = img_path + "/" + imgData['name'];

if ( navigator.appName == "Microsoft Internet Explorer" ) {
	$('#dimmerIMG').css('visibility', 'hidden');
	$('#dimmerIMG').css('display', 'block');
}
	
	$('#dimmerIMG').removeAttr("width"); 	
	$('#dimmerIMG').removeAttr("height"); 
	$('#dimmerIMG').removeAttr("src"); 
	$('#dimmerIMG').attr("src",imgName);
	
	$("#imgPrev").html(prev);
	
	$("#imgNext").html(next);
	
	$("#captionArea").html = imgData["caption"];
	
	//$('#dimmerIMG,#imgPrev,#imgNext,#captionArea').hide();
	
if ( navigator.appName == "Microsoft Internet Explorer" ) {	
	$('#imgPrev,#imgNext,#captionArea').hide();
} else {
	$('#dimmerIMG,#imgPrev,#imgNext,#captionArea').hide();
}

	/*
	$("#dimmercontent").html("<div id='imgbox'><div class='close'></div><img id='dimmerIMG' src=\"" + imgName + "\" alt\=\"\" height=\"600\" /></div><div class='caption'><div id='captionArea'>" + imgData['caption'] + "</div><div id='navArea'><div id='imgPrev'>" +  prev + "</div><div id='imgNext'>" + next + "</div></div></div><div class='clear'></div>");
	*/
	$("#dimmerIMG").one("load",function () {
		//alert($("#dimmerIMG").width());
		updateW(imgName);    	
	})
	.each(function(){
		if(this.complete) $(this).trigger("load");
	});
}


function updateW(imgsrc){ 
	//imgsrc = $("#dimmerIMG").src;
		
	var t = new Image();
	t.src = imgsrc;
	
	if(t.width>0)
	{
		newW = t.width*600/t.height;

		//alert('getW'+t.width+",newW"+newW);
		$("#dimmerIMG").css('width',newW);
	
		$("#dimmercontent").css('width',newW);
		$("#dimmercontent").css('margin-left',-(newW/2));

		$("#dimmerIMG").css('height',"600px");

		if ( navigator.appName == "Microsoft Internet Explorer" ) {
			$('#dimmerIMG').css('display', 'none');
			$('#dimmerIMG').css('visibility', 'visible');
		}		
		
		$("#dimmerIMG, #imgPrev, #imgNext, #captionArea").delay(500).fadeIn(500);
		//$("#imgPrev, #imgNext, #captionArea").delay(500).fadeIn(500);		
		
	} else {
		t = null;
		setTimeout("showAgain()", 1000);
	}
}


var currentMain = null;
var currentSub = null;
var saveHeight = 0;

//<!--[if IE 6]>
window.onload=function(){
	//$("#col2").css('height',$("#col3").height());
	//document.getElementById('col2').style.height = document.body.offsetHeight+'px';
	$('#col2').css('height',$(document).height()+'px');
	$('#col4').css('height',$(document).height()+'px');
	$('#col3').css('height',$(document).height()+'px');
	//alert($('#col4').css('height'));
	//$("#col2").css('height',);
	
/*	$(function() {
		$( "#accordion" ).accordion({
			active: false,
			animated: false,
			autoHeight: false,
			event: "mouseover"
		});
	});*/
	
	$(".hoverBtn").mouseenter(function() {
		//if (currentMain != $(this) && currentSub) {
		//	currentSub.slideUp();
		//	currentSub = null;
		//	currentMain = null;
		//}
		//$(this).children('.hide-submenu').slideDown();
		$(this).children('.hide-submenu').show();
		currentMain = $(this);
		currentSub = $(this).children('.hide-submenu');	
		
		$(this).children('a').children('.normalImg').hide();
		$(this).children('a').children('.selectedImg').show();		
	});
	
	$(".hoverBtn").mouseleave(function() {
		//$(this).children('.hide-submenu').slideUp();		
		$(this).children('.hide-submenu').hide();
		currentSub = null;
		currentMain = null;		
		
		$(this).children('a').children('.normalImg').show();
		$(this).children('a').children('.selectedImg').hide();		
	});	
	
/*	$(".hoverBtn").hover(function() {
		//$(this).children('.hide-submenu').slideDown();
		$(this).children('.hide-submenu').show();
		currentMain = $(this);
		currentSub = $(this).children('.hide-submenu');	
		
		$(this).children('a').children('.normalImg').hide();
		$(this).children('a').children('.selectedImg').show();		
	},
		function() {
			//$(this).children('.hide-submenu').slideUp();		
			$(this).children('.hide-submenu').hide();
			currentSub = null;
			currentMain = null;		
			
			$(this).children('a').children('.normalImg').show();
			$(this).children('a').children('.selectedImg').hide();		
		}
	);*/
	
	//alert($(document).height());
}
//<![endif]--> 


var currNormal = null;
var currNormalSrc = "";
function setSelect(thisSelect, selectSrc) {
	currNormal = thisSelect;
	currNormalSrc = thisSelect.src;
	
	thisSelect.src = selectSrc;
}

function shareToFB(u)
{	

	window.open('http://www.facebook.com/share.php?u='+encodeURIComponent(u),'sharer','toolbar=0,status=0,width=626,height=436');

}

function showBook(bookpath) {
	$("#iframe_book").attr('src', bookpath);
	$("#iframe_book").width($("#container").width() - $(".close").width()*2);
	$("#iframe_book").height($("#container").height() *0.9);
	$(".close").css('right', -$(".close").width());
	$("#overlaycontent").show();
	$("#overlaycontent").lightbox_me({centered: true,overlayCSS:{background:'#000000',opacity:.8}});
}


/*
function changeImage() {
	$("#dimmercontent").css('width','400px');
	
	imgName = img_path + "/" + imgData['name'];	
	$("#dimmerIMG").attr('src', imgName);
	
	$("#captionArea").html(imgData['caption']);	
	if (imgData['prev'] > 0)
		$("#imgPrev").html("<a href='#' class='button' onclick='javascript:getImage("+imgData['prev']+");'>" + prev_txt + "</a>");
	else
		$("#imgPrev").html("");
	if (imgData['next'] > 0)
		$("#imgNext").html("<a href='#' class='button' onclick='javascript:getImage("+imgData['next']+");'>" + next_txt + "</a>");	
	else
		$("#imgNext").html("");
		
		
	$("#dimmerIMG").one("load",function () {
		//alert($("#dimmerIMG").width());
		var t = new Image();
		t.src =imgName;
		newW = t.width*600/t.height;
		//alert('getW'+t.width);
		$("#dimmerIMG").css('width',newW);
		$("#dimmercontent").css('width',newW);
		$("#dimmerIMG").hide().delay(500).fadeIn(1000);
		$("#dimmercontent").lightbox_me({centered: true,overlayCSS:{background:'#000000',opacity:.8}});
	})
	.each(function(){
		if(this.complete) $(this).trigger("load");
	});
}*/
