

$(document).ready(function(){
	
	fix_inline_links();
	//	***		Search adds
	
	$("#search_str").bind("focus",function(){
		var val = $(this).val();
		if (!empty(val) && val.toLowerCase()=="артикул") $(this).val('');
	}); 
	$("#search_str").bind("blur",function(){
		var val = $(this).val();
		if (empty(val) || val=="") $(this).val('артикул');
	}); 

	$("#from_price").bind("focus",function(){
		var val = $(this).val();
		if (!empty(val) && val.toLowerCase()=="от") $(this).val('');
	}); 
	$("#from_price").bind("blur",function(){
		var val = $(this).val();
		if (empty(val) || val=="") $(this).val('от');
	}); 
	
	$("#to_price").bind("focus",function(){
		var val = $(this).val();
		if (!empty(val) && val.toLowerCase()=="до") $(this).val('');
	}); 
	$("#to_price").bind("blur",function(){
		var val = $(this).val();
		if (empty(val) || val=="") $(this).val('до');
	}); 

	$("#btn_search").bind("click", function(){
		$("#search_box").css("display", "block");
		$("#login_box").css("display", "none");
		$("#btn_search").removeClass().addClass("btn_search_active");
		$("#btn_login").removeClass().addClass("btn_login");
		return false;
	}); 

	$("#btn_login").bind("click", function(){
		$("#search_box").css("display", "none");
		$("#login_box").css("display", "block");
		$("#btn_search").removeClass().addClass("btn_search");
		$("#btn_login").removeClass().addClass("btn_login_active");
//		alert($("#btn_login").css("display"));
		return false;
	}); 


	//	***		Homepage + Favorites
	$(".set_homepage").bind("click", function(){
		var url = location.href;											  
		if (!empty(url)) {
			$.setHomepage(url);
/*			document.body.style.behavior='url(#default#homepage)';
			if (!is_undef(window.external)) {
				window.external.setHomePage(url);
			} else	document.body.setHomePage(url);*/
		}
		return false;
	}); 


	// *** init infoBox
	var tmp_str = $(".infoBox .head h3").text();
	if (empty(tmp_str)) {
		for(var i=1; i <4; i++) {
			var tmp_head = $(".infoBox .middle td.c h" + i + ":first");
//			alert($(tmp_head).html())
			var tmp_head_val = $(tmp_head).html();
			if (!empty(tmp_head_val)) {
				$(".infoBox .head h3").html(tmp_head_val);				
				$(tmp_head).remove();
				break;
			}
		}
	}
	// ** init + on prod img
//	$(".box_prod td.photo_cell img").attr('title','asd');



	//	***		Login adds
	


/*
	$('a.compare_zakaz, a.ma_link, a.ma_basket_link, a.cat_prod').bind('click',function(){//, a.ma_link
		var id = parseInt($(this).attr('id'));
		if (id > 0) {
			$(this).removeAttr('href');
			//добавляем в корзину товар с помощью ajax
			//'hr_gate.php?test=500&r='+Math.random(),
			//'../ims/logic/hr_prod_in_basket.php?test=500&r='+Math.random(),
			JsHttpRequest.query(
				'hr_gate.php?test=500&r='+Math.random(),
				{
					'sp': "prod_in_basket"
					,'add_id': $(this).attr('id')  
				},
				function(result, errors) {
					if (errors) alert(errors);
					if (result) {
						//alert("fg")
						if (result.count_prod && result.total_sum) update_count_basket(result.count_prod,result.total_sum);
					}
				},
				true  //disable caching
			);
			$(this).html('<a class="a_prod_in_cart" href="?p=ordering">Товар<br>в корзине</a>');
			$(this).attr('title','Перейти к корзине');
		}
	});
	*/				
	
	// ** dropdown brands on cat click
	/*
	$('a.item_menu').bind('click',function(e) {
		// ** cancel default
//		if (e.preventDefault)	e.preventDefault();	if (e.stopPropagation)	e.stopPropagation();	e.cancelBubble = true;	e.returnValue = false;
	
		var parent = $(this).parent();
//		alert($(parent).html());
		if (!empty(parent)) {
			$('a.item_submenu').each(function(){
				$(this).css('display', "none");
			});
			$('a.item_submenu', parent).each(function(){
//				$(this).toggle();
				var disp = $(this).css('display');
//				window.status = disp + $(this).attr("lang");
				var status = $(this).attr("lang");
//				alert(disp);
				if (status=="opened") {
					$(this).css('display', "none");
					$(this).attr("lang", "closed")
				} else {
					$(this).css('display', "block");
					$(this).attr("lang", "opened")
				}
			});
		}
		return false;	
	});
	*/
	
		
});


jQuery.extend({
setHomepage: function(url) {
if (document.all) {
 document.body.style.behavior = 'url(#default#homepage)';
 document.body.setHomePage(url);
}
else if (window.sidebar) {
 if (window.netscape) {
  try {
   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  }
  catch (e) {
   var strTemp = '';
   strTemp += "this action was aviod by your browser,";
   strTemp += "if you want to enable,please enter about:config in your address line,";
   strTemp += "and change the value of signed.applets.codebase_principal_support to true";
   alert(strTemp);
  }
 }
 var prefs = Components.classes['@mozilla.org/preferences-service;1']
     .getService(Components.interfaces.nsIPrefBranch);
 prefs.setCharPref('browser.startup.homepage', url);
}
}
});
