/* Author: Create Interactive */

/* Home Cycle */

$('#home-winter-collection').cycle({
	pager:'.slide-pager',
	timeout:3.5*1000
});

/* Image Zoom */

$(function(){  
    var options = {  
		zoomType: 'innerzoom',
		alwaysOn : false,
		zoomWidth  : 267,  
        zoomHeight	: 436,
		position : 'right',
		xOffset: 10,
		yOffset: 0,
		showEffect : 'fadein',
		hideEffect: 'fadeout',
		title: false
    };  
    $('.img_zoom').jqzoom(options);  
});

/* Our Story 

//$('.our-story-item').css({'display':'none'});
$('#our-story-1').show('fade', {easing: 'easeOutExpo'}, 2 * 1000);
$('#our-story-2').delay(.2*1000).show('fade', {easing: 'easeOutExpo'}, 2 * 1000);
$('#our-story-3').delay(.4*1000).show('fade', {easing: 'easeOutExpo'}, 2 * 1000);
$('#our-story-4').delay(.6*1000).show('fade', {easing: 'easeOutExpo'}, 2 * 1000);
$('#our-story-5').delay(.8*1000).show('fade', {easing: 'easeOutExpo'}, 2 * 1000);
$('#our-story-6').delay(1*1000).show('fade', {easing: 'easeOutExpo'}, 2 * 1000);
$('#our-story-7').delay(1.2*1000).show('fade', {easing: 'easeOutExpo'}, 2 * 1000);
$('#our-story-8').delay(1.4*1000).show('fade', {easing: 'easeOutExpo'}, 2 * 1000);
$('#our-story-9').delay(1.6*1000).show('fade', {easing: 'easeOutExpo'}, 2 * 1000);
*/
$('.testimonial-item').css({opacity:.8});

// #testimonial-container grayscale -> color hover
$("#testimonials-container ul li").hover(
	function() {
		var testimonialOver = $(this).find('img').attr('src');
		$(this).find('a.thumb').css({'background' : 'transparent url(' + testimonialOver + ') no-repeat center bottom'});
		
		var dir = $(this).attr('class');
		$(this).find('.testimonial-item').show('slide', {easing: 'easeOutExpo',direction:dir}, 500);
		console.log(dir);
		
		$(this).find('span').stop().fadeTo('normal', 0 , function() {
			$(this).hide();
		});
	}, function() {
		$(this).find('span').stop().fadeTo('normal', 1).show();
		var dir = $(this).attr('class');
		$(this).find('.testimonial-item').hide('slide', {easing: 'easeOutExpo',direction:dir}, 250);
	}
);

/* Partners */

$('#partners-grid ul li a').click(function(){
	var img = $(this).find('img').attr('src');
	
	$('#partners-grid ul li a').removeClass('active');
	$(this).addClass('active');
	
	$('.partner-tooltip').show('slide',{direction:'left'},400);
	$('.partner-tooltip').find('img.partner-logo').attr('src',img);
});

/* Navigation Dropdown */
/*
$('nav li').hover(function(){
	$(this).addClass('active');
},function(){
	$(this).removeClass('active');
});
*/

$('utility_nav li').hover(function(){
	$(this).addClass('active');
},function(){
	$(this).removeClass('active');
});


		
/* Navigation Dropdown- New (Subnav does not disappar on mouseout */

	function primaryNavRoll(oppositeNav,element) {
		var element2 = document.getElementById(oppositeNav);
		$(element2).removeClass('active');
		$(element).addClass('active');
	}
	
	function primaryNavRollOut(gender) {
	  var menElement = document.getElementById('men');
	  var womenElement = document.getElementById('women'); 

	  $(menElement).removeClass('active');
	  $(womenElement).removeClass('active');

	  if (gender == 'men') {
		$(menElement).addClass('active')
	  } else if (gender == 'women') {
		$(womenElement).addClass('active');
	  }
	}


/* Navigation Dropdown */
/*
$('nav li').hover(function(){
	$(this).addClass('active');
},function(){
	$(this).removeClass('active');
});
*/
/* Sticky/Waypoint Footer Combo */
$('#container').waypoint(function(event, direction) {
	$('#container').toggleClass('sticky', direction == "down");
}, {
	offset: function() {
		return $.waypoints('viewportHeight') - ($(this).height() - ($('#content-after').height() - ($('footer').height() - 18)));
	}
});

/* Team Fancybox */

$(document).ready(function() {
	$(".video-window").click(function() {
        $.fancybox({
            'padding'        : 0,
            'autoScale'        : false,
            'transitionIn'    : 'none',
            'transitionOut'    : 'none',
            'title'            : this.title,
            'width'            : 640,
            'height'        : 385,
            'href'            : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'            : 'swf',
            'swf'            : {
            'wmode'                : 'transparent',
            'allowfullscreen'    : 'true'
            }
        });
        return false;
    });
	/* This is basic - uses default settings */
	$("a#single_image").fancybox();
	
	/* Using custom settings */
	$("a#inline").fancybox({
		'hideOnContentClick': true
	});
	/* Apply fancybox to multiple items */
	$("a.team_member").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayColor'	:	'#FFF',
		'padding' : 0,
		'titlePosition' : 'over'
	});
	/* optIn popup click handler */
    $("#optInPopupOpenLink").click(function() {
        $.fancybox({
            'padding'        	: 0,
            'autoScale'        	: false,
            'transitionIn'    	: 'none',
            'transitionOut'    	: 'none',
            'title'            	: this.title,
            'width'            	: 400,
            'height'        	: 248,
            'href'            	: "/ASIParty/joinEmailListPopup",
            'type'            	: 'iframe',
            'scrolling'         : 'no'
        });
        return false;
    });
}); //end document ready function

/* #women-men-jump-page hover */

$('ul#women-men-jump-page li').hover(function(){
	$('ul#women-men-jump-page li').removeClass('active');
	$(this).addClass('active');
},function(){
	$(this).removeClass('active');
});


// Find Your Fit
$('div#find-your-fit-container a.point').click(function(){
	$('div#find-your-fit-container a').removeClass('active');
	$(this).addClass('active');	
	var showCallout = $(this).attr('rel');

	$('.callout').hide('fade', {easing: 'easeOutExpo'}, 250);	
	$(showCallout).delay(300).show('fade', {easing: 'easeOutExpo'}, 500);

	
// },function(){
// 	$(this).removeClass('active');
// 	
// 	var hideCallout = $(this).attr('href');
// 	$(hideCallout).hide('fade', {easing: 'easeOutExpo'}, 500);
});

/*  Quick View */
	$(function(){
		// add quick view on-the-fly
		 for (i=1;i<=18;i++) {
			$('div.contain-' + i).append('<div class="quick-view"><a href="#quick-view-container-' + i + '" border="0"><span>Quick View</span></a></div>');
		} 
		
		$('.quick-view a').attr('rel','jean-item-group').fancybox({
			'scrolling':'no',
			'titleShow':true,
			'type':'inline',
			'showCloseButton':true,
			'showNavArrows':false
		});
		$('a.prev-trigger').click(function(){
			$.fancybox.prev();
		});
		$('a.next-trigger').click(function(){
			$.fancybox.next();
		});
		$('a.close-trigger').click(function(){
			$.fancybox.close();
		});
	});

// use document.ready sparingly

/*
$(function(){
	// add quick view on-the-fly
	$('div#jeans-container div.jean-item').append('<div class="quick-view"><span>Quick View</span></div>');
	// 
	$('.jean-item a').fancybox({
		'scrolling':'no',
		'titleShow':false,
		'type':'inline'
	});
});
*/

/* Scroller Body Types */
$(window).load(function() {
    $("div#makeMeScrollable").smoothDivScroll({
        autoScroll: "onstart" , 
        autoScrollDirection: "backandforth", 
        autoScrollStep: 0, 
        autoScrollInterval: 15,
        visibleHotSpots: "always"
        });
})
/* header shipping info */
function closeShippingInfo(){
	$("#shippingInfo").hide();
}
function openShippingInfo(){
	$("#shippingInfo").show();
}
function echeck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	var rtnValue = true;
	if (str.indexOf(at)==-1){
		rtnValue = false;
	}
	else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		rtnValue = false;
	}
	else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		rtnValue = false;
	}
	else if (str.indexOf(at,(lat+1))!=-1){
		rtnValue = false;
	}
	else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		rtnValue = false;
	}
	else if (str.indexOf(dot,(lat+2))==-1){
		rtnValue = false;
	}	
	else if (str.indexOf(" ")!=-1){
		rtnValue = false;
	}
	
	return rtnValue;					
}
function joinEmailListPopupSubmit(){
	var answer = document.frmOptInPopup.email.value.trim();
	if (answer == ""){
		alert("Please enter your email address.");
		document.frmOptInPopup.email.focus();
	}
	else if (!echeck(answer)){
		alert( "You entered an invalid email address");
		document.frmOptInPopup.email.focus();	
	}
	else {
		document.frmOptInPopup.submit();
	}
}

function txtEmailClickEventHandler(obj){
	if (obj.value == "ENTER YOUR EMAIL ADDRESS"){
		obj.value = "";
	}
}
function openOptInPopup(){
	 $("#optInPopupOpenLink").trigger('click');	
}
