// Font Replacement
/*
Cufon.replace('.category-title h1,.footer h4, .product-view .product-shop .product-name h1,.page-title h1, .page-title h2,.wired-home .subscribe strong, .cufon, h2', {
	hover: true
});
*/

(function($){
	//Built In
	$(document).ready(function() {
		// Featured Products
		$('#featured').jcarousel();
		// FancyBox $
		$("a.group").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': true }); 	
		// Slider Homepage
		$('#slider').cycle({
			fx: 'fade',
			speed: 2000,
			timeout: 5000
		});
	});
	
	var tallest = 0;
	$(document).ready(function(){
		
		if( window.location.href.match(/frequently-asked-questions/gi) && window.location.href.match(/#/gi) )
		{
			mainHeight = $('.main').height();
			var hash = window.location.hash.replace("#","");
			var clicked = '.' + hash;
			var clickedHeight = $(clicked).height();
			if( $(clicked).height() < 500 )
			{
				clickedHeight = 500;
			}
			$(clicked).show();
			$('.faqs-menu').hide();
			$('.faqs-menu').animate({opacity:0}, 400);

			$('.main').animate({height: clickedHeight }, 400 );
			$(clicked).animate({opacity:1 },400);
		}
		
		$('.faqs-categories-list ul li a').click(function(){
			mainHeight = $('.main').height();
			var clicked = '.' + $(this).attr('rel');
			var clickedHeight = $(clicked).height();
			if( $(clicked).height() < 500 )
			{
				clickedHeight = 500;
			}
			$(clicked).show();
			$('.faqs-menu').hide();
			$('.faqs-menu').animate({opacity:0}, 400);

			$('.main').animate({height: clickedHeight }, 400 );
			$(clicked).animate({opacity:1 },400);
		});

		$('.return').click(function(){
			$('.main').animate({height: mainHeight}, 400);
			$('.faqsitem').animate({opacity:0}, 400, function(){
				$('.faqsitem').hide();
			});
			$('.faqs-menu').show(0, function(){
				$('.faqs-menu').animate({opacity:1}, 400);
			});
		});
		var minHeight = 500;
		var thisID;
		$('div.info-box-content-box').not('div.showThis').each(function(){
			$(this).hide();
		});

		$('div.info-box-nav li.info-box-link').each(function(){
			$(this).click(function(e){
				e.stopImmediatePropagation()
				
				//var index = parseInt($(this).attr('rel'));
				var index = parseInt( $('.info-box-nav ul li').index(this) );
				if( $.browser.msie )
				{
					index = index*2;
				}
				$('#slider').cycle(index);
				
				$('.showThis').removeClass('showThis');
				$(this).addClass('showThis');
				
				var scrollTop = $(window).scrollTop();
				$(window).scrollTop(scrollTop);
				
				var clickedIBL = this.id;
				var showIBC = '#' + clickedIBL.replace('Link','Content');
				var showIBCH = $(showIBC).height() * 14 / 10;
				if( showIBCH < 200 )
				{
					showIBCH = 200;
				}
				$('div.info-box-content-box').stop().fadeOut(200, function(){
					$('div.info-box-content').stop().animate({ height: showIBCH }, 200, function(){
						$(showIBC).stop().show();
					});
				});
			});
		});
		
		$('#slider').cycle({
			speed:    700,
			timeout:  0,
			before: function(){
				$('#slider img').css({width: 696, height: 338});
			},
			after:     function() {
				$('#slider img').css({width: 696, height: 338});
			}
		});
		
		$('#carousel').bxSlider({
			mode: 'vertical',
			displaySlideQty: 4,
			moveSlideQty: 2
		});
		
		$('#carousel').find('img').each(function(){
			
			$(this).click(function(e){
				e.preventDefault();
				var num = $(this).parent().attr('longdesc');
				$('.showThis').removeClass('showThis');
				$('.info-box-content-box').hide(0, function(){
					$('#fcContent' + num).addClass("showThis");
				});
				
				var href = $('#fcImage' + num + " img").attr('src');
				$('.slideshow img').animate({opacity:0}, 200, function(){
					$('.slideshow img').attr('src', href);
					$('.slideshow img').load(function(){
						$('.slideshow img').animate({opacity:1}, 200);
					})
				});
				var num = $(this).parent().attr('longdesc');
				$('.showThis').removeClass('showThis');
				$('.info-box-content-box').hide(0, function(){
					$('#fcContent' + num).addClass("showThis");
				});
			});
		});
		
		$('#carousel li').not('.pager').each(function(){
			$(this).find('a').attr('rel', 'noLightbox');
		});
		
	});
	
})(jQuery);
