$(function(){
    
    $('#navigation>ul>li:last>a').addClass('last');
    
    /*
     * Pretty forms
     */
    $('form.prettyform input[type*=radio]').css('border','none');
    $('form.prettyform input[type*=checkbox]').css('border','none');
    if($.browser.mozilla) { prettyform(); }
    
    /*
     * LI hover fix for IE6
     */
    $('#navigation ul li').each( function(){
        $(this).mouseover( function(){ $(this).addClass('hover'); } ).mouseout( function(){ $(this).removeClass('hover'); } );
    });
    
    /*
     * Blur on focus
     */
    $('a').focus(function() { this.blur(); });
    $('input[type*=submit]').focus(function() { this.blur(); });
    $('input[type=text], input[type=password]').addClass("input");
    $('.required').append(" <span>*</span>"); 
    
    $('img[title]').qtip({ 
    	style: { name: 'cream', tip: true }, 
	    position: {
	        corner: {
	           target: 'topLeft',
	           tooltip: 'bottomRight'
	        }
    	}
    });
    
    $("div.subcategory").click(function(){
  	  window.location=$(this).find("a").attr("href"); return false;
  	});
    
    $("div.subcategory").hover(
    		  function () {
    		    $(this).addClass("hover");
    		  },
    		  function () {
    		    $(this).removeClass("hover");
    		  }
    		);    
    $('a.colorbox').colorbox();
    
    if( $("div.catContent").length ) {
    	$("div.subcategory").each( function(){
    		$(this).find('h1').prependTo($(this));
    	});
    }
    $("div.subcategory:nth-child(odd)").addClass('clear');
    
});

$(document).ready(function() {
    $('.product-image img').each(function() {
    	$(this).load(function() {
        	var imgHeight = $(this).height();
        	var offset = (120 - imgHeight) / 2;
        	$(this).css('margin-top', offset);
    	});
    });
});

/*
 * Pretty forms
 */
function prettyform(){
  /*
   * Hide forms
   */
  $( 'form.prettyform' ).hide().end();
  /*
   * Label & list formatting
   */
  $( 'form.prettyform' ).find( 'label' ).not( '.noprettyform' ).each( function( i ){
    var labelContent = this.innerHTML;
    var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' );
    var labelSpan = document.createElement( 'span' );
        labelSpan.style.display = 'block';
        labelSpan.style.width = labelWidth;
        labelSpan.innerHTML = labelContent;
    this.style.display = '-moz-inline-box';
    this.innerHTML = '';
    this.appendChild( labelSpan );
  } ).end();
  
  /*
   * Show forms
   */
  $( 'form.prettyform' ).show().end();
}
