// JavaScript Document
$(document).ready(function() {
	

	slideVideoHandler();
	
	$('.addToCart').bind('click',function(e){
		e.preventDefault();
		if($('#option_id').val() == ''){
			htmlStringErr1 = '<div id="failureSingle" class="fade-f8acac">Please choose your size/color.</div>';
			$('#status').fadeOut().empty().append(htmlStringErr1).stop().fadeIn();
			return false;
		}
		var submitUrl = '/shop/actions.cfm?action=cart&' + $('#addToCartForm').serialize();
		$.ajax({
			url : submitUrl,
			type : 'GET',
			success : itemAdded,
			error : addFail,
			dataType : 'json'
			});
	});
	
	function itemAdded(data){
		if(data.addedToCart){
			htmlString = '<div id="success" class="fade-99cc99"><strong>'+data.message+'</strong></div>';
			$('#status').fadeOut().empty().append(htmlString).stop().fadeIn();
			$('.accountLinks').find('a[href*=/cart/cart.cfm]').text('View Cart ('+data.items+')');
			$('#status').delay(1200).fadeOut(500);
		}
	}
	
	function addFail(){
		alert("An Unexpected Error has occured.\nCould Not Add this item to Your Cart")
	}


	// add outfit
	$('.addToCartOutfit').bind('click',function(e){
		e.preventDefault();
		if($('#optionId_1').val() == ''){
			htmlStringErr1 = '<div id="failureSingle" class="fade-f8acac">Please choose your size/color for item 1.</div>';
			$('#status').fadeOut().empty().append(htmlStringErr1).stop().fadeIn();
			return false;
		}
		if($('#optionId_2').val() == ''){
			htmlStringErr1 = '<div id="failureSingle" class="fade-f8acac">Please choose your size/color for item 2.</div>';
			$('#status').fadeOut().empty().append(htmlStringErr1).stop().fadeIn();
			return false;
		}
		var submitUrl = '/shop/actions.cfm?action=cartOutfit&' + $('#addToCartForm').serialize();
		$.ajax({
			url : submitUrl,
			type : 'GET',
			success : outfitItemAdded,
			error : outfitItemFail,
			dataType : 'json'
			});
	});
	
	function outfitItemAdded(data){
		if(data.addedToCartOutfit){
			htmlString = '<div id="success" class="fade-99cc99"><strong>'+data.message+'</strong></div>';
			$('#status').fadeOut().empty().append(htmlString).stop().fadeIn();
			$('.accountLinks').find('a[href*=/cart/cart.cfm]').text('View Cart ('+data.items+')');
						
		}
	}
	
	function outfitItemFail(){
		alert("An Unexpected Error has occured.\nCould Not Add this item to Your Cart")
	}


	// add to wish list
	$('.addToWishList').bind('click',function(w){
		w.preventDefault();
		if($('#userId').val() == '0'){
			htmlStringErrWL1 = '<div id="failureSingle" class="fade-f8acac">Please must login before adding to your Wish List.</div>';
			$('#status').fadeOut().empty().append(htmlStringErrWL1).stop().fadeIn();
			return false;
		}
		if($('#option_id').val() == ''){
			htmlStringErrWL2 = '<div id="failureSingle" class="fade-f8acac">Please choose a size/color to add to your Wish List.</div>';
			$('#status').fadeOut().empty().append(htmlStringErrWL2).stop().fadeIn();
			return false;
		}
		var submitUrl = '/shop/actions.cfm?action=wishlist&' + $('#addToCartForm').serialize();
		$.ajax({
			url : submitUrl,
			type : 'GET',
			success : itemAddedWishList,
			error : addFailedWishList,
			dataType : 'json'
			});
	});

	function itemAddedWishList(data){
		if(data.addedToWishList){
			htmlString = '<div id="success" class="fade-99cc99">'+data.message+'</div>';
			$('#status').fadeOut().empty().append(htmlString).stop().fadeIn();                            
		}
	}
	
	function addFailedWishList(){
		alert("An Unexpected Error has occured.\nCould Not Add this item to Wish List")
	}

	$("a.fbModalDetails").fancybox({
		'width'				: 770,
		'height'			: 350,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});

	$("a.fbImageDetail").fancybox({
		'autoScale'		: true,
		'titleShow'		: false,
		'hideOnContentClick'	: true
	});


});


function slideVideoHandler()
{
	if($('#slideVideoPlayer').length)
	{
		$videoCnt = $('#slideVideoPlayer #video_wrapper');
		$videoCnt.slideDown('slow',function()
		{
			embedVimeoSwf();
		});
		
		$('.video-icon').bind('click',function(){
			$this = $(this);
			
			if($('#slideVideoPlayer #video_wrapper:visible').length){
				$videoCnt = $('#slideVideoPlayer #video_wrapper');
				$videoCnt.slideUp('slow',function(){
					$('.video-icon').html('Open Video Window').addClass('open');
				});
			}else{
				$videoCnt = $('#slideVideoPlayer #video_wrapper');
				$videoCnt.slideDown('slow',function()
				{
					embedVimeoSwf();
					$('.video-icon').html('Close Video Window').removeClass('open');
				});					
			}
			
			return false;
		});
			
	}	
}


