// enclosed in jQuery to run after DOM load
$(function () {
	$('#nav-menu ul ul').hide();
	$('#nav-menu li a').click(
		function() {
			var checkElement = $(this).next();
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
				checkElement.slideUp('fast');
				$(this).removeClass().addClass('arrow-r');
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				//$('#nav-menu ul ul:visible').slideUp('normal');
				checkElement.slideDown(200);
				//$('#product-info').load($(this).attr('href')+" #product-info");
				$(this).removeClass().addClass('arrow-d');
				return false;
			}
		}
	);
	
  $('#nav-menu li a, #product-info a:not([target="_blank"]').click(function(e){
  		load($(this).attr('href'));
  		e.preventDefault();
  	})
  

  function load(link) {
		var productInfo = $('#product-info');
		var loader = $('#loader');
		var loadGif = $('.loading');
/*    $('#product-info').children().fadeOut().end().load(link+" #product-info", function(){
      	$('#product-info').children().fadeIn();
     	}); */
     	productInfo.fadeOut();
     	loadGif.fadeIn();
     	loader.load(link+" #product-info", function(){
     		loadGif.hide();
     		productInfo.fadeIn();	
     	});
  }
/*
  $.history.init(function(url) {
          load(url == "" ? "1" : url);
      });

  $('#nav-menu a').live('click', function(e) {
          var url = $(this).attr('href');
         // url = url.replace(/^.*#/, '');
          $.history.load(url);
          return false;
   });
*/	
	
	$('#top-nav > ul li').mouseover(function(){
		$(this).addClass('over');
	}).mouseout(function(){
		$(this).removeClass('over');
	});
	$('#gallery').children('.slide').each(function(){
		var newDiv = $("<div></div>");
		newDiv.css({
			'background-image': 'url('+$(this).attr('src')+')',
			'height': $(this).height()+"px",
			'width' : $(this).width()+"px"
		}).appendTo('#gallery');
		$(this).remove();
	});
	$("#gallery").bxSlider({
		mode: 'fade', 
		auto: true,
		controls: false,
		speed: 2000,
		pause: 5000,
		wrapperClass: 'fader-wrap'
	});

});
