$(document).ready(function() {
	$(".product a, .product_blog a").colorbox({
		width: "950px",
		height: "550px",
		preloading: true,
		onComplete: function() {
				$('.zoom').click(function() {
					if( !$(this).hasClass('panzoom-ed') ) {
						return false;
					}
				});

				$('.product_zoom').cycle({ 
				    fx:     'fade', 
				    speed:  'slow', 
				    timeout: 0, 
				    pager:  '.additional_views', 
				    pagerAnchorBuilder: function(idx, slide) { 
				        // return selector string for existing anchor 
				        return '.additional_views li:eq(' + idx + ') a'; 
				    },
						before: function() {
							var index = $('.product_cycle').index( $(this) );
							var selector = '.zoom:eq(' + index + ')';

							bind_zoom_stuff( selector );
						}
				});

				if( $('.product_zoom').length == 1 ) {
					bind_zoom_stuff( '.product_zoom .zoom' );
				}
			applyCufon();
			$('.product_image').animate({opacity:1},1000);
		}
	});

	
	$(".newsletter_popup form .form_button").colorbox({
		transition: "none"
	});
	
	$(".newsletter_colorbox").colorbox({
		
		width: 500,
		height: 320,
                iframe: true,
		transition: "none",
		onComplete: function() {
			
			
		}
	});
	$(".magazine a").colorbox({
		innerWidth: "505px",
		innerHeight: "740px",
		scrolling: false,
		onComplete: function() {
						$('.articles').cycle({ 
					    fx:     'fade', 
					    speed:  'slow', 
					    timeout: 0,
					 	next: '.dots_articles, .articles',
					    pager:  '.dots_articles', 
								    pagerAnchorBuilder: function(idx, slide) {
							return '<a href="#">&middot;</a>';
						}
						});
			applyCufon();
			$('.mag_things_forcolorbox').animate({opacity:1}, 1000);
			
				
		}
	});

	
	$('.press_on_about .press-cycle').cycle({
		fx: 'scrollHorz',
		speed: 'fast',
		pager: '.dots',
		pagerAnchorBuilder: function(idx, slide) {
			return '<a href="#">&middot;</a>';
		},
		timeout: 0
	});

	
	//press page
	 
	
	// $('.collection.breadcrumbs ul li a').hover(
	// 	function () {
	// 		$(this).stop().animate({opacity:1});
	// 		
	// 	},
	// 	function () {
	// 		if($(this).hasClass('active') == 'false')
	// 		{
	// 			$(this).stop().animate({opacity:.4});
	// 		}
	// 		
	// 		
	// });
	$('.magazine').hover(
		function () {
			$(this).find('.mag_dates').stop().animate({opacity:1});
			$(this).find('img').stop().animate({opacity:1});
			
		},
		function () {
			$(this).find('.mag_dates').stop().animate({opacity:0});
			$(this).find('img').stop().animate({opacity:.8});		
	});
	
	$('#search_zip').click(function(){
		$('.store_lists').fadeOut("slow");
		$('.online_stores').fadeOut("slow");
		$('.map').fadeIn("slow");
	});
	
	$('.pick').click(function(){
		$('.map').fadeOut("slow");
		$('.online_stores').fadeOut("slow");
		$('.store_lists').fadeIn("slow");
	});
	$('.online').click(function(){
		$('.map').fadeOut("slow");
		$('.store_lists').fadeOut("slow");
		$('.online_stores').fadeIn("slow");
		
		return false;
	});
	$('.body.collection ul.filter li a').click(function() {
		var item_class = $(this).attr('id');
		$('.body.collection ul.filter li a').removeClass('active');
		$(this).addClass('active');

	

		if( item_class != '' ) {
			var the_items = $('.product.' + item_class + '');
			var not_items = $('.product:not(.' + item_class + ')');
			
			the_items.fadeIn('slow')
			not_items.fadeOut('slow');
			
			// the_items.height(269).animate({
			// 	width: 'show'
			// });
			// 
			// not_items.height(269).animate({
			// 	width: 'hide'
			// });
			
		} else {
			$('.product').fadeIn('slow');
		}

	});
	
});

$(window).load(function(){
	$('.map').fadeIn("slow");
});

jQuery.fn.extend({
  trueWidth: function() {
    // return this.width() + this.margin;
		return this.width() + this.getCssInt('margin-left') + this.getCssInt('margin-right') + this.getCssInt('padding-left') + this.getCssInt('padding-right');
  },
	trueHeight: function() {
    // return this.width() + this.margin;
		return this.height() + this.getCssInt('padding-top') + this.getCssInt('padding-bottom');
  },
	getCssInt: function(attr) {
		return parseInt(this.css(attr).replace('px',''));
	}
});