var isMSIE = /*@cc_on!@*/false;

isMozilla=navigator.appName=="Netscape"||navigator.appName=="Opera";

iens6=document.all||document.getElementById
ns4=document.layers

var mousex = 0;
var mousey = 0;

/*function initReq() {
  req=false;
  if(window.XMLHttpRequest)
  {
    req=new XMLHttpRequest;
    if (req.overrideMimeType) {
      req.overrideMimeType('text/html');}
  }
  else if(window.ActiveXObject)
  {
     req=new ActiveXObject("Microsoft.XMLHTTP");
  }

  return req;
} */

function initReq() {
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
    	http_request.overrideMimeType('text/xml');
    }
  }
  else if (window.ActiveXObject) { // IE
  	try {
   		http_request = new ActiveXObject("Msxml2.XMLHTTP");
   	}
   	catch (e) {
   		try {
   			http_request = new ActiveXObject("Microsoft.XMLHTTP");
   	}
   		catch (e) {}
		}
	}

  if (!http_request) {
   	alert('Giving up :( Cannot create an XMLHTTP instance');
   	return false;
  }
  return http_request;
}

function isset(varname)  {
  if(typeof( window[ varname ] ) != "undefined") return true;
  else return false;
  return false;
}


  function MoveTab(id) {
    for(var i=1; i<=6;i++) {
      var cn = (i==id)?'2':'1';
      var bc = (i==id)?'block':'none';
      document.getElementById('ann_'+i).style.display=bc;
      document.getElementById('aimg_'+i).style.display=bc;
      document.getElementById('abut_'+i).style.backgroundImage='url(/i/headbutbg'+cn+'.gif)';
    }
  }

  function MoveTabAP(id) {
    for(var i=1; i<=6;i++) {
      var cn = (i==id)?'2':'1';
      var bc = (i==id)?'block':'none';
      if(i>0) {
        document.getElementById('ann_'+i).style.display=bc;
        document.getElementById('aimg_'+i).style.display=bc;
        document.getElementById('abut_'+i).style.backgroundImage='url(http://tchernovaudio.com/i/headbutbg'+cn+'.gif)';
      }
    }
  }

  function GoTab(id) {
    window.location.href = '/?s=content&cat='+id+'';
  }
  function GoTab2(id, su) {
    window.location.href = su+'/?s=content&cat='+id+'';
  }
  function GoTabAP(id) {
    window.location.href = '/?s=audioportal&sub='+id+'';
  }

	function showPic(id) {
	  if(id.split('|').length>2){
	    alert('Недопустимый символ в названии файла');
	  }
	  else{
	    var objLink = document.createElement('a');
   		objLink.setAttribute('href',id.split('|')[0]);
   		objLink.setAttribute('rel','lightbox');
   		objLink.setAttribute('title',id.split('|')[1]);
	    Lightbox.prototype.start(objLink);
	  }
	}

function left_menu_set_active_item(n) {  for(var i=1;i<6;i++) {
  	if(i == n) {
		document.getElementById('lm_'+i).src = "../i/brand_"+i+"_new_a.gif";
  	}else {
  		document.getElementById('lm_'+i).src = "../i/brand_"+i+"_new.gif";
  	}
  }
}

function matrix_free() {  matrix_BrandHover('',0);
}

function matrix_BrandHover(key,val) {
  if(!isset('matrix_cleaned')) return 0;

  if(matrix_lastloaded==key+val) return 0;
  matrix_lastloaded=key+val;

  var matrix=document.getElementById('tc_matrix');

  matrix_infader();

  if(!tds) {
    tds=matrix.getElementsByTagName("TD");
  }

  var cols=[false,false,false,false,false,false];

  var pre=8;
  for(var i=0;i<36+pre;i++) {

  	var col=((i+4)%6);

    if(i<6+pre) continue;

    var elem=tds[i].firstChild;

  	if(key=='brand') {
  	  if(i>=(val*6+pre) && i <val*6+6+pre &&matrix_isValid(i-pre)) {
        elem.style.display='block';
        cols[col]=true;
        continue;
      }
  	}

  	if(key=='cat') {
  	  if(val=='home'&&col<3&&matrix_isValid(i-pre)) {
        elem.style.display='block';
        cols[col]=true;
        continue;
      }
  	  if(val=='car'&&col>2&&matrix_isValid(i-pre)) {
        elem.style.display='block';
        cols[col]=true;
        continue;
      }
  	}
  	if(key=='col') {
  	  if(val==col&&matrix_isValid(i-pre)) {
        elem.style.display='block';
        cols[col]=true;
        continue;
  	  }
  	}
    elem.style.display='none';
  }
  for(i=0;i<6;i++) {
    if(i==1) continue;
    if(cols[i]) {
      document.getElementById('matrix_ch'+i).style.display='none';
      document.getElementById('matrix_ch'+i+'_h').style.display='block';
    }
    else {      document.getElementById('matrix_ch'+i+'_h').style.display='none';
      document.getElementById('matrix_ch'+i).style.display='block';
    }
  }

}

function matrix_isValid(id) {
  var t=matrix_valid.length;
  for(var i=0;i<t;i++)
  if(matrix_valid[i]==id) return true;
  return false;
}

function matrix_mousemove(mousex,mousey) {  if(matrix_cleaned) return 0;

  var matrix=document.getElementById('tc_matrix');

  if(mousex<matrix.offsetLeft-179 || mousey<matrix.offsetTop|| mousey>(matrix.offsetTop+matrix.offsetHeight-10)|| mousex>(matrix.offsetLeft+matrix.offsetWidth-20) ) {	matrix_fader();
  }
  else
  if(mousex>matrix.offsetLeft-179&&mousex<matrix.offsetLeft&&mousey>matrix.offsetTop&&mousey<matrix.offsetTop+110) {  	matrix_fader();
  }
}

function matrix_fader() {  matrix_BrandHover('',0);
  matrix_cleaned=true;
  matrix_lastloaded=false;

  var matrix=document.getElementById('bg_matrix');
  if(isMSIE)
  	ie_toggleopacity(matrix,false);
  else
  matrix.style.opacity=1;

  left_menu_set_active_item(0);
}

function matrix_infader() {
  matrix_cleaned=false;
  var matrix=document.getElementById('bg_matrix');
  if(isMSIE) {  	ie_toggleopacity(matrix,true);
  }
  else {
  matrix.style.opacity=0.2;
	}
}

function ie_toggleopacity(elm, val) {    var f='DXImageTransform.Microsoft.alpha';
    if (elm.filters[f]) {
		elm.filters[f].enabled = val;
	} else {
		elm.style.filter = 'progid:' + f + '(opacity=20,enabled=true)';
	}
}

function ie_fametoggleopacity(elm, val) {	if(isMSIE) {
      var f='DXImageTransform.Microsoft.alpha';
      if (elm.filters[f]) {
		elm.filters[f].enabled = val;
  	  } else {
		elm.style.filter = 'progid:' + f + '(opacity=60,enabled=true)';
	  }
    }
    else elm.style.opacity=(val?0.6:1);
}

function movedown(){
if (iens6&&parseInt(crossobj.style.left)>=(contentWidth*(-1)+725))
crossobj.style.left=parseInt(crossobj.style.left)-speed+"px"
else if (ns4&&crossobj.left>=(contentWidth*(-1)+320))
crossobj.left-=speed
movedownvar=setTimeout("movedown()",20)
}

function moveup(){
if (iens6&&parseInt(crossobj.style.left)<=0)
crossobj.style.left=parseInt(crossobj.style.left)+speed+"px"
else if (ns4&&crossobj.left<=0)
crossobj.left+=speed
moveupvar=setTimeout("moveup()",20)

}

function getcontent_Width(){
if (iens6)
contentWidth=crossobj.offsetWidth
else if (ns4)
document.nscontainer.document.nscontent.visibility="show"
}

function str_replace(haystack, needle, replacement) {
	var temp = haystack.split(needle);
	return temp.join(replacement);
}

function makeRequest(url, container) {
	http_request = initReq();
	url_code = encodeURIComponent(url);
	//document.getElementById("Temp").innerHTML = url_code;
	//http_request.onreadystatechange = alertContents;
	http_request.onreadystatechange = function() { alertContents(container); };
	http_request.open('POST', url, true);
	http_request.send(null);
	if (http_request.readyState == 1) {
		document.getElementById("StatusIcon").innerHTML = "<img src=\"/i/ajax-loader.gif\" width=31 height=31>";
	}
}
function alertContents(container) {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			//alert(http_request.responseText);
			document.getElementById(container).innerHTML = http_request.responseText;
			document.getElementById("StatusIcon").innerHTML = "";
		}
		else {
			document.getElementById(container).innerHTML = '<span class=biglink style="color: #a00000;">0000000.</span>';
		}
	}
}

function clearAjax(container) {
	document.getElementById(container).innerHTML = '';
}



function createform() {
	window.open("","print_win","width=800,height=600,menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
	window.setTimeout("document.getElementById('preview_list').submit();",500);
}


$j(document).ready(function(){
   	$j('.topmenu div:not(:first)').click(function(){
   	if($j(this).attr('rel') != "http://trade.tchernovaudio.com/") {
   		$j('.topmenu div').unbind('click');
   		$j('.topmenu div:first').find("img").attr("src",str_replace($j('.topmenu div:first').find("img").attr("src"),'-a.gif','.gif'));
  		$j(this).find("img").attr("src",str_replace($j(this).find("img").attr("src"),'.gif','-a.gif'));
   		var i2=$j('.topmenu div:first').find("img").attr("src");
   		//left=$j(this).parent().offset().left-$j(this).offset().left;
   		$j('.topmenu div:first').animate({"width":(isMSIE)?"159":"157","left": $j(this).position().left}, 300);
   		$j(this).animate({"width":(isMSIE)?"159":"157","left": "0"}, 300,function(){
   			window.location.href = $j(this).attr('rel');
   		});
   	}
   	});
   	$j('.topmenu div:first').click(function(){
   		$j('.topmenu div').unbind('click');
   		window.location.href = $j(this).attr('rel');
   	});
   	$j('#button_basket').click(function(){
   		$j('#nobuy').hide();
   		$j('#gobuy').show();
   	});


   	$j('.topmenu2 div:not(:first)').click(function(){
   	if($j(this).attr('rel') != "http://trade.tchernovaudio.com/") {
   		$j('.topmenu2 div').unbind('click');
   		$j('.topmenu2 div:first').find("span").html($j('.topmenu2 div:first').find("span").text());
  		$j(this).find("span").html($j(this).find("span").text());
   		var i2=$j('.topmenu2 div:first').find("span").text();
   		//left=$j(this).parent().offset().left-$j(this).offset().left;

   			$j('.topmenu2 div:first').animate({"width":(isMSIE)?"145":"143","left": $j(this).position().left}, 300);
   			$j(this).animate({"width":(isMSIE)?"159":"157","left": "0"}, 300,function(){
   				window.location.href = $j(this).attr('rel');
   			});
   	}
   	});
   	$j('.topmenu2 div:first').click(function(){
   		$j('.topmenu2 div').unbind('click');
   		window.location.href = $j(this).attr('rel');
   	});
   	$j('#button_basket').click(function(){
   		$j('#nobuy').hide();
   		$j('#gobuy').show();
   	});
});
