var back_url = '';
function closemenu(boxname)
{
  document.getElementById(boxname).style.display = "none";
//  document.getElementById('home').style.background="url(/theme/images/arrow_up.jpg) no-repeat bottom center";
//  document.getElementById('portf').style.background="url(/theme/images/arrow_up.jpg) no-repeat top center";
}
function openmenu(boxname){
  document.getElementById(boxname).style.display = "block";
//  document.getElementById('home').style.background="url(/theme/images/arrow_up.jpg) no-repeat top center";
//  document.getElementById('portf').style.background="url(/theme/images/arrow_up.jpg) no-repeat bottom center";
}
function opensvyaz()
{
  closemenu('mbox1');
//  document.getElementById('home').style.background="url(/theme/images/arrow_up.jpg) no-repeat top center";
//  document.getElementById('fback').style.background="url(/theme/images/arrow_up.jpg) no-repeat bottom center";
  showPage('/feedback');
}
function closesvyaz(){
 // document.getElementById('home').style.background="url(/theme/images/arrow_up.jpg) no-repeat bottom center";
 // document.getElementById('fback').style.background="url(/theme/images/arrow_up.jpg) no-repeat top center";
  closeSitemap();
}
function rabopen(){
  closeSitemap();
  showSiteMap('rab.php');
}
function rabclose()
{
  closeSitemap();
  showPage(back_url);
 // showSiteMap('portf.php');
}
function sendmailback()
{
  closeSitemap();
  showPage('/feedback');
}



function closeSitemap() {
 $('#sitemap').remove();
 $('#overlay').remove();
 $('select').show();
 $('img.overlayclose').unbind('click').unbind('keypress');
 $('#overlay').unbind('click').unbind('keypress');
}

function setupSitemap()
{
/*
 var sitemapHeight = $('#sitemap-box').height();
 var docHeight = $(window).height();
 

 if (sitemapHeight + 40 > docHeight) {
  $('body').height(sitemapHeight + 60 + 'px');
  docHeight = $(window).height();
  $('#overlay').css({ height: docHeight + 'px' });
 }
 var sitemapTopMargin = docHeight - sitemapHeight - 40;
 //$('#sitemap-box').css({marginTop: sitemapTopMargin + 'px' });  
 $('#sitemap-box').css({marginTop: 40 + 'px' });  
 
 var closer = $('<a href="#"><img src="//theme/images/arrow_up.gif" /></a>')
 $.clickOrEnter(closer,closeSitemap);
 $('#sitemap-box').append(closer);
 $.clickOrEnter('#overlay',closeSitemap);
 $('select').hide();
 $('#sitemap-box').show();
*/
 /*
 //call google analytics tracking for dummy page for this popup
 if (typeof urchinTracker == 'function') {
  urchinTracker('/sitemap/');
 }
 */
}

function showSiteMap(page)
{
 var docHeight = $(window).innerHeight();
 var docWidth = $(document).innerWidth();

 $('<div id="overlay"></div>').insertAfter('#wrapper');
 $('<div id="sitemap"></div>').insertAfter('#overlay');
 
 window.scrollTo(0,0);
 
 $('#overlay').css({ height: docHeight + 'px', width: docWidth + 'px'});
 // анимация
 //$("#overlay").animate({opacity: 0.6}, 400);
 
 $("#overlay").css({opacity: 0.5});
 $('#sitemap').html('<img src="/theme/images/loadingAnimation.gif" style="position:absolute; top:'+docHeight/2+'px;  left:'+(docWidth/2-100)+'px;" />');
 $('#sitemap').load('/portfolio/show/'+page,setupSitemap)
 ;
}

function showPage(page)
{
 var docHeight = $(window).innerHeight();
 var docWidth = $(document).innerWidth();

 $('<div id="overlay"></div>').insertAfter('#wrapper');
 $('<div id="sitemap"></div>').insertAfter('#overlay');

 window.scrollTo(0,0);

 $('#overlay').css({ height: docHeight + 'px', width: docWidth + 'px'});
 // анимация
 //$("#overlay").animate({opacity: 0.6}, 400);

 $("#overlay").css({opacity: 0.5});
 var docHeight = $(document).innerHeight();
 var docWidth = $(document).innerWidth();
 $('#sitemap').html('<img src="/theme/images/loadingAnimation.gif" style="position:absolute; top:'+docHeight/2+'px;  left:'+(docWidth/2-100)+'px;" />');
 $('#sitemap').load(page,setupSitemap);
}

function loadPage(url)
{
 var docHeight = $(document).innerHeight();
 var docWidth = $(document).innerWidth();
    $('#sitemap').html('<img src="/theme/images/loadingAnimation.gif" style="position:absolute; top:'+docHeight/2+'px;  left:'+(docWidth/2-100)+'px;" />');
    $('#sitemap').load(url);
}

function resizeOverlay()
{
 var docHeight = $(document).innerHeight();
 var docWidth = $(document).innerWidth();
// alert(docHeight);
 $('#overlay').css({ height: docHeight + 'px', width: docWidth + 'px' });
	  
}


function showOne(id,back)
{
 back_url = back;
    loadPage('/portfolio/show_one/'+id);
}

function submitFeedBack()
{
    $.post("/feedback/send", { org: $('#org').val(),
                          mailfrom: $('#mailfrom').val(),
                          person: $('#person').val(),
                          phone: $('#phone').val(),
                          text: $('#text').val()
                      },
      function(data)
      {

         $('#sitemap').html(data);

      }
    );

}


jQuery(function($) {
  $(window).bind('resize',resizeOverlay)
  });
