var dis_city = 0;
document.onclick = function(e) {
	if (dis_city == 1) {
		$('#select_city').hide();
		$('#change_city').attr("class", "fl");
		$('#change_city SPAN').show();
		$('.str').show();
		$('#win_big').hide();
		$('#div_fishka').show();
		dis_city = 0;
	}
}

document.onkeydown = function(e) {
	e = e || event;
    keyCode = undefined == e.which ? e.keyCode : e.which;

	// Листалка в поиске.
    if (keyCode == 39 && e.ctrlKey) {
		if (parseInt($("#stop_page").text()) > 1 && parseInt($("#number_page").text()) < parseInt($("#stop_page").text())) {
			location.href=$("#link_id_"+(parseInt($("#number_page").html())+1)).attr("href");
		}
	}
	if (keyCode == 37 && e.ctrlKey) {
	 	if (parseInt($("#stop_page").text()) > 1 && parseInt($("#number_page").text()) > 1) {
			location.href=$("#link_id_"+(parseInt($("#number_page").html())-1)).attr("href");
		}
	}
	
	// Листалка в фотках.
	if ($('#exact_preview_image_shadow').size() > 0) {
		if (keyCode == 39 && e.ctrlKey) {
			next_photo_nav();
		}
		if (keyCode == 37 && e.ctrlKey) {
			prev_photo_nav();
		}
		if (keyCode == 27) {
			$('#div_win').hide();
			$('#div_shadow').hide();
			self.document.location.hash = '';
		}
	}
}

$(document).ready(function() {
	// Если главная, то только тогда и фокусируемся.
	if (main == '1') {
		$('#inp_search').focus();
	}
});

function resize() {
  if (document.body.clientWidth < 991)	{
	$("BODY").css({fontSize: '75%'});
	$(".div_logo IMG").css({margin:'0 0 20px -36px;'});
	$(".form_search").css({margin:'25px 0 40px 0'});
	$(".div_result .fl TABLE.tbl_result TD SPAN").css({fontSize:'110%'});
	$(".div_result .fl TABLE.tbl_result TD").css({padding:'6px 15px 6px 0'});
	//$(".div_result .fr").hide();
	$(".div_result .fl.rf1").css({width:'100%', margin:'0px'});
	$(".div_search").css("width", "50%");
	$(".div_width_inner .div_search ").css({width:'52%'});
	$(".div_width_inner .div_logo").css({margin:'10px 0 0 0'});
	$(".inner_search").css({width:'100%'});
	$(".w100").css({width:'88%'});
	$(".w600").css({width:'600px'});
	$(".shop_info").css({fontSize:'130%'});
} else {
	$("BODY").css({fontSize: '90%'});
	$(".div_logo IMG").css({margin:'0 0 40px -36px;'});
	$(".form_search").css({margin:'42px 0 30px 0'});
	$(".footer").css({margin:'20px 0 0 0'});
	$(".div_result .fl TABLE.tbl_result TD SPAN").css({fontSize:'140%'});
	$(".div_result .fl TABLE.tbl_result TD").css({padding:'12px 56px 13px 0'});
	//$(".div_result .fr").show();
	$(".div_result .fl.rf1").css({width:'61%', margin:'0px 11% 0 0 '});
	$(".div_search").css("width", "65%");
	$(".div_width_inner .div_search ").css({width:'75%'});
	$(".div_width_inner .div_logo").css({margin:'50px 0 0 0'});
	$(".inner_search").css({width:'70%'});
	$(".w100").css({width:'61%'});
	$(".w600").css({width:'100%'});
}

}

function change_str_search() {
	div_str = $("DIV", $("#search_txt"));
	ch = 0;
	ch = Math.floor(Math.random() * (div_str.length));
	$("#str_search").html($(div_str[ch]).html());
}

function display_city(id) {
	// Not MSIE friendly.
	//$("#select_city").css("margin", "-"+(35*(id-1)+10)+"px 0 -200px -2px");
	
	//$("#select_city").css("margin-top", -(35*(id-1)+10)+"px");
	//$("#select_city").css("margin-top", "-15px");
	$("#select_city").css("margin-right", "0");
	$("#select_city").css("margin-bottom", "-250px");
	$("#select_city").css("margin-left", "-2px");
	
	$('#select_city').show();
	$('#change_city').attr("class", "fl div_no_dis");
	$('#change_city SPAN').hide();
	$('.str').hide();
	setTimeout(function() { dis_city = 1; }, 100);
	//36
}

function change_bg(id, param) {
	$("#"+id).css("backgroundPosition", param);
}

function display_map(id) {
	if ($("#"+id+"_map").css("display") == "none") {
		//$("#"+id+"_map").show();
		$("#"+id+"_map").animate({height: "show"}, 300);
		$("#"+id+"_txtmap").html("Свернуть карту");
	} else {
		//$("#"+id+"_map").hide();
		$("#"+id+"_map").animate({height: "hide"}, 300);
		$("#"+id+"_txtmap").html("Посмотреть на карте");
	}
}

function display_map_ajax(id) {
if ($("#map_active_"+id+"_map").html() == '') {
	$("#map_active_"+id+"_map").animate({height: "show"}, 300);
	$("#map_active_"+id+"_txtmap").html("Свернуть карту");
	$("#map_active_"+id+"_map").html('<img src="/images/loading.gif" style="margin:220px 4px 0 0" />&#160;загрузка')
	var sr = new sendForm_symp;
	sr.sever_file_name = "/ajax_sent_map.php?id="+id;
	sr.type_res = "obj";
	
	sr.add_accept_function_obj = function(xml) {
		$("#jscript_map_"+id).html($("data", xml).text());
	}
	sr.send();
} else {
	if ($("#map_active_"+id+"_map").css("display") == "none") {
		//$("#"+id+"_map").show();
		$("#map_active_"+id+"_map").animate({height: "show"}, 300);
		$("#map_active_"+id+"_txtmap").html("Свернуть карту");
	} else {
		//$("#"+id+"_map").hide();
		$("#map_active_"+id+"_map").animate({height: "hide"}, 300);
		$("#map_active_"+id+"_txtmap").html("Посмотреть на карте");
	}
}
}

function display_clist_map_ajax(city) {
	if ($("#map_active_map").html() == '') {
		$("#map_active_map").animate({height: "show"}, 300);
		$("#map_active_txtmap").html("Свернуть карту");
		$("#map_active_map").html('<img src="/images/loading.gif" style="margin:220px 4px 0 0" />&#160;загрузка')
		var sr = new sendForm_symp;
		sr.sever_file_name = "/ajax_sent_clist_map.php?city="+city;
		sr.type_res = "obj";
		
		sr.add_accept_function_obj = function(xml) {
			//alert($("data", xml).text());
			$("#jscript_map").html($("data", xml).text());
		}
		sr.send();
	} else {
		if ($("#map_active_map").css("display") == "none") {
			$("#map_active_map").animate({height: "show"}, 300);
			$("#map_active_txtmap").html("Свернуть карту");
		} else {
			$("#map_active_map").animate({height: "hide"}, 300);
			$("#map_active_txtmap").html("Посмотреть на карте");
		}
	}
}

function chnage_shop_left(id, div) {
	list_shop = $("DIV", $("."+div));
	for (i=0;i<list_shop.length;i++) {
		$(list_shop[i]).attr("class", "");
	}
	$("#"+id).attr("class", "activ");
	
	list_detal = $("DIV.fl", $(".detal_"+div));
	for (i=0; i<list_detal.length;i++) {
		$(list_detal[i]).animate({height: "hide"}, 500);
		//$(list_detal[i]).hide();
	}
	$("#"+id+"_txt").animate({height: "show"}, 500);
	//$("#"+id+"_txt").show();
}

function change_class(id, classname, shop) {
	if ($("#"+id).attr("class") == classname) {
		$("#"+id).attr("class", "");
		//$(".detal_shop_left_"+shop).hide();
		$(".detal_shop_left_"+shop).animate({height: "hide"}, 500);
	} else {
		$("#"+id).attr("class", classname);
		//$(".detal_shop_left_"+shop).show();
		$(".detal_shop_left_"+shop).animate({height: "show"}, 500);
	}
}

function toggle_category_search() {
	if ($('#search_in_category').attr('checked')) {
		$('#font_find').attr('action', $('#current_search_city').text() + '/catalog/' + $('#current_search_category').text() + '/find');
	}
	else {
		$('#font_find').attr('action', $('#current_search_city').text() + '/find');
	}
}

function get_selected_text() {
	var txt = '';
	if (window.getSelection) {
		txt = window.getSelection();
	}
	else if (document.getSelection) {
		txt = document.getSelection();
	}
	else if (document.selection) {
		txt = document.selection.createRange().text;
	}
	return txt;
}

try {
	window.captureEvents(Event.KeyPress);
}
catch(e) {
}
window.onkeypress = key_pressed;
function key_pressed(e) {
	key = e.keyCode || e.which;
	if ((e.ctrlKey && (key == 13)) || (e.ctrlKey && (key == 10))) {
		//window.location = 'http://www.google.kz/search?q='+get_selected_text();
		var newWindow = window.open('http://www.google.kz/search?q='+get_selected_text(), '_blank');
		newWindow.focus();
	}
}

var current_shadow_goods_image = 0;
function prev_shadow_goods_image() {
}
function next_shadow_goods_image() {
}

image1 = new Image(); image1.src = '/images/bg_win_big_top.png';
image2 = new Image(); image2.src = '/images/bg_win_big_center.png';
image3 = new Image(); image3.src = '/images/bg_win_big_bottom.png';
image4 = new Image(); image4.src = '/images/ico_close.gif';


// photos related things -- begin		
function update_photo_nav() {
	if ($('#exact_preview_image_shadow').size() == 0) { return; }

	if (photo_current == 0) { $('#prev_photo_button').hide(); }
	else { $('#prev_photo_button').show(); }
	
	if (photo_current == photo_count - 1) { $('#next_photo_button').hide(); }
	else { $('#next_photo_button').show(); }
	
	if (photo_current == 0) { photo_postfix = ''; }
	else { photo_postfix = '_' + photo_current; }
	
	$('#exact_preview_image_shadow').attr('src', photo_url + photo_postfix + '.jpg');
	
	$('.exact_thumb_image_shadow').removeClass('activ');
	$('#exact_thumb_image_shadow_' + photo_current).addClass('activ');
}

function next_photo_nav() {
	photo_current++;
	if (photo_current > photo_count - 1) {
		photo_current = 0;
	}
	update_photo_nav();
}

function prev_photo_nav() {
	photo_current--;
	if (photo_current < 0) {
		photo_current = photo_count - 1;
	}
	update_photo_nav();
}

$().ready(update_photo_nav);
// photos related things -- end