var GB_ANIMATION = true;

// prepare the form when the DOM is ready 
$(function(){
   $('#tablist > ul').tabs({
	   fx: { opacity: 'toggle' }
	});

	$('a.lightbox').lightBox({
	   imageBtnClose: '/img/lightbox/lightbox-btn-close.gif',
	   imageLoading: '/img/lightbox/lightbox-ico-loading.gif',
	   imageBtnPrev: '/img/lightbox/lightbox-btn-prev.gif',
	   imageBtnNext: '/img/lightbox/lightbox-btn-next.gif',
	   imageBlank: '/img/lightbox/lightbox-blank.gif'
	}); // Select all links with lightbox class

   $("select#cat").change(function(){
      var optionsCat = { 
         target:        '#output',
         beforeSubmit:  categoryChange,  // pre-submit callback 
         success:       categoryJson, // post-submit callback 
         dataType:      'json',           // 'xml', 'script', or 'json' (expected server response type)
         url:           "/categories/getSubCategories/"+$(this).val(),
         type:          "get"
         //timeout:   3000
      }; 
      
      $(this).ajaxSubmit(optionsCat);
   })
   
   $("#showPhotos").click(
      function() {
         $('#tablist > ul').tabs('select', 1);
         var pos = $("#showPhotos").offset();
		   $("html").animate({ scrollTop: '-' + pos.top + "px" }, { duration: 0 });
         return false;
      }
   )

   $("#showForm").click(
      function() {
         $('#tablist > ul').tabs('select', 0);
         var pos = $("#showForm").offset();
		   $("html").animate({ scrollTop: '-' + pos.top + "px" }, { duration: 0 });
         return false;
      }
   )
   $("#secondSubmit").click(
      function() {
         $('#tablist > ul').tabs('select', 0);
         var pos = $("#showForm").offset();
		   $("html").animate({ scrollTop: '-' + pos.top + "px" }, { duration: 0 });
		   $("#infoTab form").submit();
		   return false;
		}
   )

   $("#promoteGuide").click(
      function() {
         GB_show('Christmas Gift Guidelines','/popup/xmas_guidelines',350,600);
         return false;
      }
   )

   /*$(".video_popup").click(
      function() {
         GB_show('Video Display',this,369,440);
         return false;
      }
   )*/

   $('.itemThumbnails img').hover(
      function() { 
         $med_image = '/img/photos/' + $(this).attr('hover') + '/medium/' + $(this).attr('hover') + $(this).attr('ext');
         $lrg_image = '/img/photos/' + $(this).attr('hover') + '/big/' + $(this).attr('hover') + $(this).attr('ext');
         
         if ($('#displayImage').attr('src') != $med_image)
         {
            $('#displayImage').attr('src', $med_image);
            $('#displayImageLB').attr('href', $lrg_image);
            $("#displayImage").thumbs(300,300);
         }
      },
      function() { return true; });

   $("#promoteGuide").click(
      function() {
         GB_show('Christmas Gift Guidelines','/popup/xmas_guidelines',350,600);
         return false;
      }
   )

   $("#displayImage").load(function() {
      if ($("#displayImage").height() > 300)
      {
         $("#displayImage").thumbs(300,300,0,0); 
      }
   })
       
   function categoryChange(formData, jqForm, options) { 
      $("#catLoading").show();
      return true;
   }
   
   function categoryJson(jsonData, status)
   {
      var options = '';
      $.each(jsonData, function (k, l) {
         options += '<option value="' + k + '">' + l + '</option>';
      })
      $("select#sub").html(options);

      $("#catLoading").hide();
   }
   

});


