$(document).ready(function(){

  $('.over-list').click(function() {overlist($(this)); return false;});
  
  if ( document.location.search.indexOf("noflash") > -1 ) {
    return;
  }

  $('#intro').html( "<div class='flash'></div>" );
  $('#intro .flash').flash({
    swf: 'flash/head.swf',
    height: 387,
    width: 847,
    hasVersion: 8,
    expressInstaller: 'expressInstall.swf',
    params: {
      wmode:'transparent'
      }
    });
  
/*  $('#video').html( "<div class='flash'></div>" );
  $('#video .flash').flash({
    swf: 'http://www.youtube.com/v/duBdL1VjKzM&enablejsapi=1&hl=ru&fs=1',
    height: 340,
    width: 560,
    id: "myytplayer",
    params: {
      wmode:'transparent',
      allowScriptAccess: "always",
      allowFullScreen: true
      }
    });*/
    
    
  
  $('#btn-welcome').html( "<div class='flash'></div>" );
  $('#btn-welcome .flash').flash({
    swf: 'flash/text.swf',
    height: 86,
    width: 278,
    hasVersion: 8,
    expressInstaller: 'expressInstall.swf',
    params: {
      wmode:'transparent'
      }
    });
  
  $('#btn-door').html( "<div class='flash'></div>" );
  $('#btn-door .flash').flash({
    swf: 'flash/door.swf',
    height: 500,
    width: 259,
    hasVersion: 9,
    expressInstaller: 'expressInstall.swf',
    params: {
      wmode:'transparent'
      }
    });
  
  $('#player').html( "<div class='flash'></div>" );
  $('#player .flash').flash({
    swf: 'flash/player.swf',
    height: 53,
    width: 87,
    hasVersion: 8,
    expressInstaller: 'expressInstall.swf',
    params: {
      wmode:'transparent'
      }
    });
    
  

});

function EIWelcome() {
    overlist($('#btn-welcome'));
}
  
function loadscrollcontent(_id) {
  var _href = _id.attr("href");
  var _hrefE = _href.split("#");
  var _file = "/" + _hrefE[0].replace(/^\/+/, '').replace(/\/+$/,'') + "/?" + Math.random();
//  var _file = _hrefE[0];
  var _room = _hrefE[1];
  
  var loadfile = _file;// +" #content-over-inner";
  $("#content-over-inner").load( loadfile, function(){
    $("#content-over-inner").fadeIn("slow");
    $('#btn-close').click( showFlash );
    $('.blockOverlay').click( showFlash );

    $.scrollTo.defaults.axis = 'y';
    if(_room && $('h2#'+_room).attr("id") != undefined){
      $('#over-content').scrollTo( 'h2#'+_room, 300 );
      $('a.'+_room).addClass("over-left-side-sel");
    }
    $('#over-toc a').click(function(){
      var _this = $(this);
      var _href = _this.attr("href");
      var _hrefE = _href.split("#");
      var _file = _hrefE[0];
      var _room = _hrefE[1];
      $('#over-content').scrollTo( 'h2#'+_room, 300);
      $('#over-toc a').removeClass("over-left-side-sel");
      _this.addClass("over-left-side-sel");
      return false;
    });
    $('.over-list-in').click(function() {
      var _room = "#" + ( $('.over-left-side-sel').attr("href").match(/#(^#+)$/)[1] || "" );
      /*
      if(_room == undefined){_room = "";}
      else{
        
        var _roomE = _room.split("/");
        var _roomE = _roomE[_roomE.length-1].split("#");
        var _room = "#"+_roomE[_roomE.length-1];
      }
      */
      var _href = $('.over-list-in').attr("href");
      var _hrefE = _href.split("/");
      var _hrefE = _hrefE[_hrefE.length-1].split("#");
      var _file = _hrefE[0];
      alert(_file +" "+ _room);
      $('.over-list-in').attr({href: _file + _room});
      loadscrollcontent($(this));
      return false;
    });
  });
  return false;
}

function showFlash() {
  $.unblockUI(); 
  hideFlash(0);
//  $("object,embed").css( { display: "block" } ); 
  return false;
}

function hideFlash( m ) {
  
  var s = m ? "none" : "block";
  $(".flash").css( { display: s } ); 
  /*
  var flash = document.getElementsByTagName("OBJECT");
  if ( ! flash.length ) {
    flash = document.getElementsByTagName("EMBED");
  }
  for ( var i=flash.length-1; i >= 0; i-- ) {
//    alert( flash[i].nodeName );
    flash[i].style.display = s;
  }
  */
}

function loadcontent(_id) {
  var _href = _id.attr("href");

  
  var _hrefE = _href.split("#");
  var _file = "/" + _hrefE[0].replace(/^\/+/, '').replace(/\/+$/,'') + "/?" + Math.random();
  var _room = _hrefE[1];
  var loadfile = _file; //+" #content-over-inner";
  $("#content-over-inner").load(loadfile, function(){
    $("#content-over-inner").fadeIn("slow");
    $('#btn-close').click( showFlash );
    $('.blockOverlay').click( showFlash );
    switch( _id.attr("id") ) {
      case "btn-welcome":
      case "btn-door":
      case "sitemap-rooms":
        $("#over-map a").hover( 
          function () {
            _id=$(this);
            var position = _id.position();
            $('#over-ico-info').text(_id.attr("title"));
               $('#over-ico-info').css({
              'left' : position.left+75+'px',
              'top' : position.top,
              'display' : 'block'
            });
          }, 
          function () { $('#over-ico-info').css({display : 'none'}) }
        );
        break;
      case "m-cab":
/*        var serverUrl1 = '/tmp/aristel/form/query1.php';
        var serverUrl2 = '/tmp/aristel/form/query2.php';
        $('#sendButton').click(function() {sendInformation1(serverUrl1, serverUrl2); return false;});
        */
        break;
      default:
    } // switch
  });
  return false;
}

function overlist(_id) {
	if (_id.attr("id") == 'btn-door' || _id.attr("id") == 'btn-welcome')
	{
      	document.location.href='http://www.aristel.ru/news/'; 	
      	return;
	}
	
  $.blockUI.defaults.css.top = ($(window).height() - 575) /2 + 'px';
  $.blockUI.defaults.css.left = ($(window).width() - 850) /2 + 'px';
  hideFlash(1);
  $.blockUI();
//  alert( 1 );
  switch( _id.attr("id") ) {
    case "m-cab":
    case "btn-welcome":
    case "btn-door":
    case "sitemap-rooms":
      loadcontent(_id);
      break;
    default:
      loadscrollcontent(_id);
      break;
  }
  return false;
}

function selectPrice( type ) {
  var i = 3 - type;
  $('.over-sub-menu a').toggleClass("current");
  $('.price-type-'+i).hide();
  $('.price-type-'+type).show();
  return false;
}

function selectRoom( sel ) {
  var i = sel.options[sel.selectedIndex].value;
  $('#ServiceSelect').html( $('#ServicesGroup'+i).html() ); 
//  $('#ServiceSelect optgroup').hide(); 
//  $('#ServicesGroup'+i).show();
  return;
}

function getPrivInfo(form) {
  var data = {
    number: form.numberText.value,
    password: form.passwordText.value
  };
  $.get( "/cab/getinfo/", data, function(resp) {
    var text = "number: " + resp.getElementsByTagName("number")[0].firstChild.nodeValue + ";\n" +
       "password: " + resp.getElementsByTagName("password")[0].firstChild.nodeValue + ";\n";
    alert( text );
  });
  
  
  

}


