
	// hide jquery
	$('html').addClass('js');
	
	$(document).ready(function()
 					{	
	
	
					
						// show jquery
						$('.js').css('display', 'block');
						
					 	// home 
						$('div#homeGallery ul').innerfade({
							speed:'slow',
							timeout: 6000,
							type: 'random',
							containerheight: '500px'
						});
						
					
						
							// add the h1 to the subject of email
							$(".rugName input").val($("h1").html());
							
							// hide subject on form
							$('.rugName').css('display', 'none');
							
							
							// add span to the anchor tags
							$('.rugsNav a , .bottomRugsNav a').wrapInner("<span></span>");
							
							
							
							// masonary
							$('.rugsAll').masonry({
							  columnWidth: 160, 
							  itemSelector: 'p' 
							});
							
							$('#galleryWrap div.gallery').masonry({
							  columnWidth:185, 
							  itemSelector: '.gallery-item' 
							});
							
							
							// hover caption .delay(800).fadeOut('slow');
							$('#rugs #content .rugsAll  p img, #homeGallery ul li img').hover_caption();
							
							$('#nav .children li').addClass('childNav');
							$('#nav .children li .children li').removeClass('childNav');
							$('#nav .children li ul').removeClass('children');
							
							// add class to last child in the navigatiom
							$("#nav li:last-child").addClass("last-nav");
							// add class to first child in the navigatiom
							$("#nav li:first-child").addClass("first-nav");
							// add class to	second ("rugs") child in the navigation	
							$("#nav li:nth-child(2)").addClass("rug-nav");						
							
							// rugs drop down nav page-item-173
							$('#nav .rug-nav.children').css('display', 'none');
							
							// drop down menu
							$('#nav .rug-nav a').mouseenter(function(){
								$('#nav .rug-nav .children').stop(true, true).delay(200).slideDown('fast');
								
							
								$('#nav .rug-nav').mouseleave(function(){
										$('#nav .rug-nav .children').stop(true, true).delay(1000).slideUp('fast');
								});

								//hide sub nav on rugs page
								$('#rugs #nav .children').css('display', 'none')
								
								// hide extra level children
								$('#nav .rug-nav .children .childNav ul').css('display', 'none');
							});
																					
							//image slideshow prev / next
							
							// addclass to p tags
							$('#slides p').addClass('slideWrap');

							
				
							$('.slideWrap:not(:first)').hide();
							var $boxes = $(".slideWrap"),
							    $currentBox = $boxes.first().show();

							// prev next slideshow for rugs
							$("#next").click(function() {
							    $currentBox.fadeOut(600, function() {
							        $currentBox = $currentBox.next();
							        if (!$currentBox.length) {
							            $currentBox = $boxes.first();
							        }
							        $currentBox.fadeIn(600);
							    });
							});
							$("#prev").click(function() {
							    $currentBox.fadeOut(600, function() {
							        $currentBox = $currentBox.prev();
							        if (!$currentBox.length) {
							            $currentBox = $boxes.last();
							        }
							        $currentBox.fadeIn(600);
							    });
							});
						
				            $('.slideWrap').each(function() {
							this.style.position = 'absolute';
							this.style.top = $(this).parent().height()/2 + 'px';
							this.style.marginTop = -$(this).height()/2 + 'px';
							this.style.left = ($(this).parent().width() - $(this).width())/2 + 'px';

							});
							
							
							// fade in and out press thumbs
							$(function () {
							    var animateDuration = 400;

							    $('.gallery-icon a img').hover(function() {
							        $ (this) .animate ({"opacity": .7});
							    }, function () {
							        $(this).stop() .animate ({"opacity": 1 });
							    });
							});

														
							// order dropdown navigation
							// Get your list items
							var items = $('.rug-nav .children').find('.childNav');

							// The new index order for each item
							var order = [ 0, 1, 2, 3, 4, 5, 6, 7];

							// Map the existing items to their new positions        
							var orderedItems = $.map(order, function(value) {
						    return items.get(value);
							});

							// Clear the old list items and insert the newly ordered ones
							$('.rug-nav .children').empty().html(orderedItems);
							
							
							
							// order rug navigation
							// Get your list items
							var items = $('.rugsNav, .footerRugNav').find('li');

							// The new index order for each item
							var order = [ 5, 7, 6, 4, 1, 3, 2, 0 ];

							// Map the existing items to their new positions        
							var orderedItems = $.map(order, function(value) {
						    return items.get(value);
							});

							// Clear the old list items and insert the newly ordered ones
							$('.rugsNav, .footerRugNav').empty().html(orderedItems);
					});
					
					



