$(document).ready(function(){ 
				   
    $("a.selected").click(function(){
		return false;
    });
						   
	$("div.maincat").click(loadcontent);

	$(window).load(firstload());
	
});

  	function firstload(){
		$("div.maincat:first").trigger("click");
  	}
	
	function loadcontent(){		   
		  maincat_id= this.id;
		  //maincat_id=$("#find").val();

		   $.post("getsubcategorieslist.php",{id:maincat_id,table:"categories"} ,function(data)
			{

				$("#wrapper").html(data);	

				$("div.maincat").click(loadcontent);
				$("div.subcat").click(function(){
					subcat_id=this.id;
					//alert(subcat_id)
				    $.post("getproductlist.php",{id:this.id,table:"products",maincat_id:maincat_id} ,function(data)
					{
						 $("#wrapper").html(data);

						 $("div.maincat").click(loadcontent);
						 
						$("div.products:not(:first)").bind("mouseenter mouseleave", function(e){
							$(this).toggleClass("highlight");
						});
						
							
					    $("div.products:first").addClass("highlight");
					 
					    $("div.products").click(productlist);
						 
				   });
				   
				});
		   });
	 }



function productlist(){

	
		$.post("getproductlistimages.php",{id:this.id,table:"products",maincat_id:maincat_id,subcat_id:subcat_id} ,function(data)
		{
			 $("#content").html(data);
			 
			 $("div.products").click(productlist);			 

			 $("div.maincat").click(loadcontent);
			 
			$("div.products").bind("mouseenter mouseleave", function(e){
				$(this).toggleClass("highlight");
			});
			
			$("div.selected").unbind("mouseenter mouseleave");
			
			$("div.selected").addClass("highlight");
		 
	   });
		
}


function submitForm(form, id){

		$('#loading').show(); // Show the Loading...
		$('#contactform').hide(); // Hide the drop down
		var str = $('#'+id).serialize();
		/*alert(str);	*/	
		$.post("processform.php",str,function(data)
		{
			/*alert(data);*/
			 $("#contactform").html(data);
			 $('#loading').hide(); // Show the Loading...
		     $('#contactform').show(); // Hide the drop down

	   });
		return false;
			
}


function initMenu() {
  $('#contactform form').hide();
  $('#contactform h2').click(
    function() {
      var checkElement = $(this).next();
      if((checkElement.is('form')) && (checkElement.is(':visible'))) {
        return false;
        }
      if((checkElement.is('form')) && (!checkElement.is(':visible'))) {
        $('#contactform form:visible').slideUp('normal');
        checkElement.slideDown('normal');
        return false;
        }
      }
    );
  }
$(document).ready(function() {initMenu();});

