/*
 * jQuery ifixpng plugin
 * (previously known as pngfix)
 * Version 2.0  (04/11/2007)
 * @requires jQuery v1.1.3 or above
 *
 * Examples at: http://jquery.khurshid.com
 * Copyright (c) 2007 Kush M.
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */
 
 /**
  *
  * @example
  *
  * optional if location of pixel.gif if different to default which is images/pixel.gif
  * $.ifixpng('media/pixel.gif');
  *
  * $('img[@src$=.png], #panel').ifixpng();
  *
  * @apply hack to all png images and #panel which icluded png img in its css
  *
  * @name ifixpng
  * @type jQuery
  * @cat Plugins/Image
  * @return jQuery
  * @author jQuery Community
  */
 
(function($) {

	/**
	 * helper variables and function
	 */
	$.ifixpng = function(customPixel) {
		$.ifixpng.pixel = customPixel;
	};
	
	$.ifixpng.getPixel = function() {
		return $.ifixpng.pixel || 'images/pixel.gif';
	};
	
	var hack = {
		ltie7  : $.browser.msie && $.browser.version < 7,
		filter : function(src) {
			return "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=crop,src='"+src+"')";
		}
	};
	
	/**
	 * Applies ie png hack to selected dom elements
	 *
	 * $('img[@src$=.png]').ifixpng();
	 * @desc apply hack to all images with png extensions
	 *
	 * $('#panel, img[@src$=.png]').ifixpng();
	 * @desc apply hack to element #panel and all images with png extensions
	 *
	 * @name ifixpng
	 */
	 
	$.fn.ifixpng = hack.ltie7 ? function() {
    	return this.each(function() {
			var $$ = $(this);
			var base = $('base').attr('href'); // need to use this in case you are using rewriting urls
			if ($$.is('img') || $$.is('input')) { // hack image tags present in dom
				if ($$.attr('src')) {
					if ($$.attr('src').match(/.*\.png([?].*)?$/i)) { // make sure it is png image
						// use source tag value if set 
						var source = (base && $$.attr('src').substring(0,1)!='/') ? base + $$.attr('src') : $$.attr('src');
						// apply filter
						$$.css({filter:hack.filter(source), width:$$.width(), height:$$.height()})
						  .attr({src:$.ifixpng.getPixel()})
						  .positionFix();
					}
				}
			} else { // hack png css properties present inside css
				var image = $$.css('backgroundImage');
				if (image.match(/^url\(["']?(.*\.png([?].*)?)["']?\)$/i)) {
					image = RegExp.$1;
					$$.css({backgroundImage:'none', filter:hack.filter(image)})
					  .children().children().positionFix();
				}
			}
		});
	} : function() { return this; };
	
	/**
	 * Removes any png hack that may have been applied previously
	 *
	 * $('img[@src$=.png]').iunfixpng();
	 * @desc revert hack on all images with png extensions
	 *
	 * $('#panel, img[@src$=.png]').iunfixpng();
	 * @desc revert hack on element #panel and all images with png extensions
	 *
	 * @name iunfixpng
	 */
	 
	$.fn.iunfixpng = hack.ltie7 ? function() {
    	return this.each(function() {
			var $$ = $(this);
			var src = $$.css('filter');
			if (src.match(/src=["']?(.*\.png([?].*)?)["']?/i)) { // get img source from filter
				src = RegExp.$1;
				if ($$.is('img') || $$.is('input')) {
					$$.attr({src:src}).css({filter:''});
				} else {
					$$.css({filter:'', background:'url('+src+')'});
				}
			}
		});
	} : function() { return this; };
	
	/**
	 * positions selected item relatively
	 */
	 
	$.fn.positionFix = function() {
		return this.each(function() {
			var $$ = $(this);
			var position = $$.css('position');
			if (position != 'absolute' && position != 'relative') {
				$$.css({position:'relative'});
			}
		});
	};

})(jQuery);jQuery(document).ready(function() {
	// Stuff to do as soon as the DOM is ready;
	jQuery('.micro-teasers, .micro-teaser span, .menu-image, .micro-main-teaser h2, .micro-main-teaser p').ifixpng();

	//
	var highestCol = Math.max(jQuery('.menu').outerHeight(),jQuery('.micro-wrapper.micro-panel.clearfix').outerHeight());
	mpb = jQuery('.menu').outerHeight() - jQuery('.menu').height();
	jQuery('.menu').height(highestCol-mpb);
	mpb = jQuery('.micro-wrapper.micro-panel.clearfix').outerHeight() - jQuery('.micro-wrapper.micro-panel.clearfix').height();
	jQuery('.micro-wrapper.micro-panel.clearfix').height(highestCol-mpb);

	highestCol = Math.max(jQuery('.menu').outerHeight(),jQuery('.micro-wrapper').outerHeight());
	mpb = jQuery('.menu').outerHeight() - jQuery('.menu').height();
	jQuery('.menu').height(highestCol-mpb);
	mpb = jQuery('.micro-wrapper').outerHeight() - jQuery('.micro-wrapper').height();
	jQuery('.micro-wrapper').height(highestCol-mpb);
	
});


$.fn.outerHeight = function() {
	var h, mT, mB, pT, pB, bT, bB;
	//height = parseInt(this.height(), 10) + parseInt(this.css('marginTop'), 10) + parseInt(this.css('marginBottom'), 10) + parseInt(this.css('paddingTop'), 10) + parseInt(this.css('paddingBottom'), 10) + parseInt(this.css('borderTopWidth'), 10) + parseInt(this.css('borderBottomWidth'), 10);

	h = (isNaN(parseInt(this.height(), 10))) ? 0 : parseInt(this.height(), 10);
	mT = (isNaN(parseInt(this.css('marginTop'), 10))) ? 0 : parseInt(this.css('marginTop'), 10);
	mB = (isNaN(parseInt(this.css('marginBottom'), 10))) ? 0 : parseInt(this.css('marginBottom'), 10);
	pT = (isNaN(parseInt(this.css('paddingTop'), 10))) ? 0 : parseInt(this.css('paddingTop'), 10);
	pB = (isNaN(parseInt(this.css('paddingBottom'), 10))) ? 0 : parseInt(this.css('paddingBottom'), 10);
	bT = (isNaN(parseInt(this.css('borderTopHeight'), 10))) ? 0 : parseInt(this.css('borderTopHeight'), 10);
	bB = (isNaN(parseInt(this.css('borderBottomHeight'), 10))) ? 0 : parseInt(this.css('borderBottomHeight'), 10);
	
	return h + mT + mB + pT + pB + bT + bB;
};


$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		//if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};

/*
function showTeser(id)
{
   if(document.getElementById('currentStory')!=null && document.getElementById('currentStory').value!='' && document.getElementById(id)!=null)
   {
       document.getElementById(document.getElementById('currentStory').value).style.display='none';
	   document.getElementById(id).style.display="block";
	   document.getElementById('currentStory').value=id;
   }
}
*/
function showTeser(id) {
	if(id && jQuery('#'+id).length>0) {
		jQuery('.micro-main-teaser').hide();
		jQuery('#' + id).show();
	}
}

