jQuery.noConflict();

function IEPngFix( pngimg, gifimg, width, height, unique_name )
{
	var code = '<IMG SRC="'+ gifimg +'" WIDTH="' + width + '" HEIGHT="' + height + '" BORDER=0 name='+ unique_name +' STYLE="BACKGROUND:url('+pngimg+') no-repeat 0px 0px;">';
	if( navigator.userAgent.indexOf("Opera") > 1 ) document.write(code);
	else
		if( navigator.userAgent.indexOf("MSIE 6") > 1 ) document.write('<IMG SRC="'+gifimg+'" WIDTH="' + width + '" HEIGHT="' + height + '" BORDER="0" ALT="" STYLE="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader (src=' + pngimg + ' , sizingMethod=crop );">');
		else
			if(navigator.userAgent.indexOf("MSIE 5") != -1) document.write(code);
			else document.write(code);
}

function pics(img,ref)
{
	document.images[img].src = ref;
}

function CreateBookmarkLink() {
  if (window.sidebar) { // Mozilla Firefox Bookmark]
    window.sidebar.addPanel(location.href, document.title,"");
    //return false;
  } else if( window.external ) { // IE Favorite
		window.external.AddFavorite(location.href, document.title);
    //return false;
    }
  else if(window.opera && window.print) { // Opera Hotlist
  return true;
	}
}
 
function preloadImages(arrImg){
	for(i=0;i<arrImg.length;i++){
		img=new Image();
		img.src=arrImg[i];
	}
}
window.onload=function(){
arrImg=new Array();
if(document.getElementById('gal_thumb')!=null){
	galThumbs=$('gal_thumb').getElementsByTagName("A");
		for(i=0;i<galThumbs.length;i++){
			arrImg[i]=galThumbs[i].getAttribute("href");
		}
		preloadImages(arrImg);
	}
}

window.onscroll=function(){
	if(document.getElementById('basket_frame')!=null){
		var VRegExpPage = new RegExp(/(page=[a-z\d]+)/);
		AInputText=document.location.href;
		var VResult=VRegExpPage.exec(AInputText);
		if(VResult[1]=="page=car"){
			oCont=document.getElementById('basket_container');
			oCont.style.top=document.body.scrollTop+50;
			oCont.style.left=document.body.clientWidth/2-300;
		}
	}
}

function showBasketButton(originalRequest){
//alert("Комплектация добавлена в корзину.");

var q = eval('(' + originalRequest.responseText + ')');
show_popup("?page=basket_popup&lang="+q['lang'],q['count']);
$('item_counter').innerHTML=q['count'];
jQuery('.b_toCart').show('fast');
jQuery('.b_toCart').addClass("toCart");
}

function changePrice(originalRequest){
var q = eval('(' + originalRequest.responseText + ')');
$('tot_price').innerHTML=q['price'];
if(parseInt(q['count'])<=0 || isNaN(parseInt(q['count']))) {
		toCart=window.parent.jQuery('.toCart');
		jQuery(toCart).hide('fast');
		setTimeout("hide_popup()",800);
	}
$('item_counter').innerHTML=q['count'];
}

function show_popup(href,lines){
	if(document.getElementById('basket_frame')!=null){
		$('basket_frame').src=href;
		$('basket_frame').style.height=550+parseInt(lines)*40+'px';
		oCont=document.getElementById('basket_container');
		oCont.style.top=document.body.scrollTop+50;
		oCont.style.left=document.body.clientWidth/2-300;
		back=$('back_roll');
		back.style.width=document.body.scrollWidth;
		back.style.height=document.body.scrollHeight;
		back.style.left=0;
		back.style.top=0;
		back.style.display='block';
		oCont.style.display='block';
		
		
	}
}

function hide_popup(){
	if(document.getElementById('basket_container')!=null){
			oCont=$('basket_container');
			back=$('back_roll');
			back.style.width=0;
			back.style.height=0;
			back.style.display='none';
			oCont.style.display='none';
	}
	else if(window.parent.document.getElementById('basket_container')!=null){
			oCont=window.parent.document.getElementById('basket_container');
			back=window.parent.document.getElementById('back_roll');
			back.style.width=0;
			back.style.height=0;
			back.style.display='none';
			oCont.style.display='none';
	}
}
function checkNum(num,len){
	if(num=='') return false;
	if(num.gsub(/[0-9]/,'').length>0) return false;
    if(num.length!=len) return false;
 return true;
}
function checkNumPhone(num){
	if(num=='') return false;
	if(num.gsub(/[0-9+\-()\s]/,'').length>0) return false;
 return true;
}

function echeck(str) {
	if(str=='') return false;
	if(str.gsub(/([a-z_\-\.\d]+)+@+([a-z\d]+)+\.+([a-z]{2,3})/i,'').length>0) return false;
	return true;
}
function checkEmptyText(str) {
	if(str=='') return false;
	if(str.gsub(/[\s]/,'').length>0) return true;
	return false;
}

function selectBigImg(aObj){
	src=aObj.getAttribute("href");
	$("gal_big_pic").src=src;
	galThumbs=$('gal_thumb').getElementsByTagName("A");
	for(i=0;i<galThumbs.length;i++){
		galThumbs[i].className="gal_pic";
	}
	aObj.className="gal_a_pic";
	return false;
}
 function getNewLangUrl(AInputText,lang) {
    var VRegExpLang = new RegExp(/(lang=[a-z]+)/);
	var VRegExpPage = new RegExp(/(page=[a-z\d]+)/);
	var VRemAnchor = new RegExp(/(#[\d?]+)/);
    AInputText= AInputText.replace(VRemAnchor, "");
    if(AInputText.search(VRegExpPage)==-1){
		AInputText+="?page=index&lang=ru";
	}else if(AInputText.search(VRegExpLang)==-1){
		AInputText+="&lang=ru";
	}
	AReplaceText="lang="+lang;
    var VResult = AInputText.replace(VRegExpLang, AReplaceText);
    return VResult;
}

function redirectToNewLang(lang){
	newUrl=getNewLangUrl(document.location.href,lang);
	document.location.href=newUrl;
}


jQuery(document).ready(function(){
	jQuery('.slider').click( function()
	{
		num = jQuery(this).attr("num");
		jQuery('#aslider'+num).show();
		jQuery(this).hide();
		jQuery('#par'+num).show('slow');
		return false;
	});

	jQuery('.catMenu').click( function()
	{
		if(jQuery(this).next().css("display")=="none"){
				//jQuery(".sm2").animate({"height":"hide"},"slow");
				jQuery(".sm2").css({"display":"none"});
				jQuery(this).next().css({"display":"block"});
				//jQuery(this).next().animate({"height":"show"},"slow");
		}/*else jQuery(".sm2").hide("slow");*/
		return false;
	});

	jQuery('.aslider').click( function()
	{
		num = jQuery(this).attr("num");
		jQuery(this).hide();
		jQuery('#slider'+num).show();
		jQuery('#par'+num).hide('slow');
		return false;
	});

	


	jQuery('.b_del').click( function()
	{
		jQuery(this).parent().prev().prev().prev().hide('slow');
		jQuery(this).parent().prev().prev().hide('slow');
		jQuery(this).parent().prev().hide('slow');

		jQuery(this).parent().hide('slow');
	});

});
