var path = document.location.pathname;
if ( path.charAt(path.length-1) != '/' ) path = path+'/';

var epos = document.location.pathname.indexOf('/',1) == -1 ? document.location.pathname.length : document.location.pathname.indexOf('/',1)-1;
var section = document.location.pathname.substr(1, epos );	

$(document).ready(init);

function init() {
	$(".box a[rel]").hover (
		function () {			
			$("#"+$(this).attr("rel")).show();			
		},
		function () {						
			$("#"+$(this).attr("rel")).hide();			
		}
	);
	
	$(".submenu").hover (
		function () { $(this).show(); },
		function () { $(this).hide(); }
	);
	
	$(".preview2 a").click(onPreview2Click);
	$(".preview2 a").dblclick(onPreview2DblClick);
	
	try {
		if ( section != '' ) {
			$("#section-title").attr({src:"/images/titles/"+section+".gif"});	
			var img_src = $("#menu a[href^=/"+section+"] img").attr("src");	
			$("#menu a[href^=/"+section+"] img").attr("src",img_src.replace("default", "selected"));
			$("#menu a[href^=/"+section+"]").addClass("selected");
		}
	} catch (e) {}

	$("#email").focus(
		function () {
			if ( $(this).attr("value") == "введите ваш e-mail:" )
				$(this).attr("value","");
		}
	);
	$("#email").blur(
		function () {			
			if ( !$(this).attr("value") )
				$(this).attr("value","введите ваш e-mail:");
		}
	)
}

function onPreview2Click( eventObject ) {
	
	if ( !( /preview/.test($(this).attr('href')) ) )
		$(this).attr('href', $(this).attr('href').replace('products/','products/preview_'));

	$("#main_photo a").attr('src',$(this).attr('href').replace('preview_',''));
	$("#main_photo img").attr('src',$(this).attr('href'));
	
	return false;
}

function onPreview2DblClick( eventObject ) {
	$(this).attr('href', $(this).attr('href').replace('preview_',''));		
	$(this).lightbox({start:true,events:false}); 
	return false;	
}
