var ArrBack = Array();
$(function() {

  $(".jq").jqTransform(); 
  
  $(".file-download input.file").bind("change", function(){
    $(".file-download input.text").val($(this).val());
    });

  function setTab(idx){
    $(".tabs .active").removeClass("active");
    $(".tabs li#b-tab" + idx + "-li").addClass("active");
//    $(".h-wrap").attr({"id":"wrb-tab" + idx});
    if (ArrBack.length) $(".h-wrap").css({"background-image":"url(" + ArrBack[idx-1]+")"});
    tabWraps.hide();
    $("#b-tab" + idx).show();      
  }

	if (ArrBack.length) {
		for(i=0;i<ArrBack.length;i++) {
			$.preloadImages(ArrBack[i]);
		}
	}

  if($(".home").length){
  var ab = Math.floor(Math.random()*5)+1; 

  var tabWraps = $(".tab-wrap");
  tabWraps.hide();
  setTab(ab);
  };

  $(".tabs a, .prev2, .next2").live("click", function(){
    var idx = $(this).attr("href").replace("#b-tab","");
    setTab(idx);
    return false;
    });

  $(".h-content ol li").each(function(){
      var index = $(this).index()+1;
		  var list = $('<span class="ol-list">'+ index +'</span>');
			$(this).prepend(list);
			});

  $("area")
    .bind("focus", function(){
      if(document.attachEvent){
      this.blur();
      }
      })
    .bind("click", function(){
      $(".reg-list #active").removeAttr("id");
      $(".reg-list li."+ this.id).attr({"id":"active"});
      $("#map_img").attr({"class":this.id});      
      //if(!$(this).is(".b-map1 area")){ return false; }
      })
    .bind("mouseenter", function() {
      $(".reg-list #active").removeAttr("id");
      $("#map_img").removeAttr("class");  
      $(".reg-list li."+ this.id).attr({"id":"active2"});
      $("#map_img").addClass("h-"+this.id);           
      })
    .bind("mouseleave", function() {
      $(".reg-list #active2").removeAttr("id");
      $("#map_img.h-"+this.id).removeClass("h-"+this.id);           
      });
  $(".reg-list a").bind("click", function() {
      $(".reg-list #active").removeAttr("id");
      $(this).parents(".reg-list li").attr({"id":"active"});
      $("#map_img").attr({"class":$(this).parents(".reg-list li").attr("class")});      
      //if(!$(this).is(".b-map1 a")){ return false; }
      })
    .bind("mouseenter", function() {
      $(".reg-list #active").removeAttr("id");
      $("#map_img").removeAttr("class");  
      $(this).parents(".reg-list li").attr({"id":"active2"});
      $("#map_img").addClass("h-"+$(this).parents(".reg-list li").attr("class"));           
      })
    .bind("mouseleave", function() {
      $(".reg-list #active2").removeAttr("id");
      $("#map_img.h-"+$(this).parents(".reg-list li").attr("class")).removeClass("h-"+$(this).parents(".reg-list li").attr("class"));           
      });

  $(".tree li li:last-child").addClass("last-child");
  $(".tree span a").bind("click", function() {
      $(this).parent().parent().toggleClass("open");
      return false;
      });
  
  $(".alnk").bind("click", function() { 
		if($(this).html()=='Подробнее &gt;') {  
			$(this).html('Скрыть &gt;');
		} else {
			$(this).html('Подробнее &gt;');
		}
		return false;
  });

  $(".show_all_link").bind("click", function() { 
  	    $(this).parent().next().toggle();
		if($(this).html()=='Показать все') {  
			$(this).html('Скрыть все');
		} else {
			$(this).html('Показать все');
		}
		return false;
  });
	

	$("a[rel^='prettyPhoto']").prettyPhoto({
			animationSpeed: 'normal', /* fast/slow/normal */
			padding: 40, /* padding for each side of the picture */
			opacity: 0.35, /* Value betwee 0 and 1 */
			showTitle: false, /* true/false */
			allowresize: false, /* true/false */
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
			callback: function(){}
	});


    $('.datepicker').datepicker();
});


function ShowAdvert(_ele_ids, _uri, _location) {
	var objs = new Array();
	for (var i in _ele_ids) {
		var obj = document.getElementById(_ele_ids[i]);
		if (obj) {
			objs.push(obj);
		}
	}

	$.ajax({
		type: "POST",
		url: '/ajax/goto.php',
		data: 'uri=' + _uri + '&location=' + _location,
		success: function(xml) {
			
			if (xml) {
				var i = 0;
				$(xml).find('banner').each(function(){
					objs[i].innerHTML = $(this).find('content').text();
					i++;
				});
			}
		}
	});		 
}

function message (e1,e2,e3,e4) {
	adres = "mailto:" + e1 + "@" + e2 + e3;
	if (e4) {
		adres += "?subject=" + e4; 
	} else {
		adres += "?subject=Письмо с сайта cius-ees.ru"; 
	}

	window.location.href = adres;
}

$.preloadImages = function(){
	for(var i = 0; i<arguments.length; i++){
    	$("<img />").attr("src", arguments[i]);
	}
}
 
function OpenWindow(url,width,height, name, scrlls) {
	x = (640 - width)/2, y = (480 - height)/2;
	
	if (screen) {
		y = (screen.availHeight - height)/2;
		x = (screen.availWidth - width)/2;
	}
	var window_name = (name) ? name : 'mb_' + get_random();
	var scrlls = scrlls || "yes";

	window.open (url, window_name, 'width='+width+',height='+height+',screenX='+x+',screenY='+y+',top='+y+',left='+x+ ',location=no,status=yes,resizable=yes,scrollbars=' + scrlls + ',titlebar=yes');
}


