var $ = jQuery.noConflict();
$(document).ready(function(){
	var arr = [ "a1", "a2", "a3"];
	$.each(arr, function() {
     $("#" + this).mouseover(function () {
		var id = $(this).attr("id").charAt(1); 	
		$("#tabs-0").css({"display":"none"});
		for (I=1; I<4; I++){
			if (I == id){
			   $("#tabs-"+I).css({"display":"block"});
			   $("#li"+I).addClass("active");}
			else{
			   $("#tabs-"+I).css({"display":"none"});
			   $("#li"+I).removeClass("active");}
			 }
		});
	});

   $(".help_text").mouseover(function(){
     var id = $(this).attr("alt").split('|');
     $("#debug_text").html('<div class=\'noteHead\'>'+id[1]+'</div><div class=\'noteBody\'>'+id[0]+'</div><div class=\'noteTail\'>&nbsp;</div>');
      var pic = this.getBoundingClientRect()
   	    picposX = pic.top + 20;
   	    picposY = pic.left + 20;
        $("#debug_text").attr("style", "display:block; position:fixed; top:"+ picposX +"px; left:"+picposY +"px;");
   });
  $(".help_text").mouseout(function(){
   	$("#debug_text").attr("style", "display:none");
   	   	$("#debug_text").html("&nbsp;");
   });
});
;
/*
bxCarousel v1.0
Plugin developed by: Steven Wanderski
http://bxcarousel.com
http://stevenwanderski.com

Released under the GPL license:
http://www.gnu.org/licenses/gpl.html
*/

(function($){

	$.fn.bxCarousel = function(options){

		var defaults = {
			move: 3,
			display_num: 3,
			speed: 500,
			margin:0,
			auto: true,
			auto_interval: 10000,
			auto_dir: 'next',
			auto_hover: false,
			next_text: 'next',
			next_image: '',
			prev_text: 'prev',
			prev_image: '',
			controls: true
		};

		var options = $.extend(defaults, options);		

		return this.each(function() {
			var $this = $(this);                
			var li = $this.find('li');
			var first = 0;
			var fe = 0;
			var last = options.display_num-1;
			var le = options.display_num-1;
			var is_working = false;
			var j = '';
			var clicked = false;		

			li.css({'float':'left','listStyle':'none', 'marginRight':options.margin});
			var ow = li.outerWidth(true);
			wrap_width = (ow*options.display_num) - options.margin;                
			var seg = ow*options.move;
			$this.wrap('<div class="bx_container"></div>').width(999999);
			if(options.controls){
				if(options.next_image != '' || options.prev_image != ''){var controls = '<a href="" class="prev"><img src="'+options.prev_image+'"/></a><a href="" class="next"><img src="'+options.next_image+'"/></a>';}
				else{var controls = '<a href="" class="prev">'+options.prev_text+'</a><a href="" class="next">'+options.next_text+'</a>';}	
			}			
			$this.parent('.bx_container').wrap('<div class="bx_wrap"></div>').css({'position':'relative', 'width':wrap_width,'overflow':'hidden'}).before(controls);
			var w = li.slice(0, options.display_num).clone();
			var last_appended = (options.display_num+options.move)-1;
			$this.empty().append(w);				
			get_p();				
			get_a();					//$this.css({'position':'relative', 'left':-(seg)});			$this.css( {'position':'relative', 'left':'-625px'});		
						
			$this.parent().siblings('.next').click(function(){
				slide_next();
				clearInterval(j);
				clicked = true;
				return false;
			});				
			$this.parent().siblings('.prev').click(function(){
				slide_prev();
				clearInterval(j);
				clicked = true;
				return false;
			});
			if(options.auto){
				start_slide();
				if(options.auto_hover && clicked != true){
					$this.find('li').live('mouseenter', function(){
						if(!clicked){clearInterval(j);}						
					});
					$this.find('li').live('mouseleave', function(){
						if(!clicked){start_slide();}
					});
					
				}
			}
			
			function start_slide(){
				if(options.auto_dir == 'next'){
					j = setInterval(function(){slide_next()}, options.auto_interval);
				}else{
					j = setInterval(function(){slide_prev()}, options.auto_interval);
				}
			}

			function slide_next(){
				if(!is_working){
					is_working = true;
					set_pos('next');
					$this.animate({left:'-='+seg}, options.speed, function(){
						$this.find('li').slice(0, options.move).remove();
						//$this.css('left',-(seg));						$this.css('left','-625px');
						get_a();
						is_working = false;			
					});
				}
			}
			
			function slide_prev(){
				if(!is_working){
					is_working = true;
					set_pos('prev');
					$this.animate({left:'+='+seg}, options.speed, function(){
						$this.find('li').slice(-options.move).remove();
						//$this.css('left',-(seg));						$this.css('left','-625px');
						get_p();
						is_working = false;                 
					});
				}
			}

			function get_a(){
				var str = new Array();
				var lix = li.clone();
				le = last;
				for(i=0;i<options.move;i++){
					le++
					if(lix[le] != undefined){
						str[i] = $(lix[le]);    
					}else{
						le = 0;
						str[i] = $(lix[le]);
					}                                                                       
				}					                 
				$.each(str, function(index){
					$this.append(str[index][0]);
				});
			}
							
			function get_p(){
				var str = new Array();
				var lix = li.clone();
				fe = first;
				for(i=0;i<options.move;i++){
					fe--
					if(lix[fe] != undefined){
						str[i] = $(lix[fe]);    
					}else{
						fe = li.length-1;
						str[i] = $(lix[fe]);
					}                                                                       
				}					        
				$.each(str, function(index){
					$this.prepend(str[index][0]);
				}); 
			}
							
			function set_pos(dir){
				if (dir == 'next') {
					first += options.move;
					if (first >= li.length) {
						first = first % li.length;
					}
					last += options.move;
					if (last >= li.length){
						last = last % li.length;
					}
				}else if (dir == 'prev'){
					first -= options.move;
					if (first < 0){
						first = li.length + first;
					}
					last -= options.move;
					if (last < 0){
						last = li.length + last;
					}
				}
			}				
		});			
	}    
})(jQuery);;
/* *********************************************

(C) 2008-2010, www.homepictures.ru

Support page: www.homepictures.ru/halyava/hpgallery.html

update 2008/12/13 (fixed of element positioning when doctype is defined)
update 2010/07/02 (removed coords attribute of A-tag; added multigallery support)

********************************************* */
hpTexts = {
initerror : 'Галерея с ID=%s уже инициализирована. Для инициализации другой галереи на странице используйте другой ID',
notitle : 'Название не указано',
noimg : 'Изображение отсутствует на сервере',
downloaderror : 'Сбой при загрузке изображения. Ошибка: ',
close : 'Закрыть',
noajax : 'Браузер не поддерживает AJAX'
}

var hpGalleries = {}; //кеш фотогалерей
function hpGallery(BondName){
	this.BondName = !BondName ? 'imgbond' : BondName;
	if(typeof hpGalleries[this.BondName] != 'undefined'){
		alert(hpTexts.initerror.replace('%s', this.BondName));
		return;
	}
	this.Dir = this.GetScriptDir();
	this.isIE = window.navigator.userAgent.indexOf("MSIE")>-1;
	this.Glass = null;
	this.imgWindow = null;
	this.imgcache = {};
	this.loadingimg = null;
	this.cururl = '';
	this.Index = 0;
	this.AltDivs = [];
	this.LinkDivs = [];
	this.bFirstShow = true;
	hpGalleries[this.BondName] = this;
	this.Init();
}
hpGallery.prototype.GetScriptDir = function(){
	var scripts = typeof(document.scripts)!='undefined' ? document.scripts : document.getElementsByTagName('SCRIPT');
	for(var i =0; i<scripts.length; i++)
		if(scripts[i].src.match(/^(.+)hpgallery\.js/i)!=null) return RegExp.$1;
	return '';
}
hpGallery.prototype.Init = function(){
	var c = document.getElementById(this.BondName);
	if(!c) return;
	var cld = c.getElementsByTagName('A');
	if(!cld || cld.length==0) return;
	this.BondImages = [];
	var n=0;
	for(var i=0; i<cld.length; i++){
		var img =  this.GetFirstImg(cld[i]);
		if(img == null) continue;
		var alt = hpTexts.notitle;
		if(typeof img.alt != 'undefined' && img.alt !='') alt = img.alt;
		else if(typeof cld[i].title !='undefined' && cld[i].title != '') alt = cld[i].title;
		cld[i].name = this.BondName+':'+n;
		this.BondImages[n]=[cld[i].href, alt];
		cld[i].onclick = function(e){
			if(this.name.match(/^(.+):(.+)$/)!==null){
				hpGalleries[RegExp.$1].Index = RegExp.$2; 
				hpGalleries[RegExp.$1].ShowImg(); 
			}
			return false;
		}
		n++;
	}
}

hpGallery.prototype.GetFirstImg = function(o){
	var cld = o.childNodes;
	for(var i=0; i<cld.length; i++) if(cld[i].tagName == 'IMG') return cld[i];
	return null;
}

hpGallery.prototype.ShowImg = function(){
	if(typeof(this.BondImages[this.Index])=='undefined') return true;
	var aImg = this.BondImages[this.Index];
	this.ShowGlassWindow(true);
	this.InitScreen();
	var url = aImg[0];
	this.cururl=url;
	if(typeof(this.imgcache[url])=='undefined'){
		this.ShowImgWindow(this.loadingimg);
		this.UploadAndShowImageSize(aImg);
	}
	else{
		this.ShowImgWindow(this.imgcache[url], true);
	}
	return false;
}

hpGallery.prototype.UploadAndShowImageSize = function(aImg) {
	var im = new Image();
	im.src = aImg[0];
	im.alt=aImg[1];
	thisgallery = this;
	im.onload = function(e){
		var img = document.createElement('IMG');
		with(img){ src=im.src; width=im.width; height=im.height; border=0; alt=im.alt; }
		thisgallery.imgcache[im.src]=img;
		if(thisgallery.cururl==im.src) thisgallery.ShowImgWindow(img);
	}
	im.error = function(e){
		if(!e) e = window.event;
		if(thisgallery.cururl==im.src) thisgallery.HideImgWindow();
		alert(hpTexts.downloaderror+e.toString());
	}
}


hpGallery.prototype.ShowImgWindow = function(img){
	var bShowTitle = this.loadingimg != img;
	with(img.style){
		width = this.gu(img.width);
		height = this.gu(img.height);
		marginLeft = this.gu(-Math.round(img.width/2));
		marginTop = this.gu(-Math.round(img.height/2));
		position = 'absolute';
		left = top = '50%';
	}
	if(this.bFirstShow || bShowTitle)
	with(this.imgWindow.style){
		var w = Math.round(img.width*1.20);
		var h = img.height+120;
		if(w<300) w = 300;
		if(h<300) h = 300;
		width = this.gu(w); height = this.gu(h);
		marginLeft = this.gu(-Math.round(w/2));
		marginTop = this.gu(-Math.round(h/2));
		this.bFirstShow = false;
	}
	while(this.imgWindow.childNodes.length>0) this.imgWindow.removeChild(this.imgWindow.childNodes[0]);
	if(bShowTitle){
		thisgallery = this;
		if(typeof(this.AltDivs[this.Index])!='object'){
			this.AltDivs[this.Index] = document.createElement('h3');
			this.AltDivs[this.Index].innerHTML = img.alt;
			with(this.AltDivs[this.Index].style) {
				fontSize="10pt";
				textAlign = 'center'; position = 'absolute'; width = '100%';
				top = this.gu(Math.round(img.height*0.025));
				padding = margin = 0;
			}
		}
		if(typeof(this.LinkDivs[this.Index])!='object'){
			this.LinkDivs[this.Index] = document.createElement('DIV');
			with(this.LinkDivs[this.Index].style) {
				textAlign = 'center'; position = 'absolute';
				top = this.gu(Math.round(img.height+70));
				padding = '3pt'; margin = 0; width = '100%';
			}
			if(this.BondImages.length<11){
				var fistindex = 0;
				var lastindex = this.BondImages.length-1;
			}
			else{
				var fistindex = this.Index-4;
				if(fistindex<0) fistindex = 0;
				var lastindex = fistindex + 8;
				if(lastindex > this.BondImages.length-1){
					lastindex = this.BondImages.length-1;
					var t = lastindex-8;
					if(t>=0) fistindex = t;
				}
			}
			for(var ispan=0; ispan<this.BondImages.length; ispan++){
				if(ispan<fistindex) continue;
				if(ispan>lastindex) break;
				var Page = document.createElement('SPAN');
				Page.innerHTML = (ispan+1);
				with(Page.style){ fontSize="9pt"; padding = "3pt 5pt 3pt 5pt"; marginLeft = "2pt"; width = "20pt"; } 
				if(ispan==this.Index){
					with(Page.style){
						border = "1px solid #000";
						backgroundColor = "#CCC";
						cursor = "auto";
					}
				}
				else{
					with(Page.style){
						border = "1px solid #CCC";
						backgroundColor = "#FFF";
						cursor = "pointer";
					}
					Page.onclick = function(){
						thisgallery.Index = parseInt(this.innerHTML)-1;
						thisgallery.ShowImg();
					}
				}
				this.LinkDivs[this.Index].appendChild(Page);
			}
			var Page = document.createElement('SPAN');
			Page.innerHTML = hpTexts.close;
			with(Page.style){ 
				fontSize="9pt"; 
				padding = "3pt 5pt 3pt 5pt"; marginLeft = "15pt"; 
				border = "1px solid #CCC";
				backgroundColor = "#FFF";
				cursor = "pointer";
				width = "20pt";
			} 
			Page.onclick = function(){
				thisgallery.HideImgWindow();
			}
			this.LinkDivs[this.Index].appendChild(Page);
		}
	}
	var cntr = this.clientCenter();
	with(this.imgWindow.style){
		left = this.gu(cntr[0]);
		top  = this.gu(cntr[1]);
		if(display!='block') display='block';
	}
	this.imgWindow.appendChild(img);
	if(bShowTitle){
		this.imgWindow.appendChild(this.AltDivs[this.Index]);
		this.imgWindow.appendChild(this.LinkDivs[this.Index]);
	}
}

hpGallery.prototype.InitScreen = function(){
	if(this.imgWindow==null){
		thisgallery = this;
		this.imgWindow = document.createElement('DIV');
		this.imgWindow.id ='imgWindow';
		this.imgWindow.onclick = function(){ /* thisgallery.HideImgWindow();*/}
		with(this.imgWindow.style){
			zIndex=2; display='none'; position='absolute'; border='1px solid #AAA'; 
			background = '#FFF url('+this.Dir+'fon.gif) repeat-x bottom';
		}
		document.body.appendChild(this.imgWindow);
		this.loadingimg = document.createElement('IMG');
		with(this.loadingimg){ src=this.Dir+'loading.gif'; width=64; height=64; border=0; alt='Загрузка'; }
	}
}

hpGallery.prototype.HideImgWindow = function(){
	this.imgWindow.style.display='none';
	this.ShowGlassWindow(false);
}

hpGallery.prototype.ShowGlassWindow = function(show){
	if(this.Glass==null){
		this.Glass=document.createElement('DIV');
		with(this.Glass.style){
			display='none'; position='absolute'; height=0; width=0; zIndex=1;
			if(this.isIE){
				backgroundColor = '#000';
				filter="progid:DXImageTransform.Microsoft.Alpha(Opacity=60, Style=0)";
			}
			else backgroundImage = 'url('+this.Dir+'alfa40.png)';
		}
		document.body.appendChild(this.Glass);
	}
	if(show){
		var sizes = this.documentSize();
		with(this.Glass.style){
			left = 0; top = 0;
			width = this.gu(sizes[0]);
			height = this.gu(sizes[1]);
		}
	}
	this.Glass.style.display = show ? 'block' : 'none';
}

hpGallery.prototype.GetAJAXLoader = function(){
	var req=null;
   	if (typeof(window.XMLHttpRequest)!='undefined') { try { req = new XMLHttpRequest(); } catch (e){ alert(hpTexts.ajaxfail); } }
   	else if (typeof(window.ActiveXObject)!='undefined') {
       	try { req = new ActiveXObject('Msxml2.XMLHTTP');} catch (e){
            try { req = new ActiveXObject('Microsoft.XMLHTTP'); } catch (e){ alert(hpTexts.ajaxfail); }
		}
	}
	else alert(hpTexts.noajax);
	return req;
}

hpGallery.prototype.clientSize = function(){
	var w = 0;
	var h = 0;
	if(document.compatMode=='CSS1Compat'/* && !window.opera*/){
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	}
	else{
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}
	return [w, h];
}

hpGallery.prototype.documentSize = function(){
	var w = document.body.scrollWidth > document.body.offsetWidth ? document.body.scrollWidth : document.body.offsetWidth;
	var h = document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight;
	var cs = this.clientSize();
	if(w < cs[0]) w = cs[0];
	if(h < cs[1]) h = cs[1];
	return [w, h];
}

hpGallery.prototype.documentScroll = function(){
	var l = self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
	var t = self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
	return [l, t];
}

hpGallery.prototype.clientCenter = function(){
	var sizes = this.clientSize();
	var scroll = this.documentScroll();
	return [parseInt(sizes[0]/2)+scroll[0], parseInt(sizes[1]/2)+scroll[1]];
}

hpGallery.prototype.gu = function(num){ return parseInt(num)+'px'; }
;

