window.onload=documentLoaded;
function documentLoaded(){
	drawBorder();

	var config = {
		overlayBgColor: '#000',
		overlayOpacity: '0.1',
		imageLoading: '/plugins/content/jumultithumb/media/jqlightbox/images/lightbox-ico-loading.gif',
		imageBtnClose: '/plugins/content/jumultithumb/media/jqlightbox/images/lightbox-btn-close.gif',
		imageBtnPrev: '/plugins/content/jumultithumb/media/jqlightbox/images/lightbox-btn-prev.gif',
		imageBtnNext: '/plugins/content/jumultithumb/media/jqlightbox/images/lightbox-btn-next.gif',
		containerResizeSpeed: '350',
		txtImage: 'Рисунок',
		txtOf: 'из'
	}
	
	for (var i = -1; i < 9; i++) {
		jQuery('a[rel=serial'+i+']').lightBox(config);
	}
	
	jQuery('a[@rel*=lightbox]').lightBox(config);
	
}

 
jQuery(document).ready(function() {
	jQuery(document).pngFix();
	autoclearInput();
	m5formsWidthNormalize();
	

	
	
});


function CreateBookmarkLink() {
	var url = window.document.location;
	var title = window.document.title;
	if (window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	} else if (window.external) {
		window.external.AddFavorite(url, title);
	} else if (window.opera && window.print) {
		return true;
	}
}


function autoclearInput() {
	jQuery(".autoclear").each(function() {
		jQuery(this).attr("defaultvalue", jQuery(this).attr("value"));
	});

	jQuery(".autoclear").click(function() {
		if (jQuery(this).attr("value") == jQuery(this).attr("defaultvalue")) {
			jQuery(this).attr("value", "");
		}
	});
}


function m5formsWidthNormalize(){
	if (jQuery.browser.msie && jQuery.browser.version<7) {	
		jQuery("select.m5formsNormalize").each(function(i){
			var m5formnormalizepadding=Math.ceil(Number(String(jQuery(this).css("padding-left")).slice(0,-2)))+Math.ceil(Number(String(jQuery(this).css("padding-right")).slice(0,-2)));
			var m5formnormalizeborder= Math.ceil(Number(String(jQuery(this).css("border-left-width")).slice(0,-2)))+Math.ceil(Number(String(jQuery(this).css("border-right-width")).slice(0,-2)));
			var m5formnormalizewidth=Math.ceil(Number(jQuery(this).width()))+m5formnormalizepadding+m5formnormalizeborder*2;
			jQuery(this).width(m5formnormalizewidth);
		});		
	} else {		
		jQuery("input[type=text].m5formsNormalize, input[type=password].m5formsNormalize, textarea.m5formsNormalize").each(function(i){				
			var m5formnormalizepadding=Math.ceil(Number(String(jQuery(this).css("padding-left")).slice(0,-2)))+Math.ceil(Number(String(jQuery(this).css("padding-right")).slice(0,-2)));
			var m5formnormalizewidth=Math.ceil(Number(jQuery(this).width()))-m5formnormalizepadding;			
			jQuery(this).width(m5formnormalizewidth);
			});
		jQuery("select.m5formsNormalize").each(function(i){				
			var m5formnormalizepadding=Math.ceil(Number(String(jQuery(this).css("padding-left")).slice(0,-2)))+Math.ceil(Number(String(jQuery(this).css("padding-right")).slice(0,-2)));
			var m5formnormalizeborder= Math.ceil(Number(String(jQuery(this).css("border-left-width")).slice(0,-2)))+Math.ceil(Number(String(jQuery(this).css("border-right-width")).slice(0,-2)));
			if (jQuery.browser.msie && jQuery.browser.version<8){
				var m5formnormalizewidth=Math.ceil(Number(jQuery(this).width()))+m5formnormalizepadding+m5formnormalizeborder*2;
			} else {
				var m5formnormalizewidth=Math.ceil(Number(jQuery(this).width()))+m5formnormalizepadding+m5formnormalizeborder;
			}
			jQuery(this).width(m5formnormalizewidth);
		});		
	}
}

jQuery(function() {
	cssmenuhover();
	jQuery('.img_ico').each(function(n,obj) {
		var color = jQuery(obj).parents('div.inner-box').css('background-color');
		if (color != 'rgb(255, 255, 255)' && color != '#fff') {
			jQuery(obj).attr('src', jQuery(obj).attr('src').split('.gif')[0]+'-1.gif');
		}
	});
});

function cssmenuhover() {
	if(!document.getElementById("cssmenu")) return;
	var lis = document.getElementById("cssmenu").getElementsByTagName("li");
	for (var i=0; i<lis.length; i++) {
		lis[i].onmouseover = function() {
			this.className += " iehover";
		};
		lis[i].onmouseout = function() {
			this.className = this.className.replace(new RegExp(" iehover\\b"), "");
		};
	}
}


function drawBorder() {

	jQuery('.text_content img.juimage').parent('a[rel]').each(function(n, o) {
		var w = jQuery('img', o)[0].width + 20;
		var h = jQuery('img', o)[0].height + 20;
		var html = '';
		html+= '<div style="width:'+w+'px;height:'+h+'px;background:url(\'/templates/novodent/images/border/bottom.png\') bottom left repeat-x;">';
		html+= '<div style="width:'+w+'px;height:'+h+'px;background:url(\'/templates/novodent/images/border/top.png\') top left repeat-x;">';
		html+= '<div style="width:'+w+'px;height:'+h+'px;background:url(\'/templates/novodent/images/border/left.png\') top left repeat-y;">';
		html+= '<div style="width:'+w+'px;height:'+h+'px;background:url(\'/templates/novodent/images/border/right.png\') top right repeat-y;">';
		html+= '<div style="width:'+w+'px;height:'+h+'px;background:url(\'/templates/novodent/images/border/top-right.png\') top right no-repeat;">';
		html+= '<div style="width:'+w+'px;height:'+h+'px;background:url(\'/templates/novodent/images/border/top-left.png\') top left no-repeat;">';
		html+= '<div style="width:'+w+'px;height:'+h+'px;background:url(\'/templates/novodent/images/border/bottom-right.png\') bottom right no-repeat;">';
		html+= '<div style="width:'+w+'px;height:'+h+'px;background:url(\'/templates/novodent/images/border/bottom-left.png\') bottom left no-repeat;">';
		var endhtml = '</div></div></div></div></div></div></div></div>';
		jQuery(o).replaceWith(html + '<a href="'+o.href+'" rel="'+o.rel+'">'+ jQuery(o).html() +'</a>'+ endhtml);
	});

	jQuery('.text_content img.border').each(function(n, o) {
		var w = jQuery(o)[0].width + 20;
		var h = jQuery(o)[0].height + 20;
		var html = '';
		html+= '<div style="width:'+w+'px;height:'+h+'px;background:url(\'/templates/novodent/images/border/bottom.png\') bottom left repeat-x;">';
		html+= '<div style="width:'+w+'px;height:'+h+'px;background:url(\'/templates/novodent/images/border/top.png\') top left repeat-x;">';
		html+= '<div style="width:'+w+'px;height:'+h+'px;background:url(\'/templates/novodent/images/border/left.png\') top left repeat-y;">';
		html+= '<div style="width:'+w+'px;height:'+h+'px;background:url(\'/templates/novodent/images/border/right.png\') top right repeat-y;">';
		html+= '<div style="width:'+w+'px;height:'+h+'px;background:url(\'/templates/novodent/images/border/top-right.png\') top right no-repeat;">';
		html+= '<div style="width:'+w+'px;height:'+h+'px;background:url(\'/templates/novodent/images/border/top-left.png\') top left no-repeat;">';
		html+= '<div style="width:'+w+'px;height:'+h+'px;background:url(\'/templates/novodent/images/border/bottom-right.png\') bottom right no-repeat;">';
		html+= '<div style="width:'+w+'px;height:'+h+'px;background:url(\'/templates/novodent/images/border/bottom-left.png\') bottom left no-repeat;">';
		var endhtml = '</div></div></div></div></div></div></div></div>';
		jQuery(o).replaceWith(html + '<img src="'+o.src+'" width="'+o.width+'" height="'+o.height+'" style="margin-top:10px;"/>'+ endhtml);
	});
	jQuery('.text_content img').css('margin', '10px 10px 10px 10px');
	jQuery('.text_content img.noborder').css('margin', '10px');
	

}



