function showmenu(elmnt)
{
	document.getElementById(elmnt).style.visibility="visible" ;
}
function hidemenu(elmnt)
{
	document.getElementById(elmnt).style.visibility="hidden" ;
}
function openOrderForm() {
	window.open("./form.php","newWindow","menubar=0,status=0,scrollbars=1,resizable=1,width=550,height=400");
}
function openOrderFormForProductId(prodId,phpSessId) {
	window.open("./form-order.php?PHPSESSID="+phpSessId+"&product="+prodId,"newWindow","menubar=0,status=0,scrollbars=1,resizable=1,width=550,height=500");
}
function showProductTable(tableId) {
	$('#'+tableId).slideToggle({duration:"normal"});
}
function showPageTitle(pageId) {
	$('.content-title').load('db/gs_pages-'+pageId+'-name_ru.htm');
}
function readMore(divId) {
	$('#read-more-'+divId).slideToggle({duration:"normal"});
}

function loadPage(pageId, pageAltUrl) {
	$('#content-div').html('<p align="center"><img src="images/lightbox-ico-loading.gif" alt="" /></p>');
	// LOADING BROWSER TITLE
	$.ajax({
		   url: 'db/'+pageId+'-head-title.htm',
		   dataType: "text",
		   success: function(docTitle) { document.title = docTitle ; }
	});
	// LOADING CONTENT
	$.ajax({
		   url: 'db/'+pageId+'-content.htm',
		   success: function(contentHtml) {
				$('#content-div').html(contentHtml);
				// LOADING CONTENT TITLE
				$.ajax({
					url: 'db/'+pageId+'-name.htm',
					success: function(contentTitle) { 
						$('#title-div').html(contentTitle);
						bindLinks();
					}
				});
		   },
		   error: function() {
				$('#content-div').addClass("not-found");
		   }
	});
	// REDIRECTING TO ALT URL ON ERROR
	if( $('#content-div').hasClass("not-found") ) {
		$('#content-div').removeClass("not-found");
		window.location.assign(pageAltUrl);
		return false;
	}
}

function bindLinks() {
    $('#gallery a').filter("a:not('.binded')").addClass("binded").lightBox();
    $('a.box').filter("a:not('.binded')").addClass("binded").lightBox();
    $("a[href$='.jpg']").filter("a:not('.binded')").addClass("binded").addClass("binded").lightBox();
    $("a[href$='.gif']").filter("a:not('.binded')").addClass("binded").addClass("binded").lightBox();
    $("a[href$='.png']").filter("a:not('.binded')").addClass("binded").addClass("binded").lightBox();
    $("a[href$='form.php']").filter("a:not('.binded')").addClass("binded").addClass("binded").click( function() {
					openOrderForm();
					return false;
	});

	$('.homepage-link').filter("a:not('.binded')").addClass("binded").bind( 'click' , function() { window.location=location.pathname; } );

	$("a.show-product").filter("a:not('.binded')").addClass("binded").click( function() {
					var productUrl = $(this).attr("href");
					productUrl = productUrl+'&show_content_only=1';
					window.open(productUrl,"newWindow","menubar=0,status=0,scrollbars=1,resizable=1,width=770,height=600");
					return false;
	});

	$(".blog li").each( function() {
					var ajaxUrl = $(this).find('a.item-title').attr("href") ;
					if( ajaxUrl ) {
						$(this).find('img').filter("img:not('.table-image')").filter("img:not('.link-pointer')").addClass("link-pointer")
						.attr("title",ajaxUrl).click( function() {
							var ajaxUrl = $(this).attr("title");
							window.location.assign(ajaxUrl);
						});
					}
	});

	$('.topnav a').removeClass('active');
	$("#title-div a").each( function() {
		var inWayPageId = $(this).attr("rel") ;
		$(".topnav a[rel='"+inWayPageId+"']").addClass('active');
		$(".left-nav a[rel='"+inWayPageId+"']").addClass('active');
	});
	$("#title-div a:last").each( function() {
		var inWayPageId = $(this).attr("rel") ;
		$(".left-nav a[rel='"+inWayPageId+"']").addClass('current');
	});

	$('.section a').filter("a:not('.section-binded')").addClass("section-binded").click( function() {
		var thisPageId = $(this).attr("rel") ;
		var pageAltUrl = $(this).attr("href") ;
		if( $(this).hasClass('current') ) {
			$("div.subitemOf-"+thisPageId).slideToggle("normal");
		}
		else {
			$(".section a").removeClass('active').removeClass('current');
			$(this).addClass('active').addClass('current');
			$('div.subitemDiv').filter("div:not('.subitemOf-"+thisPageId+"')").slideUp("normal");
			$("div.subitemOf-"+thisPageId).slideDown("normal");
			loadPage(thisPageId, pageAltUrl);
		}
		return false;
	});
}

$(document).ready(function() {
    bindLinks();
					var usdRur = $("#insert_rate_USD_1230665428").text();
					var usdRurDiff = $("#insert_rate_USD_1230665428").text();
					var eurRur = $("#insert_rate_EUR_1230665428").text();
					var eurRurDiff = $("#insert_rate_EUR_1230665428").text();
					$("#usd-rur").html(usdRur);
					$("#usd-rur-diff").html('');
					$("#eur-rur").html(eurRur);
					$("#eur-rur-diff").html('');
});
