
function h2grunge(){
	$('h2').each(function(){
		var h = $(this).outerHeight() + 10, w = $(this).outerWidth();
		if($('#content_shell_alt').length == 0) w = w > 530 ? 530 : w;
		if($(this).find('.grunge').length == 0){
			if($(this).children('a').length > 0) $(this).children('a').append('<span class="grunge">&nbsp;</span>');
			else $(this).append('<span class="grunge">&nbsp;</span>');
		}
		$(this).find('.grunge').height(h).width(w);
	});
}

//	function quickSlideshow(){
//		this.currentSlideWrapper = $('#sWidgGalFrame');
//		this.currentSlideSlug = $('#sWidgGalSlug');
//		this.stageWidth = this.currentSlideWrapper.width();
//		this.currentEqId = 0;
//		$('#slideWidgetWrapper').append('<a href="#" class="prev"><img src="/i/fancy/fancy_nav_left.png" alt="Previous" /></a><a href="#" class="next fancy_link"><img src="/i/fancy/fancy_nav_right.png" alt="Next" /></a>')
//		
//		this.next = function(){
//			this.currentEqId++;
//			if(this.currentSlideSlug.children().length == this.currentEqId) {
//				this.currentEqId = 0;
//				this.loadState(1000); // lasts longer to rewind
//			} else this.loadState(500);
//		}
//		
//		this.prev = function(){
//			this.currentEqId--;
//			if(-1 == this.currentEqId) {
//				this.currentEqId = this.currentSlideSlug.children().length - 1;
//				this.loadState(2000); // lasts longer to fast forward
//			} else this.loadState(500);
//		}
//		
//		this.loadState = function(duration){
//			this.slide = this.currentSlideSlug.children().children('img').eq(this.currentEqId);
//			//this.currentSlideWrapper.parent().children('.slideTitle').html(this.slide.attr('alt'));
//			this.currentSlideWrapper.scrollTo( this.slide, { 'duration' : duration, 'offset' : { 'left' : -Math.round((this.stageWidth-this.slide.outerWidth())/2) }} );
//		}
//	}

function changeProduct (object) {
	blob = object.value;
	blobs = new Array();
	blobs = blob.split(' | ');
	
	prodDesc = blobs[0];
	prodOption = blobs[1]
	prodPrice = blobs[2];
	prodID = blobs[3];
	//alert (prodDesc);
	//alert (prodPrice);
	//alert (prodID);
	
	document.getElementById("price"+prodID).innerHTML = "$"+prodPrice;
	document.getElementById("os0"+prodID).value = prodOption;
	document.getElementById("amount"+prodID).value = prodPrice;
}

function trackStoreLocation(){
	if($('#giftCardBusiness').length > 0) {
		if( $('#giftCardBusiness').val() == 'shop@hillcountryny.com' ) $('#dcGiftCardNote:visible').slideUp(200);
		else $('#dcGiftCardNote:hidden').slideDown(200);
	}
}

$(document).ready(function(){
	// when all code loads
	trackStoreLocation();
	$('#giftCardBusiness').change(function(){
		trackStoreLocation();
	})
	$('.button_red, .button_redish').each(function(){
		var position = Math.round(187 * Math.random());
		$(this).css('background-position', position+"px 0px");
	});
	if( $('#homeslideshow').length) $('.slideshow').cycle({ fx: 'fade', speed: 1050, timeout: 6000, delay: -2000, pauseOnPagerHover: false, pager: '#HomePagination'});	
	else if( $('#hcLiveFeatureds').length) $('.slideshow').cycle({ fx: 'fade', speed: 1050, timeout: 6000, delay: -2000, pauseOnPagerHover: false, pager: '#hcLivePagination'});	
	else if( $('.slideshow').length) $('.slideshow').cycle({ fx: 'fade', speed: 1050, timeout: 6000, delay: -2000, pauseOnPagerHover: false});	
	
	if( $('.slideshowdoin').length) $('.slideshowdoin').cycle({ fx: 'fade', speed: 1050, timeout: 6000, delay: -800, pauseOnPagerHover: false});	
	if( $('a.pop_up').length ) $('a.pop_up').fancybox({ showNavArrows:true, titleShow: true });	
	h2grunge();
	//	if($('#slideWidgetWrapper').length > 0){
	//		window.slidyGallery = new quickSlideshow();
	//		window.slidyGallery.currentEqId = 1; // center on the second slide, slides start at index 0
	//		window.slidyGallery.loadState(0);
	//		$('#slideWidgetWrapper .next').click(function(click){ this.blur(); click.preventDefault(); window.slidyGallery.next(); })
	//		$('#slideWidgetWrapper .prev').click(function(click){ this.blur(); click.preventDefault(); window.slidyGallery.prev(); })
	//		
	//	}
});

$(window).load(function(){
	// when images all load
	h2grunge();
	if($('#slideWidgetWrapper').length > 0) window.slidyGallery.loadState(0);
});


