$(function($){
	//IE6 PNG FIX
	if ($.browser.msie && $.browser.version == '6.0') fn_png_fix($)
	//DROP-DOWN MENU
	$('#nav_bar li')
	.hover(function(){
		$(this).find('>ul').stop(true,false).attr('style','display:none').fadeIn('fast');
	},function(){
		$(this).find('>ul').stop(true,false).fadeOut('fast');
	})
	.find('ul').css({display:'none'});
	//IE SPECIFIC WORKAROUNDS
	if ($.browser.msie)
	(function(ver){
		if (ver[0] < 8)
		$('#nav_bar li ul').each(function(){
			$(this).find('>li>a').css({'width':'auto'});
			var w = $(this).innerWidth();
			if (w) $(this).find('>li>a').css({'width':w + 'px'});
		});
	})($.browser.version.split('.'));
	//TEXT INPUT AUTOFILL
	$('.autofill .input_text')
		.live('focus',function(){ if ($(this).val() == this.defaultValue) $(this).val(''); })
		.live('blur', function(){ if ($(this).val() == '') $(this).val(this.defaultValue); });
	//POPUP LINKS
	$('a.popup').click(function(){
		window.open(this.href,'winpopup','width=480,height=460');
		return false;
	});
	//PRINT LINKS
	$('a.print').click(function(){ window.print(); return false; });
	//HACK TO LINK THE TOP LOGO
	$('#logo img').wrap($('<a/>').attr('href','/'));
	//TEXT-WRAP POSTS
	$('.posts li p.det').each(function(){
		var c = {w:470,m:87,l:2.5};
		var $p = $(this), $d = $('<div/>').css({'white-space':'nowrap','float':'left'});
		$p.wrap($d);
		var wpl = (c.w - c.m), curl = $p.width(), maxl = Math.round(wpl * c.l), strt = $p.text(), numc = strt.length;
		$p.parent().replaceWith($p.remove());
		if (numc > 1 && curl > maxl) {
			var acw = curl / numc;
			$p.text(strt.substr(0,Math.round(maxl / acw)) + ' ...');
		}
	});
	//POST IMAGES CROP
	$('.posts li img.crop').each(function(){
		var img_old = this, img_new = new Image(), src = img_old.src, str_href = $(this).closest('li').find('p.more a').attr('href');
		img_new.onload = function(){
			var mw = img_old.width, mh = img_old.height, fw = this.width, fh = this.height;
			var arr_d = fn_img_fit([fw,fh],[mw,mh],{outer:false,enlarge:true}), arr_p = [Math.round((mw - arr_d[0]) / 2),Math.round((mh - arr_d[1]) / 2)];
			var $span = $('<a/>').attr({href:str_href,'class':$(img_old).attr('class')}).css({display:'block',position:'relative',width:mw,height:mh,overflow:'hidden'});
			$(img_old).attr({'class':''}).css({width:arr_d[0],height:arr_d[1],position:'relative',left:arr_p[0] + 'px',top:arr_p[1] + 'px'}).wrap($span);
		};
		img_new.src = src;
	});
});
function fn_isdev() {
	var a = window.location.host.split('.');
	return (a[a.length - 1] == 'local')
}
function fn_img_fit(ao,an,cfg){
	var w = 0, h = 1, cfg = cfg || {};
	var r = [ao[w],ao[h]];
	if (!cfg.enlarge)
	if (ao[w] <= an[w] && ao[h] <= an[h]) return r;
	var fit_h = (cfg.outer) ? (ao[w] / ao[h] > an[w] / an[h]) : (ao[w] / ao[h] < an[w] / an[h]);
	if (fit_h) {
		r[h] = an[h];
		r[w] = Math.round(r[w] * an[h] / ao[h]);
	} else {
		r[w] = an[w];
		r[h] = Math.round(r[h] * an[w] / ao[w]);
	}
	return r;
};
function fn_png_fix($) {
	$('.png').each(function(){
		var i1 = this, i2 = new Image();
		i2.onload = function(){
			var int_w = i2.width, int_h = i2.height;
			i1.onload = function(){
				this.onload = null;
				$(this).css({'width':int_w + 'px','height':int_h + 'px','display':'block','filter':"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + i2.src + "', sizingMethod='scale')"});
			};
			i1.src = '/img/blank.gif';
		};
		i2.src = i1.src;
	});
}
function fn_get_guid() {
	var f = function(){ return (((1+Math.random())*0x10000)|0).toString(16).substring(1); };
	return "{" + f() + f() + "-" + f() + "-" + f() + "-" + f() + "-" + f() + f() + f() + "}";
}



