﻿// jQuery til A-Sport.dk //
$(document).ready(function(){
  
  //Galleri produkt visning
  $('#lImages').cycle({ 
    fx:     'fade', 
    speed:  'fast', 
    timeout: 0, 
    pagerEvent: 'mouseover',
    pager:  '#nImages', 
    slideExpr: 'div',
    pagerAnchorBuilder: function(idx, slide) { 
      // return selector string for existing anchor 
      return '#nImages li:eq(' + idx + ') a'; 
    } 
  });
  
  //MiniCart
  /*
  $('.customer dd').hide();
    $('.customer dt').click(function() {
      $(this).next(".customer dd").slideToggle(100);
      $(this).toggleClass("active");
      $(this).siblings(".customer dt").removeClass("active");
   });
  
  $('.customer').mouseleave(function() {    
    $('.customer dd').slideUp(10);
    $(".customer dt").removeClass("active");    
  });
  */
  $(".customer dd").hide();
	$(".customer dt").mouseenter(function(){
		$(this).next("dd").slideToggle(100)
		.siblings("dd:visible").slideUp(10);
		$(this).toggleClass("active");
		$(this).siblings("dt").removeClass("active");
	});
	$('.customer').mouseleave(function() {		
		$('.customer dd').slideUp(100);
		$(".customer dt").removeClass("active");		
	});
	$('.customer dt a').hover(function() {
		$('.customer dd').slideUp(100);
		$(".customer dt").removeClass("active");		
	});
	
	
	$('#mBasket').hover(
		function () {
			//show
			$(this).toggleClass("active");
			$('dd', this).slideDown(100);
		}, 
		function () {
			//hide
			$('dd', this).slideUp(10);
			$("#mBasket a").click(function () { 
      			$('dd',this).hide(); 
	  			$(this).removeClass("active");	
    		});	
			$(this).removeClass("active");
		}
	);
	
	
  /*
  $('#login dd').show();
      $('#login dt').click(function() {
      $(this).next("#login dd").slideToggle("fast");
      $(this).toggleClass("active");
      $(this).siblings("#login dt").removeClass("active");
   });
*/
  $('.createUser table').hide();
  $('.createUser input#userAcc').bind('click', function(){
    $('.createUser table').slideToggle("500");
    });
  
  
  //TopMenu super simple dropdown
  
  $('.topmenu li').hover(
    function () {
      //show its submenu
      $(this).toggleClass("active");
      $('ul', this).slideDown(100);
    }, 
    function () {
      //hide its submenu
      $('ul', this).slideUp(10);
      $(".topmenu li").click(function () { 
            $('ul',this).hide(); 
          $(this).removeClass("active");  
        });  
      $(this).removeClass("active");    
    }
  );
  
  $('.navi li').hover(
    function () {
      //show its submenu
      $(this).toggleClass("active");
      $('ul', this).slideDown(100);
    }, 
    function () {
      //hide its submenu
      $('ul', this).slideUp(10);
      $(".navi li").click(function () { 
            $('ul',this).hide(); 
          $(this).removeClass("active");  
        });  
      $(this).removeClass("active");    
    }
  );
  
  //slideshow on the homepage
  $('#slideshow').cycle({
    fx      : 'fade',
        random    : 1,
    speed    : 500,
    timeout    : 10000,
        delay    : -2000,
        pager    : '#pager',
    slideExpr  : 'div.slides'
  });
  
  //Produktvisning vha FancyBox
  $(".quickview").fancybox({
    'autoDimensions'  : true,
    'width'        : 798,
    'height'      : 480,
        'autoScale'       : true,
        'transitionIn'    : 'none',
    'transitionOut'    : 'none',
    'scrolling'      : 'true',
    'type'        : 'iframe'
  });
  
  //Tekstvisning vha FancyBox
  $(".fancyPop").fancybox({
    'width'        : '90%',
    'height'      : '75%',
        'autoScale'       : false,
        'transitionIn'    : 'none',
    'transitionOut'    : 'none',
    'scrolling'      : 'yes',
    'type'        : 'iframe'
  });
  
  //Youtube Video vha FancyBox
  $("#fcMov").click(function() {
  $.fancybox({
      'padding'    : 0,
      'autoScale'    : false,
      'transitionIn'  : 'none',
      'transitionOut'  : 'none',
      'title'      : this.title,
      'width'      : 680,
      'height'    : 495,
      'href'      : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
      'type'      : 'swf',
      'swf'      : {
            'wmode'    : 'transparent',
        'allowfullscreen'  : 'true'
      }
    });

  return false;
  });
  
  // FancyBox Galleri
  $("a.group").fancybox({
    'transitionIn'  :  'elastic',
    'transitionOut'  :  'elastic',
    'speedIn'    :  600, 
    'speedOut'    :  200
  });
  
  // Vis labels inde i input felt
  $(".search input").labelify({ text: "label", labelledClass: "labelinside" });
  $(".phoneLookUp input").labelify({ text: "label", labelledClass: "labelinside" });
  
  // Kalender til dato felter
  $( "#FromDate" ).datepicker({ minDate: "-2y", maxDate: "-1d", dateFormat: "ddmmyy", changeMonth: true, changeYear: true, appendText: ' <span class="instruks">(ddmmyyyy)</span>' });
  $( "#ToDate" ).datepicker({ minDate: "-364d", maxDate: "0d", dateFormat: "ddmmyy", changeMonth: true, changeYear: true, appendText: ' <span class="instruks">(ddmmyyyy)</span>' });
  
  
  $('.htmlDesc p').each(function(){ 
    if ($(this).html()=='&nbsp;') $(this).remove(); 
  }) 
  $('.htmlDesc p:empty').remove(); 
  
});
