
function change_main_product(product_id, lang) {
	//$('div .main_product_block').html("<img src='/img/ajax-loader.gif'>");
	$('div .main_product_block').load("/html_content/"+lang+"/products/product_main_"+product_id+".phtml");
}

// вешаем действия на селекты
function selects_bind() {
	// выбор значения
	$('.select').find('.select_popup').find('a').unbind('click');
	
	$('.select').find('.select_popup').find('a').attr("href","javascript:void(0)").bind("click", function() {
		$html 	= $(this).html();
		$value	= $(this).attr('select_value');
		$(this).parent().prev().html($html);
		$(this).parent().prev().prev().val($value);
		$('[opened_by_click="yes"]').find('.select_popup').addClass('display_no');
		$('[opened_by_click="yes"]').attr('opened_by_click','no');
	});
	
	// открытие селекта
	$('.select').unbind('click');
	
	$('.select').bind("click", function() {
		// скрываем открытые
		$('[opened_by_click="yes"]').find('.select_popup').addClass('display_no');
		$('[opened_by_click="yes"]').removeAttr('opened_by_click');
		// открываем кликнутый
		if($(this).attr('opened_by_click') != "no") {
			$(this).attr('opened_by_click','yes');
			$(this).find('.select_popup').removeClass('display_no');
		} else {
			$(this).removeAttr('opened_by_click');
		}
	});
	
	$('.select').find(".button").find("a").attr("href","javascript:void(0)")
}

$(document).ready(function() {
	
	selects_bind();
	
	// скрываем все селекты при клике в куда-нибудь
	$(document).click( function(e) {
		var el			= e ? e.target : event.srcElement;
		var el_parents	= $(el).parents();
		var to_hide		= true;
		$(el_parents).each(function() {
			if($(this).attr("class") == "select") {
				to_hide = false;
			}
		});
		if(to_hide) {
			$('.select_popup').addClass('display_no');
		}
	});
});

function popup_show(link_id) {
	var offs 		= $('#'+link_id).offset();
	var	popup_id	= "popup_" + link_id.replace("popup_link_","");
	$('#single_popup_div').find('.name').html($('#' + link_id).html());
	$('#single_popup_div').find('.text').html($('#' + popup_id).html());
	
	window_height 	= $(window).height();
	window_top		= $(window).scrollTop();
	link_top		= offs.top;
	link_left		= offs.left;
	popup_height	= $('#single_popup_div').height();

	
	if(link_top - window_top > popup_height) {
		$('#single_popup_div').css('top', link_top - popup_height + 5);
		$('#single_popup_div').css('left',link_left);
		$('#single_popup_div').find('.top').find('img:first').attr('src','/img/popup_bg_top.png').attr('height','14');
		$('#single_popup_div').find('.bot').find('img:first').attr('src','/img/popup_bg_bot.png').attr('height','42');
	} else {
		$('#single_popup_div').css('top', link_top + 21);
		$('#single_popup_div').css('left',link_left - 320);
		$('#single_popup_div').find('.top').find('img:first').attr('src','/img/popup_bg_top2.png').attr('height','42');
		$('#single_popup_div').find('.bot').find('img:first').attr('src','/img/popup_bg_bot2.png').attr('height','14');
	}
	
	$('#single_popup_div').show();
}

function popup_hide() {
	$('#single_popup_div').hide();
}

function popup_drow() {
	popup_html =	'	<!-- popup block -->' +
					'	<div id="single_popup_div" class="popup_block" style="position:absolute; left: 0px; top: 0px; display: none;">' +
					'		<div class="top"><img src="/img/popup_bg_top.png" width="330" height="14" class="png-pic" /></div>' +
					'		<div class="middle">' +
					'			<div class="name"> </div>' +
					'			<div class="text">' +
					'			</div>' +
					'		</div>' +
					'		<div class="bot"><img src="/img/popup_bg_bot.png" width="330" height="42" class="png-pic" /></div>' + 
					'	</div>' +
					'	<!-- popup block -->';
	$('body').append(popup_html);
}

$(document).ready(function() {
	popup_drow();
	$('[id^="popup_link_"]').hover( function(e) { popup_show($(this).attr("id"));}, function() { popup_hide() });
});



$(document).ready(function() {
	$('#dark-box-dark').css('height',$(document).height());
	$('#dark-box-content').find('.x_button').click(function() {
		dark_box_hide();
	});
});

function move_dark_box_content() {
	window_top	= $(window).scrollTop();
	$('#dark-box-content').css("top", window_top + 20);
}

function dark_box_hide() {
	$('#dark-box-content').hide();
	$('#dark-box-dark').hide();
}

function dark_box_show() {
	$('#dark-box-content').show();
	$('#dark-box-dark').show();
}

function darkbox_show_video(video_id) {
	inner_date = new Date();
	video_html = 	'<object width="644" height="392" align="middle" id="player" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">' +
					
					'	<param value="false" name="allowFullScreen"/>' +
					'	<param value="transparent" name="wmode"/>' +
					'	<param value="config=/php_content/video/video_' + video_id + '.php?ac=' + inner_date.getTime() + '" name="flashvars"/>' +
					'	<param value="/system/data/player.swf?ac=' + inner_date.getTime() + '" name="movie"/><param value="high" name="quality"/><param value="#626262" name="bgcolor"/>' +
					'<embed width="644" height="392" align="middle" flashvars="config=/php_content/video/video_' + video_id + '.php?ac=' + inner_date.getTime() + '" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowfullscreen="false"  name="player" bgcolor="#626262" quality="high" src="/system/data/player.swf?ac=' + inner_date.getTime() + '" wmode="transparent"/>';
					'</object>';
	$('#dark-box-content').find('.dark-box-content-inner').html(video_html);
	move_dark_box_content()
	dark_box_show();
}

function darkbox_show_image(image) {
	image_html = '<img src="' + image + '">';
	$('#dark-box-content').find('.dark-box-content-inner').html(image_html);
	move_dark_box_content()
	dark_box_show();
}