function runIntro() { 
	$('#ImgShell #Img1').fadeIn(500).delay(1400).fadeOut(400);
	$('#ImgShell #Img2').delay(2300).fadeIn(500).delay(1400).fadeOut(400);
	$('#ImgShell #Img3').delay(4600).fadeIn(1000).delay(1000);
	$('#Intro').delay(6600).animate({ opacity: 0 }, 1200, function() { 
		$(this).hide(); 
	});
}

$(document).ready(function(){
	
	var deviceAgent = navigator.userAgent.toLowerCase();
	var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
	
	$('#Intro').css('min-height', document.height); 
	
	var $holder = $('#Intro'); 
	var firstVisit = $.readCookie('first_visit');
	if (!firstVisit){
		$holder.imagesLoaded(function( $images ){
			runIntro(); 
			if($('#HomeSlides').length) { 
					$('#HomeSlides img:first').fadeIn(7000, function() { 
						$('#HomeSlides img').fadeIn();
						$('#HomeSlides').cycle({ 
							timeout: 5000, 
							pager: '#HomeSlidesNav'
						});
					});
			}
		});
	$.setCookie('first_visit', 'y', { 
			duration : 31, 
			path: '/'
		}); 
	} else { 
		$('#Intro').hide(); 
		if($('#HomeSlides').length) { 
				$('#HomeSlides img:first').fadeIn(800, function() { 
					$('#HomeSlides img').fadeIn();
					$('#HomeSlides').cycle({ 
						timeout: 4000, 
						pager: '#HomeSlidesNav'
					});
				});
		}
	}

	
	$('#FooterNav li:last').css('border-right', 'none'); 
	$('#FooterNav li:last').css('padding-right', '0px'); 
	$('#BlogFeed li:last').css('background-image', 'none'); 
	
	/*==================================== PRESS PAGE ===================================================*/
	
	$('#PressPage').css('background', '#827C75'); 
	
	$('#PressSort select').selectBox(); 
	
	if(!agentID) {
		$('#PressCoverageFeatured li, #PressCoverage li').hover(function() { 
			$(this).children('a').children('.press_overlay').show(); 
		}, function() { 
			$(this).children('a').children('.press_overlay').hide(); 
		}); 

	}
	
	// PRESS MODALS FADE-IN, POSITIONING
	
	$('#Press a').click(function() { 
		var pressindex = $(this).attr('rel'); 
		$('#PressModal' + pressindex).hide(); 
		$('#PressModal' + pressindex).fadeIn(300);
		$('#PressModal' + pressindex).css('top', $(window).scrollTop() + 65 + 'px');
		
		// PRESS MODAL CYCLES

		if($('#PressModal' + pressindex + ' .imgshell > img').length > 1) { 
			$('#PressModal' + pressindex + ' a.prev').css('display', 'block'); 
			$('#PressModal' + pressindex + ' a.next').css('display', 'block'); 
			$('#PressModal' + pressindex + ' .imgshell').cycle({ 
				timeout: 0, 
				prev: '.prev', 
				next: '.next'
			}); 
		} else { 
			$('#PressModal' + pressindex + ' a.prev').css('display', 'none'); 
			$('#PressModal' + pressindex + ' a.next').css('display', 'none');
		}
	}); 
	
	// PRESS PAGE ISOTOPE SORT
	
	function doIsotope(selector) { 
		$('#PressCoverage').isotope({
			itemSelector : '.item',
			filter: selector, 
			layoutMode: 'fitRows', 
			animationOptions: {
			     duration: 1000,
			     easing: 'easeOutQuad', 
				 queue: false
			   }
	      });
	}
	
	//$('#PressCoverage img').imagesLoaded(function($images) {
		doIsotope('.cat_date'); 
	//}); 

	$('#PressDropdown').change(function() { 
		var selector = $(this).val(); 
		selector = '.' + selector; 
	    doIsotope(selector); 
	});
	
	/*==================================== HOMEPAGE STYLING ===================================================*/
	
	$('#Nav li').hoverIntent(function() { 
		$(this).children('.subnav_wrapper').fadeIn(150)
	}, function() { 
		$(this).children('.subnav_wrapper').fadeOut(100); 
	});
	
	// TYPEPAD FEED IMG EXTRACTOR 
	
	$('div.blogfeed_img').each(function() { 
		var imgurl = $(this).find('img').attr('src'); 
		$(this).html('<img src="'+ imgurl + '" alt="The Fine Print">'); 
	}); 
	
	$('.excerpt').ellipsis(); 
	
	$('#BlogFeed li span').each(function() { 
		var fulldate = $(this).text(); 
		var yr = fulldate.substring(2,4); 
		var mnth = fulldate.substring(5,7); 
		var dayday = fulldate.substring(8,10); 
		$(this).text(mnth + '.' + dayday + '.' + yr); 
		$(this).parent('li').children('p.excerpt').append($(this)); 
	}); 
	
	// CENTER ALIGNMENT FOR DROPDOWN
	$('#Nav .subnav_wrapper').each(function() { 
		var liwidth = parseInt($(this).parent('li').width())/2 + 15; 
		var newpos = liwidth + 'px 0px';
		$(this).css('background-position', newpos); 
	});
	
	$('.subnav li:nth-child(2n)').addClass('alt'); 
	
	$('.subnav li').not('.trigger_samples').click(function(){
		window.location=$(this).children('a').attr('href');
		return false;
	});
	$('#BlogFeed li').click(function(){
		window.location=$(this).children('h4').children('a').attr('href');
		return false;
	});
	$('#BlogFeed li').hoverIntent(function() { 
		$(this).children('.blog_flyout_shell').fadeIn(150); 
	}, function() { 
		$(this).children('.blog_flyout_shell').hide(); 
	});
	
	// FANCY FADE
	
	$('#Thirds .third').hover(function() { 
		if ($.browser.msie) {		
			$(this).siblings().children('a').children('img').stop(true,false).fadeTo(100, 0.4);
		} else {
			$(this).siblings().stop(true,false).fadeTo(100, 0.4);
		}
	}, function() { 
		if ($.browser.msie) {		
			$(this).siblings().children('a').children('img').stop(true,false).fadeTo(100, 1);
		} else { 
			$(this).siblings().stop(true,false).fadeTo(100, 1);
		}
	}); 
	
	$('#Thirds .third').click(function(){
		window.location=$(this).children('a').attr('href');
		return false;
	});
	
	// VERTICAL ALIGNMENT FOR BLOG FEED FLYOUTS
	
	$('#BlogFeed li .blog_flyout_shell').each(function() { 
		var thishght = $(this).outerHeight(); 
		var thisnewmargin = -((thishght/2) - 40); 
		$(this).css('margin-top', thisnewmargin + 'px'); 
	});
	
	/*==================================== MODALS ===================================================*/
	
	$('#ExclusiveModalWrapper').jqm({ trigger: '#ExclusiveOffers' }); 
	$('#ExclusiveOffers').click(function(){
		$('html,body').animate({scrollTop: 0}, 0);
		$('.jqmWindow').css('top', '24%');
	});
	
	$('#AtAGlanceWrapper').jqm({ trigger: '.modal_pricing' }); 
	$('.modal_pricing').click(function(){
		$('html,body').animate({scrollTop: 0}, 0);
		$('.jqmWindow').css('top', '12%');
	});
	
	$('#PriceListWrapper').jqm({ trigger: '.modal_price_lists' }); 
	$('.modal_price_lists').click(function(){
		$('html,body').animate({scrollTop: 0}, 0);
		$('.jqmWindow').css('top', '12%');
	});
	
	$('#RetailerWrapper').css('top', '24%'); 
	
	$('#InspirationModal').jqm({ trigger: '#TriggerInspiration' }); 
	$('#TriggerInspiration').click(function() { 
		$('html,body').animate({scrollTop: 0}, 0);
		$('#InspirationModal').hide().css('top', '5%').fadeIn(500); 
		
	}); 
	
	
	/*==================================== GALLERY PAGE ===================================================*/
	
	
	if(!agentID) {
		$('#GalleryMenu a').hover(function() { 
			$(this).children('.gallery_overlay').show(); 
		}, function() { 
			$(this).children('.gallery_overlay').hide(); 
		}); 
	}
	
	$('#CustomizeElements').click(function() { 
		window.location = $(this).children('a').attr('href'); 
	}); 
	
	// PRICE LISTS / AT A GLANCE
	

	/*	var thishtml = $('#AtAGlance table td.price').html(); 
		thishtml.replace(thishtml.replace(/\g, '')); */

	
	// INDIVIDUAL GALLERY/SUITE PAGE
	
	if($('#SuiteImgs').length) { 
		$('#SuiteThumbs ul li:first').addClass('active'); 
		$('.suite_details_wrapper img').imagesLoaded(function($images) {
			$('#SuiteImgs').cycle({ 
				timeout: 0, 
				prevNextClick: function(isNext, zeroBasedSlideIndex, slideElement) {
					var gotoindex = zeroBasedSlideIndex + 1; 
					$('#SuiteThumbs').find('.active').removeClass('active'); 
					$('a#goto' + gotoindex).parent('li').addClass('active'); 
				}
			}); 
			$('.suite_details_wrapper img').fadeIn(150); 
		}); 
	}
	
	/*---------------------*/
	
	$('#SuiteThumbs a').click(function() { 
		$(this).parent('li').parent('ul').find('.active').removeClass('active'); 
		$(this).parent('li').addClass('active'); 
		$('.suite_details').hide(); 
		$('.see_details').removeClass('hide_details'); 
		return false; 
	}); 
	
	$('.see_details').toggle(function() { 
		if($(this).hasClass('hide_details')) { 
			$(this).removeClass('hide_details'); 
			$('.suite_details').slideUp(200); 
		}
		else { 
			$(this).addClass('hide_details'); 
			$('.suite_details').slideDown(200); 
		}
	}, function() { 
		if($(this).hasClass('hide_details')) { 
			$(this).removeClass('hide_details'); 
			$('.suite_details').slideUp(200); 
		}
		else { 
			$(this).addClass('hide_details'); 
			$('.suite_details').slideDown(200); 
		}
	});
	
	$('#SuiteCustom ul li:last').css('background-image', 'none'); 
	$('#SuiteEmbellish ul li:last').css('background-image', 'none'); 
	
	$('#SuiteCustom ul li a, #SuiteEmbellish ul li a, #IssuuPages li a, li.look_book_url a').not('.null').click(function() { 
		var addr = $(this).attr('href'); 
		var addrPdf = $(this).attr('rel'); 
		if (($.browser.msie && $.browser.version < 9) || agentID){	
			window.open(addrPdf); 
			return false; 
		} else { 
			$('html,body').css('overflow', 'hidden');
			$('#IssuuModal').html('<a href="#" class="modal_close jqmClose">X</a>'); 
			$('#IssuuModal').append('<iframe src="' + addr + '" width="100%" height="100%" scrolling="no" frameborder="0" allowtransparency="true"></iframe>');
			var addOverflow = function(hash) { 
				hash.w.fadeOut('300',function(){ hash.o.remove(); 
					$('html, body').css('overflow', 'visible'); 
				}); 
			}; 
			var addFade = function(hash){ hash.w.css('opacity', 1).fadeIn(1000); }; 
			$('#IssuuModal').css('opacity', '0').jqm({ onHide: addOverflow, onShow: addFade }).jqmShow(); 
			return false;
		}
	}); 
	
	/*==================================== CONTACT PAGE ===================================================*/
	
	$('select#input_1').selectBox(); 
	$('form.jotform-form').validate();
	
	/*==================================== TESTIMONIALS PAGE ===============================================*/
	
	$('#Testimonials').columnize(); 
	
	/*==================================== PLACING YOUR ORDER PAGE ==========================================*/
	
	$('#PlaceOrder li:last').css('background-image', 'none'); 
	
	/*==================================== VINTAGE PRINTING METHODS PAGE ====================================*/
	
	$('#Vintage li:last').css('border-bottom', '0px');
	
	/*==================================== RETAILER MAP PAGE =================================================*/
	
	$('#RetailerDropdown').selectBox(); 
	
	$('#RetailerDropdown').change(function() { 
		if($(this).val() == 'all') { 
			$('.search_list_header').hide(); 
		} else { 
			$('.search_list_header').show(); 
		}
		var newloc = $(this).val(); 
		var newloctext = $('option:selected', this).text(); 
		$('#RetailerList').hide().load('/locate-retailer/retailerlist/' + newloc).delay(400).fadeIn(600); 
		$('#Map').load('/locate-retailer/retailermap/' + newloc); 
		$('#StateSearch').html(newloctext); 
	});
	
	
	/*==================================== RETAILER LOGIN PAGE ===================================================*/
	
	$('#RetailerLogin .outer h3 a').toggle(function() { 
		$(this).addClass('active'); 
		$(this).parent('h3').parent('.outer').children('.inner').slideDown('slow', 'easeOutQuad', function() {}); 
	}, function() { 
		$(this).removeClass('active'); 
		$(this).parent('h3').parent('.outer').children('.inner').slideUp('slow', 'easeOutQuad', function() {}); 
	}); 
	
	// MINIMUM HEIGHT
	
	var windowht = $(window).height(); 
	var minht = windowht - 130 - 72 - 61; 
	var leftminht = minht - 217; 
	//$('#Container').css('min-height', minht + 'px'); 
	//$('.left_main').css('min-height', leftminht + 'px'); 
	//$('#RetailerSidebar').css('min-height', minht + 'px'); 
	
	/*=============================== SHOP LOGIN ===========================================*/
	
	$('#ShopModalShell').jqm({ trigger: '.trigger_shop' }); 
	$('#SamplesModalShell').jqm({ trigger: '.trigger_samples' }); 
	
	$('a.trigger_samples').parent('li').addClass('trigger_samples'); 
	
	$('a.trigger_shop').click(function(){
		$('html,body').animate({scrollTop: 0}, 0);
		$('.jqmWindow').css('top', '24%');
	});
	
	$('#mc-embedded-subscribe-form').validate(); 

});

$(document).keydown(function(e) {
	switch(e.keyCode){
		case 39:        
			$('#SuiteImgs').cycle('next');
        break;  
        case 37:        
			$('#SuiteImgs').cycle('prev');
        break;
	}
});

$(window).resize(function() {
	var windowht = $(window).height(); 
	var minht = windowht - 130 - 72 - 61; 
	$('#Container').css('min-height', minht + 'px'); 
});

$(window).load(function() { 
	/*======================== LEFT AND RIGHT HEIGHT LEVEL ===============================*/
	
	$('.right_main').each(function() { 
		var rightheight = $(this).height(); 
		var leftheight = $(this).parent('div').children('.left_main').height(); 
		if(leftheight > rightheight) { 
			$(this).css('min-height', leftheight + 'px'); 
		} else { 
			$(this).parent('div').children('.left_main').css('min-height', rightheight + 'px'); 
		}
	});
}); 

