iCurrentPage = 1;


$(document).ready(function()	{
	var sPosition = "fixed";
	
	$(document.body).append('<div id="panel_overlay"></div>');
	$(document.body).append('<div id="panel_content"></div>');
	
	if ($.browser.msie)	{
		if (parseFloat($.browser.version) <= 6)	{
			sPosition = "absolute";
		}
	}
	$('#panel_overlay').css('position', sPosition);
	$('#panel_overlay').css('width', $(window).width() + "px");
	$('#panel_overlay').css('height', $(window).height() + "px");
	
	$('#photo-form-panel').remove().appendTo('#panel_content');
	
});

function ShowGallery(iPage){
  //apivars = ;
  $('#gallery-panel')
    .html('<div style="width:150px; height:150px;"><img style="position:relative; left:100px; top:75px;" src="/images/spinner.gif"></div>')
    .load('api.php', {_a:2, p:iPage}, function(responseText, textStatus, XMLHttpRequest){
      iCurrentPage = iPage;
      $('#gallery-panel').show();
    });
  iCurrentPage = iPage;
}
function SubmitPhoto(){
  var postvar = $(document.forms.frmPhotoEntry).serializeArray();
  $('#photo-form')
    .html('<div style="width:150px; height:150px;"><img style="position:relative; left:150px; top:100px;" src="/images/spinner.gif"></div>')
    .load('api.php', postvar, function(responseText, textStatus, XMLHttpRequest){
    });
}

var bPopupShown = false;

function TogglePhotoForm(){
  if(NickName_Authenticate()){
    $('#photo-form-panel').toggle();
  }

	if (bPopupShown)	{
		$('#panel_overlay').hide();
		$('#panel_content').hide();
		
		//$(window).unbind('scroll',scrollLock); // unbinds lock

	}
	else	{
		$('#panel_overlay').show();
		$('#panel_content').show();
		
		CenterDiv($('#panel_content'));
		
		 var a = [
        self.pageXOffset ||
        document.documentElement.scrollLeft ||
        document.body.scrollLeft
        ,
        self.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop
        ];
   // $(window).bind('scroll',{pos: a},scrollLock);

		
		
	}
	bPopupShown = !bPopupShown;
}

function ToggleIntro(){
    $('#intro-panel').toggle();
}
function NickName_Authenticate(){
  if(new String(nickname).length > 0){
    return true;
  } else {
    document.location = "/nickname/login.php";
  }
}

function CenterDiv(oJQuery)	{
	var ScrollTop = $(document).scrollTop()
	$(oJQuery).css('top', ($(window).height() / 2) - ($(oJQuery).height() / 2) + ScrollTop);
	$(oJQuery).css('left', ($(window).width() / 2) - ($(oJQuery).width() / 2));
}


function scrollLock(e) {
    var a=e.data.pos;
    window.scrollTo(a[0],a[1]);
    return false;
}


