var P = {};

jQuery.log = function(message) {
  if(window.console) {
     console.debug(message);
  } else {
     alert(message);
  }
};

/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);


/**
 * wapInFLuidBox
 * wraps selection into some html so a nice fluid box show up styled with css
 * @author AK|Peppered
 */

jQuery.fn.wrapInFluidBox = function() {
	$(this).wrap('<div class="fluidbox"></div>');
	oFb = $(this).parent();
	oFb.wrapInner('<div class="top"><div class="inner"></div></div>');
	oFb.append('<div class="bottom"><div class="inner">&nbsp;</div></div>');
}


/**
 * imgOverlay
 * wraps img in box, and gives it a siblinb overlay box which is positioned over it.
 * the overlay style is same as fluidbox
 * @author AK|Peppered
 */

jQuery.fn.imgOverlay = function() {
	var e = $('body').get(0);
	
	var agt=navigator.userAgent.toLowerCase();
	var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	var is_major = parseInt(navigator.appVersion);
	var is_minor = parseFloat(navigator.appVersion);
	var ie_alphaSupport = (e.runtimeStyle && typeof(e.runtimeStyle.filter) != 'undefined');
	var ie_alphaImg = (is_ie && ie_alphaSupport && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1 || agt.indexOf("msie 6.") != -1));
	
	if (is_ie && !ie_alphaSupport) {
		return;
	}
	
	$(this).each(function() {		
		/* please note: safari&opera need img width&height attrs set for these to work correctly! */
		w = $(this).width();
		h = $(this).height();
		
		if (!ie_alphaImg) {
			//- overlay w/h. substract padding:
			w = w-12;
			h = h-12;
		
			$(this).wrap('<div class="overlayContainer" style="width:' + w + 'px; height:' + h + 'px"></div>');
			oOc = $(this).parent();
			
			oOc.append('<div class="overlay fluidbox"><div class="top"><div class="inner"></div></div><div class="bottom"><div class="inner">&nbsp;</div></div></div>');
			oOc.children('div.overlay').children('div.top').css({
				width: w + "px",
				height: h + "px"
			});
		}
		else {
			// to get the job done 'nicely' in IEnoPNG, we use 4 corner imgs
			$(this).wrap('<div class="overlayContainer" style="width:' + w + 'px; height:' + h + 'px"></div>');
			oOc = $(this).parent();
			oOc.append('<div class="overlay" style="width: '+(w-2)+'px; height: '+(h-2)+'px"></div>');
			oOc.append('<div class="imgOverlayCornerContainer" class="hiddden"><span class="imgOverlayCorner-lt"></span><span class="imgOverlayCorner-rt"></span><span class="imgOverlayCorner-rb"></span><span class="imgOverlayCorner-lb"></span></div>')
		}
		
	});

}

$(function(){
	/**
	 * first-child stuff
	 */
	$('#content h4:first').addClass('first-child');
	
	/**
	 * set img overlay
	 */
	$('#content .subColumn img').imgOverlay();
});

