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() {		
	/*$("#menu a").hover(
		function () {									
			var name = $(this).attr("href").replace('/','');
			
			if ( name == section ) return;
						
			$("#"+name).addClass("left");
			$(this).parent().addClass("selected");
			$("#"+name+" + th + td").addClass("right");
		},
		function () {			
			var name = $(this).attr("href").replace('/','');			
			
			if ( name == section ) return;
			
			$("#"+name).removeClass("left");			
			$(this).parent().removeClass('selected');
			$("#"+name+" + th + td").removeClass("right");
		}
	);*/
	
	/*$(".box.catalogue a").hover (
		function() {
			var src = $("img.icon", $(this)).attr('src').replace('default','selected');
			$("img.icon", $(this)).attr('src', src);
			
			var src = $("img[class!='icon']", $(this)).attr('src').replace('default','selected');
			$("img[class!='icon']", $(this)).attr('src', src);
		},
		function() {
			var src = $("img.icon", $(this)).attr('src').replace('selected','default');			
			$("img.icon", $(this)).attr('src', src);
			
			var src = $("img[class!='icon']", $(this)).attr('src').replace('selected','default');
			$("img[class!='icon']", $(this)).attr('src', src);
		}
	);*/
    
    $("#search input").click (
        function () { if ( $(this).attr("value") == 'введите ключевое слово' ) $(this).attr("value",''); }
    )
    $("#search input").blur (
        function () { if ( !$(this).attr("value") ) $(this).attr("value","введите ключевое слово") }
    );
    
    
	try {
		if ( path != '/' ) {
			$("#menu a[href^='/"+section+"']").parent().addClass("active");			
 		
			$("#bottom-menu a[href^='/"+section+"']").addClass("current");
		}
		
		if ( path.indexOf('/catalogue/') == 0 ) {		
			path.match(new RegExp("/catalogue/(\\d+)"));		
			var id = RegExp.$1;
			$("#cat a[href$='/catalogue/"+id+"']").parent().addClass("active");	
			
			  
		}
	} catch (e) {}
	/*$("#images .img a").click(
		function () {
			var src = $(this).attr("href");
			$("#big-image").attr('src', src);
			return false;
		}
	);*/
	
	if(typeof sIFR == "function") {
		sIFR.replaceElement("#data h1.title", named({
			sFlashSrc: "/fonts/YanusC.swf", 			
			sColor: "#4c4c4c",			
			sWmode: "transparent",
			sCase: "upper"
		}));
		
		sIFR.replaceElement(".box h1.title", named({
			sFlashSrc: "/fonts/YanusC.swf", 			
			sColor: "#ffffff",			
			sWmode: "transparent",
			sCase: "upper"
		}));
		
		sIFR.replaceElement(".price strong", named({
			sFlashSrc: "/fonts/YanusC.swf", 			
			sColor: "#000000",			
			sWmode: "transparent",
			sCase: "upper"
		}));
		
		sIFR.replaceElement(".price span", named({
			sFlashSrc: "/fonts/YanusC.swf", 			
			sColor: "#000000",
			sWmode: "transparent",
			sCase: "upper"
		}));
	};
	
}

function viewImage(image)
{
	var win = window.open(
		'/viewimage/image-'+image+'/', 
		'ViewImage',
		"scrollbars=1, resizable=1, titlebar=1,height=600, width=650, left="+(screen.width-700)+", top=20")
}

function printView(id)
{
	var win = window.open(
		'/printview/id-'+id+'/', 
		'PrintView',
		"scrollbars=1, resizable=1, titlebar=1,height=600, width=700, left="+(screen.width-750)+", top=20")
}

function viewIcon(url)
{
	var win = window.open(
		url, 
		'ViewIcon',
		"scrollbars=1, resizable=1, titlebar=1,height=600, width=650, left="+(screen.width-700)+", top=20")
}

function add1Cart(id, count) {
	/*var win = window.open(
		'/cart/action-add1cart/id-'+id+'/count-'+count+'/',
		'Add1Cart',
		"scrollbars=1, resizable=1, titlebar=1, height=520, width=700, left="+(screen.width-750)+", top=20");*/
        
    document.location = "/cart/action-add1cart/id-"+id+"/count-"+count+"/?from="+encodeURIComponent(document.location);
    return false;
}

function makeOrder() {
	var win = window.open(
		'/makeorder/',
		'MakeOrder',
		"scrollbars=1, resizable=1, titlebar=1, height=520, width=700, left="+(screen.width-750)+", top=20");
}

function openWindow( url, w, h ) {
	var win = window.open(
		url,
		'PopupWindow',
		"scrollbars=1, resizable=1, titlebar=1, height="+h+", width="+w+", left="+(screen.width/2-w/2)+", top=20");	
}
