var addthis_config = {
     ui_language: "ru",
	 services_expanded: 'favorites, email, facebook, vk, twitter, gmail,100zakladok,blogger,delicious,google,mymailru,memori,zakladoknet'
}
var search_string='Введите название товара/артикул';
var def_insurance;
var cookie_time;


var prce=new Array();
var cart_text;
var session_name;
var session_id;

function search_focus(obj)
{
	if (obj.value==search_string) {$(obj).attr('value',"");$(obj).css("font-Style",'normal');$(obj).css('color','#000');}
}

function search_blur(obj)
{
	if (obj.value=='') {$(obj).attr('value',search_string); $(obj).css("font-Style",'oblique'); $(obj).css('color','#666');}
}



function search_item(search_str)
{ 
var str=search_str;
if (str!=search_string)
{
var reg= new RegExp('[\/\\\\\'\":;]', 'ig');
str=str.replace(reg,' ');
var str=$.trim(str);
str=encodeURIComponent(str);
if (str!="") document.location.href="/search/"+str+"/";
}
}


$(document).ready(function(){
	//alert($.browser.webkit);
	//$('#header a').not('a.skype').text('');
	//$('#content').css('opacity',0);
	//$('div.final_line').css('opacity',0);
	 $('input[type="button"], input[type="submit"]').each(function(){
            obj=$(this);
			var className = obj.attr('class');
			var id=obj.attr('id');
			if (id=='search_btn') rel='search';
			else rel='nofollow';
			var value=obj.val();
			var disabled=obj.attr('disabled');
			var title=obj.attr('title');
			title=(title != undefined)?title:value;
			if (disabled) obj.replaceWith('<div class="disabled_button '+className+'" id="'+id+'"><b></b><em></em><span>'+value+'</span></div>');
            else obj.replaceWith('<a rel="'+rel+'" class="button '+className+'" id="'+id+'" title="'+title+'"><b></b><em></em><span>'+value+'</span></a>');
			
        });
							   
var height=$('#left_menu_container').height();
	
$('#content_div').css('min-Height',(height)+'px');

	$("#adimg").bind("load",function () {var height=$('#left_menu_container').height();$('#content_div').css('min-Height',(height)+'px');});



	
	$('#search_str').bind('blur',function () {search_blur(this)})
	                .bind('focus',function () {search_focus(this)})
					.bind('keypress',function (event) {if(event.keyCode == 13) {search_item(this.value);return false;}})
					.val("");
	$('#search_btn').bind('click',function () {search_item($('#search_str').attr('value'));}); 
	search_blur($('#search_str')[0]);
	 
		
	
	cart_text=$('#cart_container').html();
	
	
	not_change_margin=false;
	
	if (typeof additional_dom_ready == 'function') additional_dom_ready();
	if (typeof additional_dom_ready2 == 'function') additional_dom_ready2();
	
	
	
	if (!not_change_margin) {
		
		$("img.category_img").each(function () {


	if (!this.complete) $(this).bind('load',function () {change_margin(this);$(this).unbind('load');});
	else change_margin(this);


});
	}



if (typeof $.prettyPhoto=='object')
$("a[rel^='prettyPhoto']").prettyPhoto({
		theme: 'facebook',
	
	counter_separator_label:' из ',
	overlay_gallery: false,
				
			keyboard_shortcuts: false,
			animation_speed:'normal'
	});
	
		$('#menuitem_question').bind('click', function () {
							
							question_params=(typeof question_params=='string')?question_params:"";
							
							open_window('/support/question/question_modal.php?'+question_params,330,435,true);
							//$('#tmp_div').bind('click',function () {});
							return false;
													});
	$('#menuitem_tracking').bind('click', function () {
								
							
									
							open_window('/order/tracking_login/tracking_login_modal.php',435,180,true);		
							return false;
													});
	

	$('#content').animate({opacity: 1}, 500);
	$('div.final_line').animate({opacity: 1}, 500);
	
						   });
						   
						   
function open_window(url,width,height, not_hide)
{

	$.prettyPhoto.open(url+'&iframe=true&width='+width+'&height='+height,'','',true);
	if (!not_hide) $(".pp_close").hide();
	else $(".pp_close").show();
}

function prettyphotoclose()
{
	$.prettyPhoto.close();
}

function alert_error(text)
{
	$('#error_message').text(text);
	if ($('#done_message').css('display')!='none') $('#done_message').hide();
	$('#error_message').slideDown(200);
}

function alert_done(text)
{
	$('#done_message').text(text);
	if ($('#error_message').css('display')!='none') $('#error_message').hide();
	$('#done_message').slideDown(200);
};

function change_margin(obj)
{
	var obj1=$(obj);
	$category_text=obj1.parent().children('div.category_text');
	
	$category_text.css('margin-left',(obj1.width()+parseFloat(obj1.css('margin-right'))+parseFloat($category_text.css('margin-left')) )+'px');
obj1.css('margin-right',0);
var height_img=obj1.height();
var height_text=$category_text.height();
//alert ('height_img '+height_img);
//alert ('height_text '+height_text);
if (height_img>height_text) $category_text.css('margin-top',((height_img-height_text)/2+parseFloat($category_text.css('margin-top'))+parseFloat(obj1.parent().children('h2').css('margin-bottom')))+'px');
else obj1.css('margin-top',((height_text-height_img)/2+parseFloat(obj1.css('margin-top')))+'px');

};


