$(function(){ 

	// Preload images
	$.preloadCssImages();



    // Find all the input elements with title attributes and add hint to it
    $('input[title!=""]').hint();
    
    
    
    /*$(" #catnav ul ").css({display: "none"}); // Opera Fix
	$(" #catnav li").hover(function(){
		$(this).addClass('hover');
		$(this).find('ul:first').css({visibility: "visible",display: "block"}).slideDown(400);
	},function(){
		$(this).removeClass('hover');
		$(this).find('ul:first').css({visibility: "hidden",display: "none"});
	});
	
	
	
	$(" #pagenav_wrapper .inner .pagenav ul ul ").css({display: "none"}); // Opera Fix
	$(" #pagenav_wrapper .inner .pagenav li").hover(function(){
		$(this).addClass('hover');
		$(this).find('ul:first').css({visibility: "visible",display: "block"}).show(400);
	},function(){
		$(this).removeClass('hover');
		$(this).find('ul:first').css({visibility: "hidden",display: "none"});
	});*/
	
	
	$('#catnav li').each(function(){ 
		var navChildren = $(this).find('ul.children');
		
		//if has submenu
		if(navChildren.length > 0)
		{
			var childrenHTML = navChildren.html();
			navChildren.remove();
			
			var styleSubNav = '<div class="popup">';
			styleSubNav += '<div class="top"></div>';
			styleSubNav += '<div class="content"><ul class="submenu">'+childrenHTML+'</ul><br class="clear"/></div>';
			styleSubNav += '<div class="footer"></div>';
			
			$(this).append(styleSubNav);
		}
	});
	
	
	// Setup main navigation menu
	$('#catnav li a').each(function(){ 
		$(this).click(function(){
			
			$('#catnav li a').removeClass('selected');
			$('.popup').css('display', 'none');
				
			$(this).addClass('selected');
				
			var popup = $(this).parent().find('.popup');
				
			//if has submenu
			if(popup.length > 0)
			{
				//get the position of the placeholder element
  				var pos = $(this).parent().offset();
  				var width = $(this).parent().width();
  				var popupPos = pos.left-80+(width/2)+1;

  				//show the menu directly over the placeholder
  				popup.css( { "left": popupPos + "px", "top":pos.top + 48 + "px" } );
  				popup.show();
  					
  				return false;
			}
		});
	});
	$(document).click(function(){
		$('.popup').css('display', 'none');
		$('.popup').parent().find('a').removeClass('selected');
	});
	
	
	
	// Setup contact form
	$.validator.setDefaults({
		submitHandler: function() { 
		    var actionUrl = $('#contact_form').attr('action');
		    
		    $.ajax({
  		    	type: 'POST',
  		    	url: actionUrl,
  		    	data: $('#contact_form').serialize(),
  		    	success: function(msg){
  		    		$('#contact_form').hide();
  		    		$('#reponse_msg').html(msg);
  		    	}
		    });
		    
		    return false;
		}
	});
		    
		
	$('#contact_form').validate({
		rules: {
		    your_name: "required",
		    email: {
		    	required: true,
		    	email: true
		    },
		    message: "required"
		},
		messages: {
		    your_name: "Please enter your name",
		    email: "Please enter a valid email address",
		    agree: "Please enter some message"
		}
	});
	
	$(".accordion").accordion({ collapsible: true });
	$(".tab").tabs();

});
