$(function () {
	
	var i = document.createElement('input');
	if (!('placeholder' in i)) {
		$('input[placeholder]').each(function () {
			var placeholder = $(this).attr('placeholder');
			$(this).val(placeholder).addClass('placeholder').focus(function () {
				$(this).removeClass('placeholder');
				if ($(this).val() == placeholder) {
					$(this).val('');
				}
			}).blur(function () {
				if ($(this).val() == "") {
					$(this).addClass('placeholder');
					$(this).val(placeholder);
				}
			});
		})
	}
	
	$('#navBox>ul>li').hover(function () {
	    $(this).find('ul').stop(true, true).slideDown(400);
	}, function () {
	    $(this).find('ul').stop(true, true).slideUp(200);
	})
	
	VideoJS.setupAllWhenReady();
		
	$('.homePage #focuss ul, .magzine #focuss ul, .feature-page #feature-slideshow ul, .magazine-page #slideshow ul, .pages-page #slideshow ul').cycle({ 
		fx:      'scrollHorz', 
		speed:   400, 
		next:    '.next', 
		prev:    '.prev',
		timeout: 6000
	});
	
	$("#header-wrapper .emailBox").colorbox({
		transition: "",
		width: "400px", 
		inline: true, 
		href: "#header-wrapper .emailBox .tableForm"
	});
	
	$('#similarproducts').jcarousel({
		visible: 4,
		scroll: 1,
		animation: 200,
		easing: 'easeInOutQuad',
		initCallback: function (carousel) {
			$('#carousel-next').bind('click', function() {
				carousel.next();
				return false;
			});

			$('#carousel-prev').bind('click', function() {
				carousel.prev();
				return false;
			});
		}
	});
	
	$('.features ul.large').jcarousel({
		scroll: 1,
		animation: 750,
		easing: 'easeInOutQuad',
		initCallback: function (carousel) {
			$('.prev-next .next').bind('click', function() {
				carousel.next();
				return false;
			});
	
			$('.prev-next .prev').bind('click', function() {
				carousel.prev();
				return false;
			});
		}
	});
	
	
	$('.features ul.thumbs').jcarousel({
		scroll: 1,
		animation: 750,
		easing: 'easeInOutQuad',
		initCallback: function (carousel) {
			$('.prev-next .next').bind('click', function() {
				carousel.next();
				return false;
			});
	
			$('.prev-next .prev').bind('click', function() {
				carousel.prev();
				return false;
			});
		}
	});
	
	$('.stores #slideshow ul').jcarousel({
		scroll: 1,
		easing: 'easeInOutQuad',
		animation: 400,
		auto: 4,
		wrap: 'circular',
		buttonPrevHTML: '<a class="prev" href="#"></a>',
		buttonNextHTML: '<a class="next" href="#"></a>',
		initCallback: function (carousel) {
			$('#all-stores li').each(function (i) {
				$(this).hover(function () {
					carousel.scroll(i);
					return false;
				}, function () {});
			});
		}
	});
	
	$('#hot_magazine').each(function () {
		$(this).find('ul.tabMenu').css('display', 'block');
                
		var mv = $(this);
		$(this).find('ul.tabMenu li > a').click(function () {
                        $(this).parent().siblings().find('a').removeClass("selected");
                        $(this).addClass('selected');
			var panel = mv.find('> div.' + $(this).attr('data-period'));
                        panel.fadeIn().siblings('div').fadeOut();
			//panel.show().siblings('div').hide();
			return false;
		})
	});

	$('.homePage .rotator').each(function() {

		$(this).find('li:eq(0)').addClass('on');
		
		var images = $(this).find('.hotJDJX img');
		images.hide();
		images.eq(0).show();
		
		$('.hotJDJX').each(function(){
			var currentTallest = 0;
			$(this).find('img').each(function() {
				if ($(this).height() > currentTallest) { 
					currentTallest = $(this).height(); 
				}
			});
			$(this).css({'height': currentTallest}); 
		});
		
		$(this).find('li').each(function (i) {
			$(this).hover(function () {
				if (!$(this).hasClass('on')) {
					images.stop(true, true).fadeOut();
					images.eq(i).stop(true, true).fadeIn();
					$(this).addClass('on').siblings().removeClass('on');
				}
			}, function () { });
		});
	});
	
	$('#products li').live('mouseover mouseout', function(event) {
		if (event.type == 'mouseover') {
			$(this).find('img').stop(true, false).css({ opacity: 0.5 });
			$(this).find('.panel').stop(true, false).fadeIn('fast');
		} else {
			$(this).find('img').stop(true, true).css({ opacity: 1 });
			$(this).find('.panel').stop(true, true).fadeOut('fast');
		}
	});
	
	
	$('.brands-letter').each(function (i) {
		var list = this;
		$(this).css('visibility', 'hidden');
		setTimeout(function () {
			$(list).css({visibility: "visible"}).hide().fadeIn(250);
		}, i * 50);
	});
		
	$('.printpage').click(function () {
		window.print();
		return false;
	});
	
	$('.search-results li img').each(function () {
		var self = this;
		var img = new Image();
		var box = 140;
		img.onload = function () {
			
			if (this.height / this.width > 1.3) {
				var neww = Math.ceil(140 * this.width / this.height);
				var newp = Math.round((140 - neww)/2);
				
				$(self).attr('width', neww).css({
					'padding-left': newp,
					'width': neww,
					'padding-right': newp
				});
			}
			
		}
		img.src = $(this).attr('src');
		
	})
	
	$('.search .col2 li').each(function () {
		var cat = $(this).data('cat');
		
		$(this).find('a').click(function () {
			$(this).parent().parent().addClass('selected').siblings().removeClass('selected');
			$('.search-results li:hidden').filter('.' + cat).slideDown(600);
			$('.search-results li:visible').not('.' + cat).slideUp(600);
			
			return false;
		});
	});
	
	$('.homePage .rotator.obsessions').each(function () {
		var interval;
		var images = $(this).find('img');
		var lists = $(this).find('li');
		var currentImage = 0;
		
		var go = function () {
			interval = setInterval(function () {
				var nextImage = (currentImage + 1) % images.length;
				images.eq(currentImage).fadeOut(500);
				images.eq(nextImage).fadeIn(500);
				lists.eq(nextImage).addClass('on').siblings().removeClass('on');
				currentImage = nextImage;
			}, 6000);
		}
		
		$(this).hover(function () {
			clearInterval(interval);
		}, function () {
			go();
		})
		
		lists.each(function (i) {
			$(this).hover(function () {
				currentImage = i;
			}, function () {});
		});
		
		go();
		
	})
	
	
});

