a=function(data,mode){var ajax_data=null;if(mode==null||mode!=true)var mode=false;if(window.XMLHttpRequest)xmlhttp=new XMLHttpRequest;else if(window.ActiveXObject)xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");xmlhttp.open('POST','/'+sys_lang+'/ajax/',mode);xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){if(xmlhttp.status==200){ajax_data=xmlhttp.responseText;}}};xmlhttp.send(data);return xmlhttp.responseText;};
loadXML=function(txt){try{xmlDoc=new ActiveXObject("Microsoft.XMLDOM");xmlDoc.async="false";xmlDoc.loadXML(txt);return(xmlDoc);}catch(e){try{parser=new DOMParser();xmlDoc=parser.parseFromString(txt,"text/xml");return(xmlDoc);}catch(e){}}return(null)};
trim=function(str, chars) {return ltrim(rtrim(str, chars), chars);};
ltrim=function(str, chars) {chars = chars || "\\s";return str.replace(new RegExp("^[" + chars + "]+", "g"), "");};
rtrim=function(str, chars) {chars = chars || "\\s";return str.replace(new RegExp("[" + chars + "]+$", "g"), "");};
//urldecode=function(str){var histogram={},histogram_r={},code=0,str_tmp=[];var ret=str.toString();var replacer=function(search,replace,str){var tmp_arr=[];tmp_arr=str.split(search);return tmp_arr.join(replace);};histogram['!']='%21';histogram['%20']='+';for(replace in histogram){search=histogram[replace];ret=replacer(search,replace,ret);}ret=decodeURIComponent(ret);return ret;};
urlencode=function(str){string=encodeURIComponent(str).replace(/~/g,'%7E');return string.replace(/%20/g,'+');};
isMail=function(str){var filter=/^.+@.+\..{2,3}$/; return filter.test(str)};
opener=function(url,w,h){var l=(screen.width-w)/2;var t=(screen.height-h)/2;window.open(url,'','height='+h+',width='+w+',top='+t+',left='+l+',scrollbars=no,resizable=no,location=no,directories=no,status=no,menubar=no,toolbar=no')};
ga=function(obj,attr){return urldecode(obj.getAttribute(attr))};
array_search=function(needle,haystack,argStrict){var strict=!!argStrict;var key='';for(key in haystack){if((strict&&haystack[key]===needle)||(!strict&&haystack[key]==needle)){return key;}}return false};

$(document).ready(function(){
	$('.main-menu').css({'padding-right':($(document).width()-970)/2});
	$('.submenu>a').each(function(){
		$(this).click(function(e){
			e.preventDefault();
			var ul=$('.submenu>ul[rel='+$(this).parent().attr('rel')+']');
			if($(ul).css('display')=='none'){
				$(ul).slideDown();
				$('.submenu>ul').not(ul).not($(ul).parent().parent()).slideUp();
				
			}else{
				$(ul).slideUp();
			}
		});
	});
	
	$('.target').attr({'target':'_blank'});
	if(/Mozilla/.test(navigator.userAgent)){$('.footer').css({'margin-top':'-40px'});}
	$('.lang').hover(
		function(){if(!/act/.test($(this).attr('className'))){$(this).addClass('act').animate({'height':'43px'},200)}},
		function(){if(/act/.test($(this).attr('className'))){$(this).animate({'height':'14px'},200,function(){$(this).removeClass('act')})}});
	$('.email').each(function(){
		var t=$(this).text().replace('(abols)','@');
		$(this).text(t).attr('href','mailto:'+t)});
	
	switch(page){
	case 'gallery':
		$(".product").fancybox();
	break;
	case 'home':
		$(".product").fancybox();
	break;
	case 'contacts':
		$('input[type=text], textarea')
			.focus(function(){if($(this).val()==$(this).attr('rel')){$(this).val('')}$(this).addClass('focused')})
			.blur(function(){
				if($(this).val()==''){$(this).val($(this).attr('rel'))}
				if($(this).val()==$(this).attr('rel')){$(this).removeClass('focused')}
			});
		$('#contacts').submit(function(e){
			$('.message, .success').hide();
			if($('#ff1').val()==$('#ff1').attr('rel')||$('#ff1').val()==''){$('#contacts>.foot>.message').show();e.preventDefault();$('#ff1').focus();return false}
			if($('#ff2').val()==$('#ff2').attr('rel')||$('#ff2').val()==''){$('#contacts>.foot>.message').show();e.preventDefault();$('#ff2').focus();return false}
			if(!isMail($('#ff3').val())){$('#contacts>.foot>.message').show();e.preventDefault();$('#ff3').focus();return false}
			if($('#ff4').val()==$('#ff4').attr('rel')||$('#ff4').val()==''){$('#contacts>.foot>.message').show();e.preventDefault();$('#ff4').focus();return false}
		});
	break;
	}
	
	if (window.opera) {
		//alert('opra');
		//document.getElementById('foo').style.height = '100px';
	}
	
});
