$(document).ready(function () {
  $('#bigpush .pushGroup').cycle({
    fx: 'scrollHorz',
    activePagerClass: 'active',
    delay: 100,
    timeout: 8000,
    pager: '#bigpush .pushPager',
    next: '#bigpush .pushNext',
    prev: '#bigpush .pushPrev',
    pagerAnchorBuilder: function (i) {
      return '<a href="#"></a>';  // for first slideshow, return a new anchro
    }
  });

  $('.popPrdSlide').cycle({
    fx: 'scrollHorz',
    activePagerClass: 'active',
    delay: 100,
    timeout: 0,
    pager: '.popPrdPager',
    pagerAnchorBuilder: function (i) {
      var i = i + 1
      return '<li><a href="#"></a></li>';  // for first slideshow, return a new anchro
    }
  });

  $('.pushNext, .pushPrev').find('span').hide();
  $('.pushNext, .pushPrev').hover(function () {
    $(this).find('span').fadeIn();
  }, function () {
    $(this).find('span').fadeOut();
  });

  $('.showTopBasket').click(function () {
    $('#topSearch').hide();
    $('#topBasketWrapper').slideToggle();
  });
  $('.showTopSearch').click(function () {
    $('#topSearch').slideToggle();
    $('#topBasketWrapper').hide();
  });

  $('body').click(function (event) { $('.searchSubmit').fadeOut('fast'); })
  $('.searchSubmit, .searchText').click(function (event) { event.stopPropagation(); })
  $('.searchText').keydown(function (event) { $('.searchSubmit').fadeIn('fast'); });

  // SHOP SLIDESHOW W. ImgMap
  /*
  $("#showcase").awShowcase(
  {
  content_width:      700,
  content_height:      320,
  fit_to_parent:      false,
  auto:          true,
  interval:        3000,
  continuous:        true,
  loading:        true,
  tooltip_width:      250,
  tooltip_icon_width:    33,
  tooltip_icon_height:  35,
  tooltip_offsetx:    18,
  tooltip_offsety:    0,
  arrows:          true,
  buttons:        true,
  btn_numbers:      false,
  keybord_keys:      true,
  mousetrace:        false,
  pauseonover:      true,
  stoponclick:      true,
  transition:        'hslide',
  transition_speed:    500,
  transition_delay:    0,
  show_caption:      'onhover',
  thumbnails:        false,
  thumbnails_position:  'outside-last',
  thumbnails_direction:  'horizontal',
  thumbnails_slidex:    0,
  dynamic_height:      false,
  speed_change:      false,
  viewline:        false

  });*/

  $('.showcase-arrow span').hide();
  $('.showcase-arrow').hover(function () {
    $(this).find('span').fadeToggle()
  });

  //Tabs
  $(".prdTabContent").hide();
  $(".prdTabContents").find('.prdTabContent:first').show();
  $(".prdTabs li:first-child a").each(function () { $(this).addClass("active").show(); });
  $(".prdTabs li a").click(function () {
    $(this).parents('.prdTabs').find('a').removeClass("active");
    $(this).addClass("active");
    $(".prdTabContent").hide();
    var activeTab = $(this).attr("href");
    $(activeTab).fadeIn();
    return false;
  });

  //shoppingcart jcarousel
  $('#shopBasket.skin-pf').jcarousel({
    setupCallback: function () {
      $('<span class="inner"></span>').appendTo('.jcarousel-next, .jcarousel-prev');
    }
  });

  //rounded corners with pie.js
  $(function () {
    if (window.PIE) {
      $('.innerframe, .newsDate, #topnav a, .prdImage, .prdTotalPrice').each(function () {
        $(this).css('position', 'relative');
        PIE.attach(this);
      });
    }
  });

  // FORM WIZARD min:c.validator.format("Please enter a value greater than or equal to {0}.")
  //if($("#petForm").length != 0){
  $("#petForm").formwizard({
    formPluginEnabled: true,
    validationEnabled: true,
    focusFirstInput: true,
    textBack: 'Backa',
    textNext: 'Nästa',
    textSubmit: 'Skicka formulär',
    validationOptions: {
      rules: {
        User: { required: true, minlength: 6, maxlength: 12 },
        Password: { required: true, minlength: 6, maxlength: 12 },
        Name: "required",
        Telephone: "required",
        Cellphone: "required",
        CompanyName: "required",
        Address: "required",
        ZipCode: "required",
        City: "required",
        BillingAddress: "required",
        BillingZipCode: "required",
        BillingCity: "required",
        OrganizationNumber: "required",
        Email: {
          required: true,
          email: true
        }
      },
      messages: {
        User: "Användarnamn är obligatoriskt (6-12 tecken)",
        Password: "Lösenord är obligatoriskt (6-12 tecken)",
        Name: "Namn är obligatoriskt",
        Telephone: "Telefonnummer är obligatoriskt",
        Cellphone: "Mobilnummer är obligatoriskt",
        CompanyName: "Företagsnamn är obligatoriskt",
        Address: "Adress är obligatoriskt",
        ZipCode: "Postnummer är obligatoriskt",
        City: "Postort är obligatoriskt",
        BillingAddress: "Adress är obligatoriskt",
        BillingZipCode: "Postnummer är obligatoriskt",
        BillingCity: "Postort är obligatoriskt",
        OrganizationNumber: "Organisationsnummer är obligatoriskt",
        Email: "Felaktig epost-adress"
      }
    },
    formOptions: {
      success: function () {
        $('#article').hide();
        $('#message').show();
      }
    }
  });
  $("#petForm").bind("after_remote_ajax", function (event, data) {
    alert("Tack för din ansökan!");
  });
  //}
  $('#next').click(function () {
    if (!$('#petForm').valid())
    { $('#petForm').validate().focusInvalid(); }
  })
  // IE Placeholder fix
  if ($.browser.msie) {
    if ($('[placeholder]').val() == '')
      $('[placeholder]').addClass('placeholder');

    $('[placeholder]').focus(function () {
      var input = $(this);
      if (input.val() == input.attr('placeholder')) {
        if (this.originalType) {
          this.type = this.originalType;
          delete this.originalType;
        }
        input.val('');
        input.removeClass('placeholder');
      }
    }).blur(function () {
      var input = $(this);
      if (input.val() == '') {
        if (this.type == 'password') {
          this.originalType = this.type;
          this.type = 'text';
        }
        input.addClass('placeholder');
        input.val(input.attr('placeholder'));
      }
    }).blur();

    // pre-submit clear placeholders
    $('[placeholder]').parents('form').submit(function () {
      $(this).find('[placeholder]').each(function () {
        var input = $(this);
        if (input.val() == input.attr('placeholder')) {
          input.val('');
        }
      })
    });
  }
});   //end of ready.scripts

function getUrlVars() {
  var vars = [], hash;
  var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  for (var i = 0; i < hashes.length; i++) {
    hash = hashes[i].split('=');
    vars.push(hash[0]);
    vars[hash[0]] = hash[1];
  }
  return vars;
}
