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);

var menuNames = new Array('about', 'articles', 'catalogue', 'certification', 'company', 'contacts', 'cooperation', 'order');
var imagesD = new Array();
var imagesH = new Array();
for ( i in menuNames ) {    
    var key = menuNames[i];
    imagesD[key] = new Image();
    imagesD[key].src = '/images/menu/default/'+key+'.gif';
    
    imagesH[key] = new Image();
    imagesH[key].src = '/images/menu/hover/'+key+'.gif';
}

function init() {		
	/*$("#hits-news .news a").hover(
		function () {
			var id = $(this).attr("rel");
			$(this).after('<div id="box-'+id+'" class="picture-box"><div class="img"><b class="tlc"></b><b class="trc"></b><b class="blc"></b><b class="brc"></b></div></div>');
			
			$("#box-"+id+" .img").append("<img src='images/tmp/cp1.jpg'/>")		
			
			return false;
		},
		function () {
			var id = $(this).attr("rel");
			$("#box-"+id).remove();
		}
	);
	
	$("#images .img a").click(
		function () {
			var src = $(this).attr("href");
			$("#big-image").attr('src', src);
			return false;
		}
	);*/
    
    $("#menu a").hover(
		function () {
			var name = $(this).attr('href').replace('/','');            
			$("img", $(this)).get(0).src = imagesH[name].src;
		},
		function () {
            var name = $(this).attr('href').replace('/','');						
            $("img", $(this)).get(0).src = imagesD[name].src;
		}
	);
    
    
	if(typeof sIFR == "function") {
		sIFR.replaceElement("#data h1.title", named({
			sFlashSrc: "/fonts/Micra.swf", 			
			sColor: "#ffffff",			
			sWmode: "transparent",
			sCase: "upper"
		}));
	};
    
    try {
		if ( path != '/' ) {			
            var src = $("#menu a[href^='/"+section+"'] img").attr('src').replace('default','selected');
            $("#menu a[href^='/"+section+"'] img").attr('src', src);
            
            
            $("#catalogue a").each (
                function () {
                    
                    var href = $(this).attr("href");                    
                    if ( path.indexOf(href) == 0 ) {
                        
                        var src = $("#catalogue a[href='"+href+"'] img").attr('src').replace('default','selected');                        
                        $("#catalogue a[href='"+href+"'] img").attr('src', src);                        
                        $('<div id="arrow"></div>').prependTo("#catalogue a[href='"+href+"']");                                                
                        return;
                    }
                }
            );            
		}
        
        
        $("table.tech tr:nth-child(even)").addClass("grey");	
        
	} catch (e) {}

	
}

function sendForm( name ) {
	try {
		var n = document.forms[name].length;		
		
		var i = 0;
		while ( i < n ) {		
			if ( document.forms[name].elements[i].value == '' && document.forms[name].elements[i].className != 'nrq' ) {
				alert('Не все поля зополнены');
				
				document.forms[name].elements[i].focus();
				return;
			}
		
			i++;
		}
		document.forms[name].submit();		
	}
	catch ( ex ) {
		alert(ex);
	}
}

function clearForm( name ) {
	try {
		var n = document.forms[name].length;		
		
		var i = 0;
		while ( i < n ) {		
			document.forms[name].elements[i].value = '';				
			i++;
		}		
	}
	catch ( ex ) {
		alert(ex);
	}
}
