jQuery.easing['jswing']=jQuery.easing['swing'];jQuery.extend(jQuery.easing,{def:'easeOutQuad',swing:function(x,t,b,c,d){return jQuery.easing[jQuery.easing.def](x,t,b,c,d)},easeInQuad:function(x,t,b,c,d){return c*(t/=d)*t+b},easeOutQuad:function(x,t,b,c,d){return-c*(t/=d)*(t-2)+b},easeInOutQuad:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t+b;return-c/2*((--t)*(t-2)-1)+b},easeInCubic:function(x,t,b,c,d){return c*(t/=d)*t*t+b},easeOutCubic:function(x,t,b,c,d){return c*((t=t/d-1)*t*t+1)+b},easeInOutCubic:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t+b;return c/2*((t-=2)*t*t+2)+b},easeInQuart:function(x,t,b,c,d){return c*(t/=d)*t*t*t+b},easeOutQuart:function(x,t,b,c,d){return-c*((t=t/d-1)*t*t*t-1)+b},easeInOutQuart:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t*t+b;return-c/2*((t-=2)*t*t*t-2)+b},easeInQuint:function(x,t,b,c,d){return c*(t/=d)*t*t*t*t+b},easeOutQuint:function(x,t,b,c,d){return c*((t=t/d-1)*t*t*t*t+1)+b},easeInOutQuint:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t*t*t+b;return c/2*((t-=2)*t*t*t*t+2)+b},easeInSine:function(x,t,b,c,d){return-c*Math.cos(t/d*(Math.PI/2))+c+b},easeOutSine:function(x,t,b,c,d){return c*Math.sin(t/d*(Math.PI/2))+b},easeInOutSine:function(x,t,b,c,d){return-c/2*(Math.cos(Math.PI*t/d)-1)+b},easeInExpo:function(x,t,b,c,d){return(t==0)?b:c*Math.pow(2,10*(t/d-1))+b},easeOutExpo:function(x,t,b,c,d){return(t==d)?b+c:c*(-Math.pow(2,-10*t/d)+1)+b},easeInOutExpo:function(x,t,b,c,d){if(t==0)return b;if(t==d)return b+c;if((t/=d/2)<1)return c/2*Math.pow(2,10*(t-1))+b;return c/2*(-Math.pow(2,-10*--t)+2)+b},easeInCirc:function(x,t,b,c,d){return-c*(Math.sqrt(1-(t/=d)*t)-1)+b},easeOutCirc:function(x,t,b,c,d){return c*Math.sqrt(1-(t=t/d-1)*t)+b},easeInOutCirc:function(x,t,b,c,d){if((t/=d/2)<1)return-c/2*(Math.sqrt(1-t*t)-1)+b;return c/2*(Math.sqrt(1-(t-=2)*t)+1)+b},easeInElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);return-(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b},easeOutElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);return a*Math.pow(2,-10*t)*Math.sin((t*d-s)*(2*Math.PI)/p)+c+b},easeInOutElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d/2)==2)return b+c;if(!p)p=d*(.3*1.5);if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);if(t<1)return-.5*(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b;return a*Math.pow(2,-10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p)*.5+c+b},easeInBack:function(x,t,b,c,d,s){if(s==undefined)s=1.70158;return c*(t/=d)*t*((s+1)*t-s)+b},easeOutBack:function(x,t,b,c,d,s){if(s==undefined)s=1.70158;return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b},easeInOutBack:function(x,t,b,c,d,s){if(s==undefined)s=1.70158;if((t/=d/2)<1)return c/2*(t*t*(((s*=(1.525))+1)*t-s))+b;return c/2*((t-=2)*t*(((s*=(1.525))+1)*t+s)+2)+b},easeInBounce:function(x,t,b,c,d){return c-jQuery.easing.easeOutBounce(x,d-t,0,c,d)+b},easeOutBounce:function(x,t,b,c,d){if((t/=d)<(1/2.75)){return c*(7.5625*t*t)+b}else if(t<(2/2.75)){return c*(7.5625*(t-=(1.5/2.75))*t+.75)+b}else if(t<(2.5/2.75)){return c*(7.5625*(t-=(2.25/2.75))*t+.9375)+b}else{return c*(7.5625*(t-=(2.625/2.75))*t+.984375)+b}},easeInOutBounce:function(x,t,b,c,d){if(t<d/2)return jQuery.easing.easeInBounce(x,t*2,0,c,d)*.5+b;return jQuery.easing.easeOutBounce(x,t*2-d,0,c,d)*.5+c*.5+b}});

//
//$(document).ready(function() {
//  
//  if(getPath() == 'redenim') {
//    open();
//  }
//
//  $('#slide-link').click(function(){
//    if (!$(this).hasClass('active')) {
//      open(true);
//    } else {
//      close();
//    }
//  });
//
//  $(document).keyup(function(e) {
//    if(e.keyCode == 27) {close();}
//  });
//
//});
//
//function open(immediately) {
//  var slideLink = $('#slide-link');
//  var delay = (immediately) ? 0 : 1300;
//  slideLink.delay(delay).animate({right:-6}, 600);
//  slideLink.addClass('active');
//  slideLink.filter('.open').mouseover(function() {
//    $(this).animate({right:-26});
//  });
//  slideLink.filter('.open').mouseout(function() {
//    $(this).animate({right:-6});
//  });
//  changeUrl('redenim');
//}
//  
//function close() {
//  var slideLink = $('#slide-link');
//  slideLink.animate({right:-675}, 600, 'swing', function() {
//    slideLink.animate({right:-695}, 600, 'swing');
//  });
//  slideLink.removeClass('active');
//  changeUrl('');
//}
//
//function changeUrl(url) {
//  if(window.history && history.pushState) {
//    if(url == '') {
//      var url = location.protocol + '//' + location.host;
//    } else {
//      if(url.substring(0,4) != 'http') {
//        var url = location.protocol + '//' + location.host + '/' + url;
//      }
//    }
//    history.pushState(null, null, url);
//  } else {
//    if(url != '') {
//      location.hash = url;
//    } else {
//      location.hash = '';
//    }
//  }
//}
//
//function getPath() {
//  if(window.history && history.pushState) {
//    var url = window.location.pathname.split("/");
//    if(url.length > 1) {
//      var path = url[url.length-1];
//    }
//  } else {
//    var path = location.hash.replace('#', '');
//  }
//  
//  return path;
//}

$(document).ready(function() {
    var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
    if (mobile) { document.location = "http://crossjeans.com/mobile/";}

  $('#side-top').click(function(){
    $.scrollTo('#top', 1700, {easing:'easeOutQuart', offset:0});
  })
  $('#collection #side-01').click(function(){
    $.scrollTo('#content-01', 1700, {easing:'easeOutQuart', offset:-123});
  })
  $('#collection #side-02').click(function(){
    $.scrollTo('#content-02', 1700, {easing:'easeOutQuart', offset:-123});
  })
  $('#fitguide #side-01').click(function(){
    $.scrollTo('#content-01', 1700, {easing:'easeOutQuart', offset:-77});
  })
  $('#fitguide #side-02').click(function(){
    $.scrollTo('#content-02', 1700, {easing:'easeOutQuart', offset:-123});
  })
  $('#tradition #side-01').click(function(){
    $.scrollTo('#content-01', 1700, {easing:'easeOutQuart', offset:-223});
  })
  $('#tradition #side-02').click(function(){
    $.scrollTo('#content-02', 1700, {easing:'easeOutQuart', offset:-293});
  })
  $('#tradition #side-03').click(function(){
    $.scrollTo('#content-03', 1700, {easing:'easeOutQuart', offset:-187});
  })
  $('#tradition #side-04').click(function(){
    $.scrollTo('#content-04', 1700, {easing:'easeOutQuart', offset:-183});
  })  
  $('#tradition #side-05').click(function(){
    $.scrollTo('#content-05', 1700, {easing:'easeOutQuart', offset:-123});
  })    

  
// set Active Sidelink to active or inactive
  $('.side-link').click(function(){
    $(this).addClass('active');
    $(this).siblings('li').removeClass('active');
  })
  $('.side-link').mouseover(function(){
    $(this).children().stop().animate({opacity:1});
  });
  $('.side-link').mouseout(function(){
    $(this).children().stop().animate({opacity:0});
  })
  
   /* Detect Scrollposition */
 var ScrollTop = window.pageYOffset;
 $(window).scroll(function(){
   ScrollTop = window.pageYOffset;
   console.log(ScrollTop);
   if ($('#fitguide').length){
     if(ScrollTop <= 342){
       $('#side-top').addClass('active');
       $('#side-01, #side-02').removeClass('active');
     }
     if (ScrollTop >= 1100){
       $('#side-01').addClass('active')
       $('#side-top, #side-02').removeClass('active');
     }
     if (ScrollTop >= 1800){
       console.log('groesser als 2300');
       $('#side-02').addClass('active')
       $('#side-top, #side-01').removeClass('active');
     }
   }
   if ($('#tradition').length){
     if(ScrollTop <= 550){
       $('#side-top').addClass('active');
       $('#side-01, #side-02, #side-03, #side-04, #side-05').removeClass('active');
     }
     if(ScrollTop >= 550){
       $('#side-01').addClass('active');
       $('#side-top, #side-02, #side-03, #side-04, #side-05').removeClass('active');
     }
     if(ScrollTop >= 1700){
       $('#side-02').addClass('active');
       $('#side-top, #side-01, #side-03, #side-04, #side-05').removeClass('active');
     }
     if(ScrollTop >= 3000){
       $('#side-03').addClass('active');
       $('#side-top, #side-01, #side-02, #side-04, #side-05').removeClass('active');
     }
     if(ScrollTop >= 4000){
       $('#side-04').addClass('active');
       $('#side-top, #side-01, #side-02, #side-03, #side-05').removeClass('active');
     }
     if(ScrollTop >= 4700){
       $('#side-05').addClass('active');
       $('#side-top, #side-01, #side-02, #side-03, #side-04').removeClass('active');
     }       
   }
   if ($('#collection').length){
     if(ScrollTop <= 600){
       $('#side-top').addClass('active');
       $('#side-01, #side-02').removeClass('active');
     } 
     if(ScrollTop >= 600){
       $('#side-01').addClass('active');
       $('#side-top, #side-02').removeClass('active');
     }    
     if(ScrollTop >= 1700){
       $('#side-02').addClass('active');
       $('#side-top, #side-01').removeClass('active');
     }      
   }
 }); 
  
  
  
  
// Stop Scrolling if user uses scroller
  if(window.addEventListener) document.addEventListener('DOMMouseScroll', stopScroll, false);
  document.onmousewheel = stopScroll;

  function stopScroll() {
    $(window)._scrollable().stop(true, false);  // Stops and dequeue's animations
  }


$('#collection #content-01, #collection #content-02').prepend('<div class="sort-controls"><div class="sort-all active">All</div><div class="sort-men">Men</div><div class="sort-women">Women</div></div>');
$('.sort-controls div').click(function(){
  $(this).addClass('active');
  $(this).siblings('div').removeClass('active');
})
$('.jcarousel-skin-tango-2, .jcarousel-skin-tango-3, .jcarousel-skin-tango-5, .jcarousel-skin-tango-6').hide();
// COLLECTION SUMMER
// Show Men
$('#content-01 .sort-men').click(function(){
  $('.jcarousel-skin-tango-1, .jcarousel-skin-tango-3').fadeOut('slow', function(){
    $('.jcarousel-skin-tango-2').delay(1000).fadeIn('slow');
  }); 
});

// Show women
$('#content-01 .sort-women').click(function(){
  $('.jcarousel-skin-tango-1, .jcarousel-skin-tango-2').fadeOut('slow', function(){
    $('.jcarousel-skin-tango-3').delay(1000).fadeIn('slow');
  });
});

// Show All
$('#content-01  .sort-all').click(function(){
  $('.jcarousel-skin-tango-2, .jcarousel-skin-tango-3').fadeOut('slow', function(){
    $('.jcarousel-skin-tango-1').delay(1000).fadeIn('slow');
  });
});

// COLLECTION WINTER
// Show Men
$('#content-02 .sort-men').click(function(){
  $('.jcarousel-skin-tango-4, .jcarousel-skin-tango-6').fadeOut('slow', function(){
    $('.jcarousel-skin-tango-5').delay(1000).fadeIn('slow');
  }); 
});

// Show women
$('#content-02 .sort-women').click(function(){
  $('.jcarousel-skin-tango-4, .jcarousel-skin-tango-5').fadeOut('slow', function(){
    $('.jcarousel-skin-tango-6').delay(1000).fadeIn('slow');
  });
});

// Show All
$('#content-02  .sort-all').click(function(){
  $('.jcarousel-skin-tango-5, .jcarousel-skin-tango-6').fadeOut('slow', function(){
    $('.jcarousel-skin-tango-4').delay(1000).fadeIn('slow');
  });
});

  // Adjust Side-menu
  var halfsidemenuheight = $('#side-menu').height() / 2;
  $('#side-menu').css({marginTop:-halfsidemenuheight});
  
  $("a.fancybox, a#single-image").fancybox({
    'hideOnContentClick': false,
    'transitionIn'	:	'elastic',
    'transitionOut'	:	'elastic',
    'speedIn'		:600, 
    'speedOut'		:200, 
    'overlayShow'	:	false,
    'padding':0,
    'margin':0,
    'autoScale' : true
  });
  $('#fancybox-content').click(function(){
    console.log();
    $.fancybox.next();
  });

$('a[href$="contact.php"]').fancybox({
  'type' : 'iframe',
  'width':740,
  'height':500,
  'transitionIn':'fade',
  'transitionOut':'fade'
});

$('a[href$="imprint.html"]').fancybox({
  'type' : 'iframe',
  'width':400,
  'height':422,
  'transitionIn':'fade',
  'transitionOut':'fade'
});

$('#logo').delay(600).animate({opacity:1}, 2000);

   $('.fancy-thumb-01').addClass('active');
   $('.fancy-thumb-01').click(function(){
     $(this).parent('.fancybox-thumb-image').prev().children('.fancy-detail-02').fadeOut(function(){
       $(this).prev().fadeIn();
     });
     $(this).addClass('active');
     $(this).siblings().removeClass('active');
   });
   $('.fancy-thumb-02').click(function(){
     $(this).parent('.fancybox-thumb-image').prev().children('.fancy-detail-01').fadeOut(function(){
       $(this).next().fadeIn();
     });
     $(this).addClass('active');
     $(this).siblings().removeClass('active');
   });
});

