(function($){
     $.fn.extend({
          center: function () {
                return this.each(function() {
                    var t = jQuery(this);
                    var p = jQuery(this).parent();
                    w = p.width(); 
                    h = p.height();
                    mtop = (h - t.height()) / 2;
                    mleft = (w - t.outerWidth()) / 2;
                    t.css({'margin-top': mtop, 'margin-left': mleft});
                });
        }
     });
})(jQuery);



$(document).ready(function() {
	$(".datepicker").datepicker({ dateFormat: 'yy-mm-dd' });
	
	$('#session_flash_message').delay(5000).fadeOut('slow');
	$("#flashMessage").click(function() { $(this).next().hide(); $(this).hide(); })
	$('#flashMessage').after(function() {
		if($(this).hasClass('error-message')) {
			return '<div class="arrow-down arrow-error"></div>';
		}
		return '<div class="arrow-down"></div>';
	});
	
	$("#items-table tr, .inner-table tr, .admin-table tr").live({
		mouseover: function() { 
		   	$(this).addClass("hover");	
		},
		mouseout: function() { 
		   	$(this).removeClass("hover");
		}
	});
	

/* --- Navigation ------------------------------------------------------------------------------------------------------------- */
	
	$("#catNav span.special").each(
		function() {
			v = $(this).parent().outerWidth() - $(this).prev().outerWidth();
			$(this).width(v).show();
		}
	);
	

	$("#catNav ul li.depth-0").hover(
	   function() {
		   $('#navigation').height('100%');
		    $(this).addClass("hover");
		   	li = $(this);
		   	menu = li.parent();
	    	sub = $(this).find("ul");

	    	m_pos = menu.position();
	    	m_width = 1200;

			width = sub.outerWidth();
			width_i = sub.width();

			pos = li.position();
			mleft = pos.left;
	    	if(mleft+width > m_width) {
		    	mleft = m_width - width;
	    	}
	    	sub.css({ "margin-left": mleft + "px"})
	    	//sub.css({ "width": width_i + "px"})
	   },
	   function() {
	    	$(this).removeClass("hover");
	    	$('#navigation').height(45);
	   }
	);
	
/* ---------------------------------------------------------------------------------------------------------------------------- */

});



(function($){
	 $.fn.extend({
	 
	 	customStyle : function(options) {
		  if(!$.browser.msie || ($.browser.msie&&$.browser.version>6)){
		  return this.each(function() {
		  
				var currentSelected = $(this).find(':selected');
				$(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">'+currentSelected.text()+'</span></span>').css({position:'absolute', opacity:0,fontSize:$(this).next().css('font-size')});
				var selectBoxSpan = $(this).next();
				var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) -parseInt(selectBoxSpan.css('padding-right'));			
				var selectBoxSpanInner = selectBoxSpan.find(':first-child');
				selectBoxSpan.css({display:'inline-block'});
				selectBoxSpanInner.css({width:selectBoxWidth, display:'inline-block'});
				var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
				$(this).height(selectBoxHeight).change(function(){
					// selectBoxSpanInner.text($(this).val()).parent().addClass('changed');   This was not ideal
				selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('changed');
					// Thanks to Juarez Filho & PaddyMurphy
				});
				
		  });
		  }
		}
	 });
})(jQuery);




