var t;
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function alphaImg(img) {
      var imgID = (img.id) ? "id='" + img.id + "' " : ""
      var imgClass = (img.className) ? "class='" + img.className + "' " : ""
      var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
      var imgStyle = "display:inline-block;"
      if (img.align == "left") imgStyle = "float:left;" + imgStyle
      if (img.align == "right") imgStyle = "float:right;" + imgStyle
      var strNewHTML = "<span " + imgID + imgClass + imgTitle
       + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
       + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
       + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
      img.outerHTML = strNewHTML
}

function switch_tab(tab_name)
{
	$('#basic_content').css('display', 'none');
	$('#science_content').css('display', 'none');
	$('#nature_content').css('display', 'none');
	$('#basic_content > div.right > div').css('display', 'none');
	$('#science_content > div.right > div').css('display', 'none');
	$('#nature_content > div.right > div').css('display', 'none');
	
	$('ul#series > li.active').removeClass('active');
	
	$('#' + tab_name + '_content').css('display', 'block');
	$('#' + tab_name + '_content > div.right > div').eq(0).css({
		'display': 'block',
		'left': '0px'
	});
	
	var sel = '#' + tab_name + '_content ul.sub_series > li:first';
	var act = $('#' + tab_name + '_content').find('ul.sub_series > li.active').removeClass('active');
	var act_n = act.attr('class').substring(7, 8);
	act.find('span').replaceWith("<a href='javascript:switch_prod(" + act_n + ")'>" + act.find('span').text() + "</a>");
	$(sel).addClass('active');
	$(sel + ' > a').replaceWith("<span>" + $(sel + ' > a').text() + "</span>");
	
	if ((version >= 5.5 && version < 7) && (document.body.filters)) {
		if($('#' + tab_name + '_content > div.right > div:first span').length == 0) {
			var i = $('#' + tab_name + '_content > div.right > div:first').attr('class').substring(11, 12);
			$('#wrapper #tabs .content').css('background', 'url(/s/loadinfo.net.gif) 58% 200px no-repeat #DADADA');
			var image = new Image()
			image.onload = function() {
				$('#wrapper #tabs .content').css('background-image', 'none')
				$('div.product_tab' + i + ' img').attr('src', 's/i/table' + i + '.png');
				if($('div.product_tab' + i + ' img').length > 0) alphaImg($('div.product_tab' + i + ' img').get(0))
			}
			image.src = 's/i/table' + i + '.png'
		}
	}
	
	$('ul#series > li#' + tab_name).addClass('active');
}

function switch_prod(prod_n)
{
	var sel = 'li.switch_' + prod_n;
	var act = $(sel).parent().find('li.active');
	
	act.removeClass('active');
	var act_n = act.attr('class').substring(7, 8);
	$('div.product_tab' + act_n + ' img').stop(true);
	clearTimeout(t)
	act.find('span').replaceWith("<a href='javascript:switch_prod(" + act_n + ")'>" + act.find('span').text() + "</a>");
	$(sel).addClass('active');
	$(sel + ' > a').replaceWith("<span>" + $(sel + ' > a').text() + "</span>");

  $('#wrapper #tabs .content').css('background-image', 'none');
	$('div.product_tab' + prod_n + ' > p').css('display', 'none')
	var animation = function() {
		act.parent().parent().find('div').css('display', 'none');
		$('div.product_tab' + prod_n).css('display', 'block');
		$('#wrapper #tabs .content').css('background', 'url(/s/loadinfo.net.gif) 58% 200px no-repeat #DADADA');
	
			var selector = 'img'
			if ((version >= 5.5 && version<7) && (document.body.filters))
				selector = 'span'
			var image = new Image()
			$('#wrapper #tabs .content').css('background', 'url(/s/loadinfo.net.gif) 58% 200px no-repeat #DADADA');
			$('div.product_tab' + prod_n + ' img')
			.css({
					'position': 'relative',
					'left': '800px'
			});
			image.onload = function() {
				$('#wrapper #tabs .content').css('background-image', 'none')
				$('div.product_tab' + prod_n + ' img').attr('src', 's/i/table' + prod_n + '.png');
				if ((version >= 5.5 && version<7) && (document.body.filters)) {
					if($('div.product_tab' + prod_n + ' img').length > 0) alphaImg($('div.product_tab' + prod_n + ' img').get(0))
					$('div.product_tab' + prod_n + ' span')
					.css({
						'position': 'relative',
						'left': '800px'
					});
				}
				if(jQuery.browser['opera'] || jQuery.browser['safari'] || jQuery.browser['msie'])
					$('div.product_tab' + prod_n + ' ' + selector).animate({"left": "0px"}, "normal", "linear", function(){
								t = setTimeout("$('#wrapper #tabs .content').css('background', 'url(s/i/bg_fon.jpg) right no-repeat #DADADA')", 300);
								$('div.product_tab' + prod_n + ' > p').fadeIn('slow');
					});
				else				
					$('div.product_tab' + prod_n + ' img').load(function(){
						$(this).animate({"left": "0px"}, "normal", "linear", function(){
								t = setTimeout("$('#wrapper #tabs .content').css('background', 'url(s/i/bg_fon.jpg) right no-repeat #DADADA')", 300);
								$('div.product_tab' + prod_n + ' > p').fadeIn('slow');
						});
					});
			}
			image.src = 's/i/table' + prod_n + '.png'
	
	}
	
	if(!jQuery.browser['msie'])	$('div.product_tab' + act_n).fadeOut('slow',animation);
	else $('div.product_tab' + act_n).slideUp('fast',animation);

}


$(document).ready(function () {
	$('div.fotos a').lightbox();
});


window.onload = function () {
	$('div.product_tab8 img').attr('src', 's/i/table8.png');
	$('div.product_tab3 img').attr('src', 's/i/table3.png');
};